encode

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Timestamp int8 = -1

Functions

This section is empty.

Types

type EncoderState

type EncoderState struct {
	// contains filtered or unexported fields
}

EncoderState contains data to correctly encode the current type.

func NewEncoderState

func NewEncoderState() *EncoderState

func (*EncoderState) SetExternalTypeHandler

func (e *EncoderState) SetExternalTypeHandler(typeInvolved interface{}, handler ExtUserHandler) error

SetExternalTypeHandler associate a specific data type with a custom encoding function provided by the user. Code is a number between 0 and 127 and indicate the correspondent MessagePack External type code. The handler function receives the value to encode as an empty interface, so it needs to do a type assertion and provide a byte array as result, along with an eventual error (error = nil if there were no errors).

func (*EncoderState) TypeWrapper

func (e *EncoderState) TypeWrapper(value reflect.Value) utils.MessagePackTypeEncoder

TypeWrapper convert a primitive type into its messagepack correspondent type using reflection.

type EncodingStruct

type EncodingStruct struct {
	types.Struct
	// contains filtered or unexported fields
}

EncodingStruct is the internal representation of a Go struct which is used to do the encoding to MessagePack.

func NewEncodingStruct

func NewEncodingStruct(s types.Struct, e *EncoderState) EncodingStruct

func (EncodingStruct) Len

func (e EncodingStruct) Len() int

Len returns the length of the MessagePack encoded struct. It returns 0 if the struct has already been written.

func (EncodingStruct) WriteTo

func (e EncodingStruct) WriteTo(w io.Writer) (int64, error)

WriteTo writes the encoding of the struct value to io.Writer. It implements io.WriterTo interface. It returns the number of written bytes and an optional error. It doesn't write anything if it has already been written, to prevent cyclic reference between multiple structs.

type ExtUserHandler

type ExtUserHandler struct {
	Type    byte
	Encoder func(interface{}) ([]byte, error)
}

ExtUserHandler is a function that handle a custom encode defined by the user, and serializes to a MessagePack External.

Jump to

Keyboard shortcuts

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