github.com/timstclair/heapster@v0.20.0-alpha1/Godeps/_workspace/src/k8s.io/kubernetes/pkg/runtime/interfaces.go (about) 1 /* 2 Copyright 2014 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package runtime 18 19 import ( 20 "io" 21 "net/url" 22 ) 23 24 // Codec defines methods for serializing and deserializing API objects. 25 type Codec interface { 26 Decoder 27 Encoder 28 } 29 30 // Decoder defines methods for deserializing API objects into a given type 31 type Decoder interface { 32 Decode(data []byte) (Object, error) 33 // TODO: Remove this method? 34 DecodeToVersion(data []byte, version string) (Object, error) 35 DecodeInto(data []byte, obj Object) error 36 // TODO: Remove this method? 37 DecodeIntoWithSpecifiedVersionKind(data []byte, obj Object, kind, version string) error 38 39 DecodeParametersInto(parameters url.Values, obj Object) error 40 } 41 42 // Encoder defines methods for serializing API objects into bytes 43 type Encoder interface { 44 Encode(obj Object) (data []byte, err error) 45 EncodeToStream(obj Object, stream io.Writer) error 46 47 // TODO: Add method for processing url parameters. 48 // EncodeParameters(obj Object) (url.Values, error) 49 } 50 51 // ObjectCodec represents the common mechanisms for converting to and from a particular 52 // binary representation of an object. 53 // TODO: Remove this interface - it is used only in CodecFor() method. 54 type ObjectCodec interface { 55 Decoder 56 57 // EncodeToVersion convert and serializes an object in the internal format 58 // to a specified output version. An error is returned if the object 59 // cannot be converted for any reason. 60 EncodeToVersion(obj Object, outVersion string) ([]byte, error) 61 EncodeToVersionStream(obj Object, outVersion string, stream io.Writer) error 62 } 63 64 // ObjectDecoder is a convenience interface for identifying serialized versions of objects 65 // and transforming them into Objects. It intentionally overlaps with ObjectTyper and 66 // Decoder for use in decode only paths. 67 // TODO: Consider removing this interface? 68 type ObjectDecoder interface { 69 Decoder 70 // DataVersionAndKind returns the version and kind of the provided data, or an error 71 // if another problem is detected. In many cases this method can be as expensive to 72 // invoke as the Decode method. 73 DataVersionAndKind([]byte) (version, kind string, err error) 74 // Recognizes returns true if the scheme is able to handle the provided version and kind 75 // of an object. 76 Recognizes(version, kind string) bool 77 } 78 79 /////////////////////////////////////////////////////////////////////////////// 80 // Non-codec interfaces 81 82 // ObjectConvertor converts an object to a different version. 83 type ObjectConvertor interface { 84 Convert(in, out interface{}) error 85 ConvertToVersion(in Object, outVersion string) (out Object, err error) 86 ConvertFieldLabel(version, kind, label, value string) (string, string, error) 87 } 88 89 // ObjectTyper contains methods for extracting the APIVersion and Kind 90 // of objects. 91 type ObjectTyper interface { 92 // DataVersionAndKind returns the version and kind of the provided data, or an error 93 // if another problem is detected. In many cases this method can be as expensive to 94 // invoke as the Decode method. 95 DataVersionAndKind([]byte) (version, kind string, err error) 96 // ObjectVersionAndKind returns the version and kind of the provided object, or an 97 // error if the object is not recognized (IsNotRegisteredError will return true). 98 ObjectVersionAndKind(Object) (version, kind string, err error) 99 // Recognizes returns true if the scheme is able to handle the provided version and kind, 100 // or more precisely that the provided version is a possible conversion or decoding 101 // target. 102 Recognizes(version, kind string) bool 103 } 104 105 // ObjectCreater contains methods for instantiating an object by kind and version. 106 type ObjectCreater interface { 107 New(version, kind string) (out Object, err error) 108 } 109 110 // ObjectCopier duplicates an object. 111 type ObjectCopier interface { 112 // Copy returns an exact copy of the provided Object, or an error if the 113 // copy could not be completed. 114 Copy(Object) (Object, error) 115 } 116 117 // ResourceVersioner provides methods for setting and retrieving 118 // the resource version from an API object. 119 type ResourceVersioner interface { 120 SetResourceVersion(obj Object, version string) error 121 ResourceVersion(obj Object) (string, error) 122 } 123 124 // SelfLinker provides methods for setting and retrieving the SelfLink field of an API object. 125 type SelfLinker interface { 126 SetSelfLink(obj Object, selfLink string) error 127 SelfLink(obj Object) (string, error) 128 129 // Knowing Name is sometimes necessary to use a SelfLinker. 130 Name(obj Object) (string, error) 131 // Knowing Namespace is sometimes necessary to use a SelfLinker 132 Namespace(obj Object) (string, error) 133 } 134 135 // All api types must support the Object interface. It's deliberately tiny so that this is not an onerous 136 // burden. Implement it with a pointer receiver; this will allow us to use the go compiler to check the 137 // one thing about our objects that it's capable of checking for us. 138 type Object interface { 139 // This function is used only to enforce membership. It's never called. 140 // TODO: Consider mass rename in the future to make it do something useful. 141 IsAnAPIObject() 142 }