serialization

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader, outStruct interface{}, format Format) error

Decode decodes body from the reader into the struct.

func Encode

func Encode(inStruct interface{}, w io.Writer, format Format) error

Encode encodes the struct in the correct format & writes it to the writer.

func Marshal

func Marshal(inStruct interface{}, format Format) ([]byte, error)

Marshal dumps the struct to bytes in the correct format.

func Unmarshal

func Unmarshal(data []byte, outStruct interface{}, format Format) error

Unmarshal loads the data in the correct format to the struct.

Types

type Format

type Format string

Format represents an available file format.

const (
	MsgPack Format = "application/msgpack"
	JSON    Format = "application/json"
	YAML    Format = "text/x-yaml"
)

Available file formats.

type FormatSerializer

type FormatSerializer interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error

	Encode(interface{}, io.Writer) error
	Decode(io.Reader, interface{}) error
}

FormatSerializer defines the method set for a format to be used by the smart serializer.

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer serializes messages to json.

func (*JSONSerializer) Decode

func (m *JSONSerializer) Decode(r io.Reader, outStruct interface{}) error

Decode unmarshals the struct from a stream.

func (*JSONSerializer) Encode

func (m *JSONSerializer) Encode(inStruct interface{}, w io.Writer) error

Encode marshals the struct to a stream.

func (*JSONSerializer) Marshal

func (m *JSONSerializer) Marshal(inStruct interface{}) ([]byte, error)

Marshal marshals inStruct to msgpack.

func (*JSONSerializer) Unmarshal

func (m *JSONSerializer) Unmarshal(rawBytes []byte, outStruct interface{}) error

Unmarshal unmarshals a raw msgpack message to a struct.

type MsgpackSerializer

type MsgpackSerializer struct {
}

MsgpackSerializer implements msgpack serialization for the smart serializer.

func (*MsgpackSerializer) Decode

func (m *MsgpackSerializer) Decode(r io.Reader, outStruct interface{}) error

Decode unmarshals the struct from a stream.

func (*MsgpackSerializer) Encode

func (m *MsgpackSerializer) Encode(inStruct interface{}, w io.Writer) error

Encode marshals the struct to a stream.

func (*MsgpackSerializer) Marshal

func (m *MsgpackSerializer) Marshal(inStruct interface{}) ([]byte, error)

Marshal marshals inStruct to msgpack.

func (*MsgpackSerializer) Unmarshal

func (m *MsgpackSerializer) Unmarshal(rawBytes []byte, outStruct interface{}) error

Unmarshal unmarshals a raw msgpack message to a struct.

Jump to

Keyboard shortcuts

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