Documentation
¶
Overview ¶
Package serde defines the serialization and deserialization mechanisms.
The serialization works through the implementation of the Message interface that can either support a single format, or a dynamic registration of a format engine for each format.
The deserialization works in a similar fashion but through the Factory interface.
See dela/serde/registry for more advanced control of the formats.
Documentation Last Review: 07.10.2020
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct { ContextEngine // contains filtered or unexported fields }
Context is the context passed to the serialization/deserialization requests.
func NewContext ¶
func NewContext(engine ContextEngine) Context
NewContext returns a new empty context.
func WithFactory ¶
WithFactory adds a factory to the context. The factory will then be availble with the key when deserializing.
func (Context) GetFactory ¶
GetFactory returns the factory associated to the key or nil.
type ContextEngine ¶
type ContextEngine interface { // GetFormat returns the name of the format for this context. GetFormat() Format // Marshal returns the bytes of the message according to the format of the // context. Marshal(message interface{}) ([]byte, error) // Unmarshal populates the message with the data according to the format of // the context. Unmarshal(data []byte, message interface{}) error }
ContextEngine is the interface to implement to create a context.
type Factory ¶
type Factory interface { // Deserialize deserializes the message instantiated from the data. Deserialize(ctx Context, data []byte) (Message, error) }
Factory is the interface that a message factory must implement.
type Fingerprinter ¶
type Fingerprinter interface { // Fingerprint writes a deterministic binary representation of the object // into the writer. Fingerprint(writer io.Writer) error }
Fingerprinter is an interface to fingerprint an object.
type FormatEngine ¶
type FormatEngine interface { // Encode marshals the message according to the format definition. Encode(ctx Context, message Message) ([]byte, error) // Decode unmarshal a message according to the format definition. Decode(ctx Context, data []byte) (Message, error) }
FormatEngine is the interface that a format implementation must implement.
Directories
¶
Path | Synopsis |
---|---|
Package json implements the context engine for a the JSON format.
|
Package json implements the context engine for a the JSON format. |
Package registry defines the format registry mechanism.
|
Package registry defines the format registry mechanism. |
Package xml implements the context engine for the XML encoding.
|
Package xml implements the context engine for the XML encoding. |