serde

package
v0.0.0-...-89602ce Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 18, 2020 License: BSD-3-Clause Imports: 7 Imported by: 2

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deserialize

func Deserialize(domain string, typeVal string, data []byte) (interface{}, error)

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

func RegisterSerdes(serdesToRegister ...Serde) error

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

func Serialize(domain string, typeVal string, data interface{}) ([]byte, error)

Serialize serializes an object (`data`) by delegating to the appropriate Serde identified by the domain and typeVal. This function is thread-safe.

func UnregisterAllSerdes

func UnregisterAllSerdes(t *testing.T)

UnregisterAllSerdes should only be used in test code!!!!! DO NOT USE IN ANYTHING OTHER THAN TESTS

func UnregisterSerdesForDomain

func UnregisterSerdesForDomain(t *testing.T, domain string)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL