2016-03-18 12:07:56 -04:00
|
|
|
/*
|
2016-06-02 20:25:58 -04:00
|
|
|
Copyright 2016 The Kubernetes Authors.
|
2016-03-18 12:07:56 -04:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package framework
|
|
|
|
|
|
|
|
|
|
import (
|
2017-01-11 09:09:48 -05:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/serializer/versioning"
|
2016-03-18 12:07:56 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// NewSingleContentTypeSerializer wraps a serializer in a NegotiatedSerializer that handles one content type
|
2016-10-12 16:55:28 -04:00
|
|
|
func NewSingleContentTypeSerializer(scheme *runtime.Scheme, info runtime.SerializerInfo) runtime.StorageSerializer {
|
2016-03-18 12:07:56 -04:00
|
|
|
return &wrappedSerializer{
|
2016-10-12 16:55:28 -04:00
|
|
|
scheme: scheme,
|
|
|
|
|
info: info,
|
2016-03-18 12:07:56 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type wrappedSerializer struct {
|
2016-10-12 16:55:28 -04:00
|
|
|
scheme *runtime.Scheme
|
|
|
|
|
info runtime.SerializerInfo
|
2016-03-18 12:07:56 -04:00
|
|
|
}
|
|
|
|
|
|
2016-04-23 15:00:28 -04:00
|
|
|
var _ runtime.StorageSerializer = &wrappedSerializer{}
|
2016-03-16 10:17:04 -04:00
|
|
|
|
2016-10-12 16:55:28 -04:00
|
|
|
func (s *wrappedSerializer) SupportedMediaTypes() []runtime.SerializerInfo {
|
|
|
|
|
return []runtime.SerializerInfo{s.info}
|
2016-03-18 12:07:56 -04:00
|
|
|
}
|
2016-04-23 15:00:28 -04:00
|
|
|
|
|
|
|
|
func (s *wrappedSerializer) UniversalDeserializer() runtime.Decoder {
|
2016-10-12 16:55:28 -04:00
|
|
|
return s.info.Serializer
|
2016-04-20 13:35:09 -04:00
|
|
|
}
|
2016-03-18 12:07:56 -04:00
|
|
|
|
2016-05-22 19:10:42 -04:00
|
|
|
func (s *wrappedSerializer) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
|
2018-07-06 09:18:05 -04:00
|
|
|
return versioning.NewCodec(encoder, nil, s.scheme, s.scheme, s.scheme, s.scheme, gv, nil, s.scheme.Name())
|
2016-03-18 12:07:56 -04:00
|
|
|
}
|
|
|
|
|
|
2016-05-22 19:10:42 -04:00
|
|
|
func (s *wrappedSerializer) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
|
2018-07-06 09:18:05 -04:00
|
|
|
return versioning.NewCodec(nil, decoder, s.scheme, s.scheme, s.scheme, s.scheme, nil, gv, s.scheme.Name())
|
2016-03-18 12:07:56 -04:00
|
|
|
}
|