Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ce95f68d
Commit
ce95f68d
authored
Oct 30, 2015
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes in codec interfaces
parent
1831a057
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
43 deletions
+47
-43
fixture.go
pkg/client/unversioned/testclient/fixture.go
+9
-2
interfaces.go
pkg/runtime/interfaces.go
+38
-41
No files found.
pkg/client/unversioned/testclient/fixture.go
View file @
ce95f68d
...
...
@@ -43,6 +43,13 @@ type ObjectRetriever interface {
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
// <verb>-<resource> or <verb>-<subresource>-<resource> and attempts to return a runtime
// 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
{
types
map
[
string
][]
runtime
.
Object
last
map
[
string
]
int
scheme
runtime
.
ObjectScheme
scheme
ObjectScheme
decoder
runtime
.
ObjectDecoder
}
...
...
@@ -135,7 +142,7 @@ var _ ObjectRetriever = &objects{}
// 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
// subsequent calls.
func
NewObjects
(
scheme
runtime
.
ObjectScheme
,
decoder
runtime
.
ObjectDecoder
)
ObjectRetriever
{
func
NewObjects
(
scheme
ObjectScheme
,
decoder
runtime
.
ObjectDecoder
)
ObjectRetriever
{
return
objects
{
types
:
make
(
map
[
string
][]
runtime
.
Object
),
last
:
make
(
map
[
string
]
int
),
...
...
pkg/runtime/interfaces.go
View file @
ce95f68d
...
...
@@ -20,54 +20,40 @@ import (
"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
// Codec defines methods for serializing and deserializing API objects.
type
Codec
interface
{
Decoder
Encoder
}
// Decoder defines methods for deserializing API objects into a given type
type
Decoder
interface
{
Decode
(
data
[]
byte
)
(
Object
,
error
)
// TODO: Remove this method?
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
}
// 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.
type
Codec
interface
{
Decoder
Encoder
// TODO: Add method for processing url parameters.
// EncodeParameters(obj Object) (url.Values, error)
}
// ObjectCopier duplicates an object.
type
ObjectCopier
interface
{
// Copy returns an exact copy of the provided Object, or an error if the
// copy could not be completed.
Copy
(
Object
)
(
Object
,
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
// ObjectEncoder turns an object into a byte array. This interface is a
// general form of the Encoder interface
type
ObjectEncoder
interface
{
// EncodeToVersion convert and serializes an object in the internal format
// to a specified output version. An error is returned if the object
// cannot be converted for any reason.
...
...
@@ -75,6 +61,24 @@ type ObjectEncoder interface {
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.
type
ObjectConvertor
interface
{
Convert
(
in
,
out
interface
{})
error
...
...
@@ -103,18 +107,11 @@ type ObjectCreater interface {
New
(
version
,
kind
string
)
(
out
Object
,
err
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.
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
// ObjectCopier duplicates an object.
type
ObjectCopier
interface
{
// Copy returns an exact copy of the provided Object, or an error if the
// copy could not be completed.
Copy
(
Object
)
(
Object
,
error
)
}
// ResourceVersioner provides methods for setting and retrieving
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment