serializer

package
v0.32.0-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 23,747

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DisablePretty added in v0.16.4

func DisablePretty(options *CodecFactoryOptions)

DisablePretty disables including a pretty serializer along with the non-pretty one

func DisableStrict added in v0.16.4

func DisableStrict(options *CodecFactoryOptions)

DisableStrict disables configuring all serializers in strict mode

func EnablePretty added in v0.16.4

func EnablePretty(options *CodecFactoryOptions)

EnablePretty enables including a pretty serializer along with the non-pretty one

func EnableStrict added in v0.16.4

func EnableStrict(options *CodecFactoryOptions)

EnableStrict enables configuring all serializers in strict mode

Types

type CodecFactory

type CodecFactory struct {
	// contains filtered or unexported fields
}

CodecFactory provides methods for retrieving codecs and serializers for specific versions and content types.

func NewCodecFactory

func NewCodecFactory(scheme *runtime.Scheme, mutators ...CodecFactoryOptionsMutator) CodecFactory

NewCodecFactory provides methods for retrieving serializers for the supported wire formats and conversion wrappers to define preferred internal and external versions. In the future, as the internal version is used less, callers may instead use a defaulting serializer and only convert objects which are shared internally (Status, common API machinery).

Mutators can be passed to change the CodecFactoryOptions before construction of the factory. It is recommended to explicitly pass mutators instead of relying on defaults. By default, Pretty is enabled -- this is conformant with previously supported behavior.

TODO: allow other codecs to be compiled in? TODO: accept a scheme interface

func (CodecFactory) CodecForVersions

func (f CodecFactory) CodecForVersions(encoder runtime.Encoder, decoder runtime.Decoder, encode runtime.GroupVersioner, decode runtime.GroupVersioner) runtime.Codec

CodecForVersions creates a codec with the provided serializer. If an object is decoded and its group is not in the list, it will default to runtime.APIVersionInternal. If encode is not specified for an object's group, the object is not converted. If encode or decode are nil, no conversion is performed.

func (CodecFactory) DecoderToVersion

func (f CodecFactory) DecoderToVersion(decoder runtime.Decoder, gv runtime.GroupVersioner) runtime.Decoder

DecoderToVersion returns a decoder that targets the provided group version.

func (CodecFactory) EncoderForVersion

func (f CodecFactory) EncoderForVersion(encoder runtime.Encoder, gv runtime.GroupVersioner) runtime.Encoder

EncoderForVersion returns an encoder that targets the provided group version.

func (CodecFactory) LegacyCodec

func (f CodecFactory) LegacyCodec(version ...schema.GroupVersion) runtime.Codec

LegacyCodec encodes output to a given API versions, and decodes output into the internal form from any recognized source. The returned codec will always encode output to JSON. If a type is not found in the list of versions an error will be returned.

This method is deprecated - clients and servers should negotiate a serializer by mime-type and invoke CodecForVersions. Callers that need only to read data should use UniversalDecoder().

TODO: make this call exist only in pkg/api, and initialize it with the set of default versions. All other callers will be forced to request a Codec directly.

func (CodecFactory) SupportedMediaTypes

func (f CodecFactory) SupportedMediaTypes() []runtime.SerializerInfo

SupportedMediaTypes returns the RFC2046 media types that this factory has serializers for.

func (CodecFactory) UniversalDecoder

func (f CodecFactory) UniversalDecoder(versions ...schema.GroupVersion) runtime.Decoder

UniversalDecoder returns a runtime.Decoder capable of decoding all known API objects in all known formats. Used by clients that do not need to encode objects but want to deserialize API objects stored on disk. Only decodes objects in groups registered with the scheme. The GroupVersions passed may be used to select alternate versions of objects to return - by default, runtime.APIVersionInternal is used. If any versions are specified, unrecognized groups will be returned in the version they are encoded as (no conversion). This decoder performs defaulting.

TODO: the decoder will eventually be removed in favor of dealing with objects in their versioned form TODO: only accept a group versioner

func (CodecFactory) UniversalDeserializer

func (f CodecFactory) UniversalDeserializer() runtime.Decoder

UniversalDeserializer can convert any stored data recognized by this factory into a Go object that satisfies runtime.Object. It does not perform conversion. It does not perform defaulting.

func (CodecFactory) WithoutConversion

func (f CodecFactory) WithoutConversion() runtime.NegotiatedSerializer

WithoutConversion returns a NegotiatedSerializer that performs no conversion, even if the caller requests it.

type CodecFactoryOptions added in v0.16.4

type CodecFactoryOptions struct {
	// Strict configures all serializers in strict mode
	Strict bool
	// Pretty includes a pretty serializer along with the non-pretty one
	Pretty bool
}

CodecFactoryOptions holds the options for configuring CodecFactory behavior

type CodecFactoryOptionsMutator added in v0.16.4

type CodecFactoryOptionsMutator func(*CodecFactoryOptions)

CodecFactoryOptionsMutator takes a pointer to an options struct and then modifies it. Functions implementing this type can be passed to the NewCodecFactory() constructor.

type WithoutConversionCodecFactory

type WithoutConversionCodecFactory struct {
	CodecFactory
}

WithoutConversionCodecFactory is a CodecFactory that will explicitly ignore requests to perform conversion. This wrapper is used while code migrates away from using conversion (such as external clients) and in the future will be unnecessary when we change the signature of NegotiatedSerializer.

func (WithoutConversionCodecFactory) DecoderToVersion

DecoderToVersion returns an decoder that does not do conversion.

func (WithoutConversionCodecFactory) EncoderForVersion

func (f WithoutConversionCodecFactory) EncoderForVersion(serializer runtime.Encoder, version runtime.GroupVersioner) runtime.Encoder

EncoderForVersion returns an encoder that does not do conversion, but does set the group version kind of the object when serialized.

Directories

Path Synopsis
direct
Package direct provides functions for marshaling and unmarshaling between arbitrary Go values and CBOR data, with behavior that is compatible with that of the CBOR serializer.
Package direct provides functions for marshaling and unmarshaling between arbitrary Go values and CBOR data, with behavior that is compatible with that of the CBOR serializer.
Package protobuf provides a Kubernetes serializer for the protobuf format.
Package protobuf provides a Kubernetes serializer for the protobuf format.
Package streaming implements encoder and decoder for streams of runtime.Objects over io.Writer/Readers.
Package streaming implements encoder and decoder for streams of runtime.Objects over io.Writer/Readers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL