mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Changes in codec interfaces
This commit is contained in:
parent
1831a057f1
commit
ce95f68d2a
@ -43,6 +43,13 @@ type ObjectRetriever interface {
|
|||||||
Add(runtime.Object) error
|
Add(runtime.Object) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ObjectScheme abstracts the implementation of common operations on objects.
|
||||||
|
type ObjectScheme interface {
|
||||||
|
runtime.ObjectCreater
|
||||||
|
runtime.ObjectCopier
|
||||||
|
runtime.ObjectTyper
|
||||||
|
}
|
||||||
|
|
||||||
// ObjectReaction returns a ReactionFunc that takes a generic action string of the form
|
// ObjectReaction returns a ReactionFunc that takes a generic action string of the form
|
||||||
// <verb>-<resource> or <verb>-<subresource>-<resource> and attempts to return a runtime
|
// <verb>-<resource> or <verb>-<subresource>-<resource> and attempts to return a runtime
|
||||||
// Object or error that matches the requested action. For instance, list-replicationControllers
|
// Object or error that matches the requested action. For instance, list-replicationControllers
|
||||||
@ -119,7 +126,7 @@ func AddObjectsFromPath(path string, o ObjectRetriever, decoder runtime.Decoder)
|
|||||||
type objects struct {
|
type objects struct {
|
||||||
types map[string][]runtime.Object
|
types map[string][]runtime.Object
|
||||||
last map[string]int
|
last map[string]int
|
||||||
scheme runtime.ObjectScheme
|
scheme ObjectScheme
|
||||||
decoder runtime.ObjectDecoder
|
decoder runtime.ObjectDecoder
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +142,7 @@ var _ ObjectRetriever = &objects{}
|
|||||||
// as a runtime.Object if Status == Success). If multiple PodLists are provided, they
|
// as a runtime.Object if Status == Success). If multiple PodLists are provided, they
|
||||||
// will be returned in order by the Kind call, and the last PodList will be reused for
|
// will be returned in order by the Kind call, and the last PodList will be reused for
|
||||||
// subsequent calls.
|
// subsequent calls.
|
||||||
func NewObjects(scheme runtime.ObjectScheme, decoder runtime.ObjectDecoder) ObjectRetriever {
|
func NewObjects(scheme ObjectScheme, decoder runtime.ObjectDecoder) ObjectRetriever {
|
||||||
return objects{
|
return objects{
|
||||||
types: make(map[string][]runtime.Object),
|
types: make(map[string][]runtime.Object),
|
||||||
last: make(map[string]int),
|
last: make(map[string]int),
|
||||||
|
@ -20,54 +20,40 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ObjectScheme represents common conversions between formal external API versions
|
|
||||||
// and the internal Go structs. ObjectScheme is typically used with ObjectCodec to
|
|
||||||
// transform internal Go structs into serialized versions. There may be many valid
|
|
||||||
// ObjectCodecs for each ObjectScheme.
|
|
||||||
type ObjectScheme interface {
|
|
||||||
ObjectConvertor
|
|
||||||
ObjectTyper
|
|
||||||
ObjectCreater
|
|
||||||
ObjectCopier
|
|
||||||
}
|
|
||||||
|
|
||||||
// ObjectCodec represents the common mechanisms for converting to and from a particular
|
|
||||||
// binary representation of an object.
|
|
||||||
type ObjectCodec interface {
|
|
||||||
ObjectEncoder
|
|
||||||
Decoder
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decoder defines methods for deserializing API objects into a given type
|
|
||||||
type Decoder interface {
|
|
||||||
Decode(data []byte) (Object, error)
|
|
||||||
DecodeToVersion(data []byte, version string) (Object, error)
|
|
||||||
DecodeInto(data []byte, obj Object) error
|
|
||||||
DecodeIntoWithSpecifiedVersionKind(data []byte, obj Object, kind, version string) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encoder defines methods for serializing API objects into bytes
|
|
||||||
type Encoder interface {
|
|
||||||
Encode(obj Object) (data []byte, err error)
|
|
||||||
EncodeToStream(obj Object, stream io.Writer) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// Codec defines methods for serializing and deserializing API objects.
|
// Codec defines methods for serializing and deserializing API objects.
|
||||||
type Codec interface {
|
type Codec interface {
|
||||||
Decoder
|
Decoder
|
||||||
Encoder
|
Encoder
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectCopier duplicates an object.
|
// Decoder defines methods for deserializing API objects into a given type
|
||||||
type ObjectCopier interface {
|
type Decoder interface {
|
||||||
// Copy returns an exact copy of the provided Object, or an error if the
|
Decode(data []byte) (Object, error)
|
||||||
// copy could not be completed.
|
// TODO: Remove this method?
|
||||||
Copy(Object) (Object, error)
|
DecodeToVersion(data []byte, version string) (Object, error)
|
||||||
|
DecodeInto(data []byte, obj Object) error
|
||||||
|
// TODO: Remove this method?
|
||||||
|
DecodeIntoWithSpecifiedVersionKind(data []byte, obj Object, kind, version string) error
|
||||||
|
|
||||||
|
// TODO: Add method for processing url parameters.
|
||||||
|
// DecodeParametersInto(parameters url.Values, obj Object) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectEncoder turns an object into a byte array. This interface is a
|
// Encoder defines methods for serializing API objects into bytes
|
||||||
// general form of the Encoder interface
|
type Encoder interface {
|
||||||
type ObjectEncoder interface {
|
Encode(obj Object) (data []byte, err error)
|
||||||
|
EncodeToStream(obj Object, stream io.Writer) error
|
||||||
|
|
||||||
|
// TODO: Add method for processing url parameters.
|
||||||
|
// EncodeParameters(obj Object) (url.Values, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ObjectCodec represents the common mechanisms for converting to and from a particular
|
||||||
|
// binary representation of an object.
|
||||||
|
// TODO: Remove this interface - it is used only in CodecFor() method.
|
||||||
|
type ObjectCodec interface {
|
||||||
|
Decoder
|
||||||
|
|
||||||
// EncodeToVersion convert and serializes an object in the internal format
|
// EncodeToVersion convert and serializes an object in the internal format
|
||||||
// to a specified output version. An error is returned if the object
|
// to a specified output version. An error is returned if the object
|
||||||
// cannot be converted for any reason.
|
// cannot be converted for any reason.
|
||||||
@ -75,6 +61,24 @@ type ObjectEncoder interface {
|
|||||||
EncodeToVersionStream(obj Object, outVersion string, stream io.Writer) error
|
EncodeToVersionStream(obj Object, outVersion string, stream io.Writer) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ObjectDecoder is a convenience interface for identifying serialized versions of objects
|
||||||
|
// and transforming them into Objects. It intentionally overlaps with ObjectTyper and
|
||||||
|
// Decoder for use in decode only paths.
|
||||||
|
// TODO: Consider removing this interface?
|
||||||
|
type ObjectDecoder interface {
|
||||||
|
Decoder
|
||||||
|
// DataVersionAndKind returns the version and kind of the provided data, or an error
|
||||||
|
// if another problem is detected. In many cases this method can be as expensive to
|
||||||
|
// invoke as the Decode method.
|
||||||
|
DataVersionAndKind([]byte) (version, kind string, err error)
|
||||||
|
// Recognizes returns true if the scheme is able to handle the provided version and kind
|
||||||
|
// of an object.
|
||||||
|
Recognizes(version, kind string) bool
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Non-codec interfaces
|
||||||
|
|
||||||
// ObjectConvertor converts an object to a different version.
|
// ObjectConvertor converts an object to a different version.
|
||||||
type ObjectConvertor interface {
|
type ObjectConvertor interface {
|
||||||
Convert(in, out interface{}) error
|
Convert(in, out interface{}) error
|
||||||
@ -103,18 +107,11 @@ type ObjectCreater interface {
|
|||||||
New(version, kind string) (out Object, err error)
|
New(version, kind string) (out Object, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectDecoder is a convenience interface for identifying serialized versions of objects
|
// ObjectCopier duplicates an object.
|
||||||
// and transforming them into Objects. It intentionally overlaps with ObjectTyper and
|
type ObjectCopier interface {
|
||||||
// Decoder for use in decode only paths.
|
// Copy returns an exact copy of the provided Object, or an error if the
|
||||||
type ObjectDecoder interface {
|
// copy could not be completed.
|
||||||
Decoder
|
Copy(Object) (Object, error)
|
||||||
// DataVersionAndKind returns the version and kind of the provided data, or an error
|
|
||||||
// if another problem is detected. In many cases this method can be as expensive to
|
|
||||||
// invoke as the Decode method.
|
|
||||||
DataVersionAndKind([]byte) (version, kind string, err error)
|
|
||||||
// Recognizes returns true if the scheme is able to handle the provided version and kind
|
|
||||||
// of an object.
|
|
||||||
Recognizes(version, kind string) bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceVersioner provides methods for setting and retrieving
|
// ResourceVersioner provides methods for setting and retrieving
|
||||||
|
Loading…
Reference in New Issue
Block a user