pkg/runtime/serializer/codec_factory.go

    实现 NegotiatedSerializer 接口,可以获取不同media type的encoder、decoder、serializer。其中serializer实现了encoder、decoder。

    1. // DecoderToVersion returns a decoder that targets the provided group version.
    2. func (f CodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder {
    3. return f.CodecForVersions(nil, decoder, nil, gv)
    4. }
    5. // EncoderForVersion returns an encoder that targets the provided group version.
    6. func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder {
    7. return f.CodecForVersions(encoder, nil, gv, nil)
    8. }
    9. func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode runtime.GroupVersioner, decode runtime.GroupVersioner) runtime.Codec {
    10. // TODO: these are for backcompat, remove them in the future
    11. if encode == nil {
    12. encode = runtime.DisabledGroupVersioner
    13. }
    14. if decode == nil {
    15. //默认decode版本
    16. decode = runtime.InternalGroupVersioner
    17. }
    18. return versioning.NewDefaultingCodecForScheme(f.scheme, encoder, decoder, encode, decode)
    19. }