etf

package
v1.999.200 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStringTooLong = fmt.Errorf("Encoding error. String too long. Max allowed length is 65535")
	ErrAtomTooLong   = fmt.Errorf("Encoding error. Atom too long. Max allowed UTF-8 chars is 255")
)

Functions

func Encode

func Encode(term Term, b *lib.Buffer, options EncodeOptions) (retErr error)

func NewInvalidTypesError

func NewInvalidTypesError(t reflect.Type, term Term) error

func ReleaseListAtomCache added in v1.999.200

func ReleaseListAtomCache(l *ListAtomCache)

func TermIntoStruct

func TermIntoStruct(term Term, dest interface{}) (err error)

TermIntoStruct transforms 'term' (etf.Term, etf.List, etf.Tuple, etf.Map) into the given 'dest' (could be a struct, map, slice or array). Its a pretty expencive operation in terms of CPU usage so you shouldn't use it on highload parts of your code. Use manual type casting instead.

func TermProplistIntoStruct

func TermProplistIntoStruct(term Term, dest interface{}) (err error)

ProplistIntoStruct transorms given term into the provided struct 'dest'. Proplist is the list of Tuple values with two items { Name , Value }, where Name can be string or Atom and Value must be the same type as it has the field of 'dest' struct with the equivalent name. Its also accepts []ProplistElement as a 'term' value

func TermToString

func TermToString(t Term) (s string, ok bool)

TermToString transforms given term (Atom, []byte, List) to the string

Types

type Alias

type Alias Ref

func (Alias) String

func (a Alias) String() string

type Atom

type Atom string

type AtomCache

type AtomCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewAtomCache

func NewAtomCache(ctx context.Context) *AtomCache

func (*AtomCache) Append added in v1.999.200

func (a *AtomCache) Append(atom Atom)

func (*AtomCache) GetLastID added in v1.999.200

func (a *AtomCache) GetLastID() int16

func (*AtomCache) List added in v1.999.200

func (a *AtomCache) List() [maxCacheItems]Atom

func (*AtomCache) ListSince added in v1.999.200

func (a *AtomCache) ListSince(id int16) []Atom

type CacheItem

type CacheItem struct {
	ID      int16
	Encoded bool
	Name    Atom
}

type Charlist

type Charlist string

Charlist this type is intended to be used to interact with Erlang. Charlist value encodes as a list of int32 numbers in order to support Erlang string with UTF-8 symbols on an Erlang side (Erlang type: [...])

type DecodeOptions

type DecodeOptions struct {
	FlagV4NC        bool
	FlagBigCreation bool
}

type EncodeOptions

type EncodeOptions struct {
	LinkAtomCache     *AtomCache
	WriterAtomCache   map[Atom]CacheItem
	EncodingAtomCache *ListAtomCache

	// FlagV4NC The node accepts a larger amount of data in pids
	// and references (node container types version 4).
	// In the pid case full 32-bit ID and Serial fields in NEW_PID_EXT
	// and in the reference case up to 5 32-bit ID words are now
	// accepted in NEWER_REFERENCE_EXT. Introduced in OTP 24.
	FlagV4NC bool

	// FlagBigCreation The node understands big node creation tags NEW_PID_EXT,
	// NEWER_REFERENCE_EXT.
	FlagBigCreation bool
}

type Export

type Export struct {
	Module   Atom
	Function Atom
	Arity    int
}

type Function

type Function struct {
	Arity  byte
	Unique [16]byte
	Index  uint32
	//	Free      uint32
	Module    Atom
	OldIndex  uint32
	OldUnique uint32
	Pid       Pid
	FreeVars  []Term
}

type InvalidStructKeyError

type InvalidStructKeyError struct {
	Term Term
}

func (*InvalidStructKeyError) Error

func (s *InvalidStructKeyError) Error() string

type List

type List []Term

func (List) Element

func (l List) Element(i int) Term

type ListAtomCache added in v1.999.200

type ListAtomCache struct {
	L []CacheItem

	HasLongAtom bool
	// contains filtered or unexported fields
}

func TakeListAtomCache added in v1.999.200

func TakeListAtomCache() *ListAtomCache

func (*ListAtomCache) Append added in v1.999.200

func (l *ListAtomCache) Append(a CacheItem)

func (*ListAtomCache) Len added in v1.999.200

func (l *ListAtomCache) Len() int

func (*ListAtomCache) Reset added in v1.999.200

func (l *ListAtomCache) Reset()

type ListImproper

type ListImproper []Term

ListImproper as a workaround for the Erlang's improper list [a|b]. Intended to be used to interact with Erlang.

type Map

type Map map[Term]Term

func (Map) Element

func (m Map) Element(k Term) Term

type Marshaler

type Marshaler interface {
	MarshalETF() ([]byte, error)
}

Marshaler interface implemented by types that can marshal themselves into valid ETF binary Interface implementation must be over the object e.g. (MyObject) UnmarshalETF:

	type MyObject struct{}

	func (m MyObject) MarshalETF() ([]byte, error) {
		var encoded []byte
		... encoding routine ...
		return encoded, nil
}

type Pid

type Pid struct {
	Node     Atom
	ID       uint64
	Creation uint32
}

func (Pid) String

func (p Pid) String() string

type Port

type Port struct {
	Node     Atom
	ID       uint32
	Creation uint32
}

type ProplistElement

type ProplistElement struct {
	Name  Atom
	Value Term
}

type Ref

type Ref struct {
	Node     Atom
	Creation uint32
	ID       [5]uint32
}

func (Ref) String

func (r Ref) String() string

type String

type String string

String this type is intended to be used to interact with Erlang. String value encodes as a binary (Erlang type: <<...>>)

type StructPopulatorError

type StructPopulatorError struct {
	Type reflect.Type
	Term Term
}

func (*StructPopulatorError) Error

func (s *StructPopulatorError) Error() string

type Term

type Term interface{}

func Decode

func Decode(packet []byte, cache []Atom, options DecodeOptions) (retTerm Term, retByte []byte, retErr error)

type Tuple

type Tuple []Term

func (Tuple) Element

func (t Tuple) Element(i int) Term

type Unmarshaler

type Unmarshaler interface {
	UnmarshalETF([]byte) error
}

Unmarshaler interface implemented by types that can unmarshal an ETF binary of themselves. Returns error ErrEmpty for []byte{}. Interface implementation must be over pointer to the object e.g. (*MyObject) UnmarshalETF:

type MyObject struct{}

func (m *MyObject) UnmarshalETF(b []byte) error {
	var err error
	... decoding routine ...
	return err
}

Jump to

Keyboard shortcuts

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