Documentation ¶
Index ¶
- func ApplicationName() string
- func Decode(pb proto.Message, id *resourcepb.Identifier) (driver.Value, error)
- func DecodeBytes(pb proto.Message, id *resourcepb.Identifier) ([]byte, error)
- func DecodeInt64(pb proto.Message, id *resourcepb.Identifier) (int64, error)
- func Encode(pb proto.Message, value driver.Value) (*resourcepb.Identifier, error)
- func Name(pb proto.Message) string
- func Plural() bool
- func RegisterApplication(name string)
- func RegisterCodec(codec Codec, pb proto.Message)
- func ReturnEmpty() bool
- func SetPlural()
- func SetReturnEmpty()
- type Codec
- type Namer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplicationName ¶
func ApplicationName() string
ApplicationName returns application name registered by RegisterApplication.
func Decode ¶
func Decode(pb proto.Message, id *resourcepb.Identifier) (driver.Value, error)
Decode decodes identifier using a codec registered for pb if found.
If codec is not found - and id is nil, the (nil, nil) are returned. - and pb is nil the id is decoded in a fully qualified string value in format specified for Atlas References. - only Resource ID part of the identifier is returned as string value.
func DecodeBytes ¶
func DecodeBytes(pb proto.Message, id *resourcepb.Identifier) ([]byte, error)
DecodeBytes decodes value returned by Decode as []byte. Returns an error if value is not of []byte type.
func DecodeInt64 ¶
func DecodeInt64(pb proto.Message, id *resourcepb.Identifier) (int64, error)
DecodeInt64 decodes value returned by Decode as int64. Returns an error if value is not of int64 type.
func Encode ¶
func Encode(pb proto.Message, value driver.Value) (*resourcepb.Identifier, error)
Encode encodes identifier using a codec registered for pb.
If codec is not found - and value is not of string type an error is returned. - and pb is nil the id is encoded as it would be a string value in fully qualified format - and value is nil the (nil, nil) are returned
If Resource ID part is not empty, the Application Name and Resource Type parts are populated by ApplicationName and Name functions accordingly, otherwise the empty identifier is returned.
func Name ¶
Name returns name of pb. If pb implements Namer interface it is used to return name, otherwise the the proto.MessageName is used to obtain fully qualified resource name.
The only last part of fully qualified resource name is used and converted to lower case. E.g. infoblox.rpc.Identifier -> identifier
If SetPlural is called the 's' symbol is added at the end of resource name.
func Plural ¶
func Plural() bool
Plural returns true if resource.SetPlural was called, otherwise returns false.
func RegisterApplication ¶
func RegisterApplication(name string)
RegisterApplication registers name of the application. Registered name is used by Encode to populate application name of Protocol Buffer Identifier.
func RegisterCodec ¶
RegisterCodec registers codec for a given pb. If pb is nil the codec is registered as default. If codec is nil or registered twice for the same resource the panic is raised.
func ReturnEmpty ¶
func ReturnEmpty() bool
ReturnEmpty returns flag that indicates all nil values of driver.Value type in codecs must be converted to empty instance of Identifier.
func SetPlural ¶
func SetPlural()
SetPlural sets package flag that instructs resource.Name to return name in plural form by adding 's' at the end of the name.
func SetReturnEmpty ¶
func SetReturnEmpty()
SetReturnEmpty sets package flag that indicates all nil values of driver.Value type in codecs must be converted to empty instance of Identifier. Default value is false.
Types ¶
type Codec ¶
type Codec interface { // Encode encodes value to Protocol Buffer representation Encode(driver.Value) (*resourcepb.Identifier, error) // Decode decodes Protocol Buffer representation to the driver.Value Decode(*resourcepb.Identifier) (driver.Value, error) }
Codec defines the interface package uses to encode and decode Protocol Buffer Identifier to the driver.Value. Note that implementation must be thread safe.