Documentation ¶
Overview ¶
Package serde contains the definition of a SERializer-DEserializer concept. This package also includes a global registry of serdes for applications to delegate implementation-agnostic serialization and deserialization to. Serdes are one of the primary plugin interfaces exposed by orc8r to extend services with domain-specific data models and logic.
Index ¶
- func Deserialize(domain string, typeVal string, data []byte) (interface{}, error)
- func RegisterSerdes(serdesToRegister ...Serde) error
- func Serialize(domain string, typeVal string, data interface{}) ([]byte, error)
- func UnregisterAllSerdes(t *testing.T)
- func UnregisterSerdesForDomain(t *testing.T, domain string)
- type BinaryConvertible
- type Serde
- type ValidatableModel
- type ValidateableBinaryConvertible
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Deserialize ¶
Deserialize deserializes a bytearray by delegating to the appropriate Serde identified by the domain and typeVal. This function is thread-safe. If the data parameter is nil or empty, this function will return nil, nil.
func RegisterSerdes ¶
RegisterSerdes will register a collection of Serde implementations with the global Serde registry. The semantics are all-or-nothing: if an error is encountered while registering any Serde, the registry will rollback all changes made. This function is thread-safe.
func Serialize ¶
Serialize serializes an object (`data`) by delegating to the appropriate Serde identified by the domain and typeVal. This function is thread-safe.
func UnregisterAllSerdes ¶
UnregisterAllSerdes should only be used in test code!!!!! DO NOT USE IN ANYTHING OTHER THAN TESTS
func UnregisterSerdesForDomain ¶
UnregisterSerdesForDomain should only be used in test code!!!! DO NOT USE IN ANYTHING OTHER THAN TESTS
Types ¶
type BinaryConvertible ¶
type BinaryConvertible interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler }
BinaryConvertible wraps encoding.BinaryMarshaler and encoding.BinaryUnmarshaler for use in generic serde factory functions.
type Serde ¶
type Serde interface { // GetDomain returns a globally unique key which represents the domain of // this Serde. Serde types are unique within each domain but not across // domains. GetDomain() string // GetType returns a unique key within the domain for the specific Serde // implementation. This represents the type of data that the Serde will be // responsible for serializing and deserialing. GetType() string // Serialize a piece of data Serialize(in interface{}) ([]byte, error) // Deserialize a piece of data Deserialize(in []byte) (interface{}, error) }
Serde (SERializer-DEserializer) implements logic to serialize/deserialize a specific piece of data.
func NewBinarySerde ¶
func NewBinarySerde(domain string, serdeType string, dataInstance BinaryConvertible) Serde
NewBinarySerde returns a Serde implementation for a structure which implements BinaryConvertible. `dataInstance` is expected to be a pointer.
type ValidatableModel ¶
type ValidatableModel interface {
ValidateModel() error
}
ValidateableModel implements a ValidateModel() function that returns whether the instance is valid.
type ValidateableBinaryConvertible ¶
type ValidateableBinaryConvertible interface { BinaryConvertible ValidatableModel }
ValidateableBinaryConvertible wraps both BinaryConvertible, for generic serde factory functions, and ValidateableModel for validations.