etf

package
v1.999.224 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 9 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)

Encode

func NewInvalidTypesError

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

func ReleaseEncodingAtomCache

func ReleaseEncodingAtomCache(l *EncodingAtomCache)

ReleaseEncodingAtomCache

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)

TermProplistIntoStruct 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

func UnregisterType

func UnregisterType(name Atom) error

UnregisterType unregisters type with a given name.

Types

type Alias

type Alias Ref

Alias

func (Alias) String

func (a Alias) String() string

String

type Atom

type Atom string

Atom

func RegisterType

func RegisterType(t interface{}, options RegisterTypeOptions) (Atom, error)

RegisterType registers new type with the given options. It returns a Name of the registered type, which can be used in the UnregisterType function for unregistering this type. Supported types: struct, slice, array, map. Returns an error if this type can not be registered.

type AtomCache

type AtomCache struct {
	In  *AtomCacheIn
	Out *AtomCacheOut
}

func NewAtomCache

func NewAtomCache() AtomCache

NewAtomCache

type AtomCacheIn

type AtomCacheIn struct {
	Atoms [maxCacheItems]*Atom
}

type AtomCacheOut

type AtomCacheOut struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

AtomCache

func (*AtomCacheOut) Append

func (a *AtomCacheOut) Append(atom Atom) (int16, bool)

Append

func (*AtomCacheOut) LastAdded

func (a *AtomCacheOut) LastAdded() (Atom, int16)

LastID

func (*AtomCacheOut) ListSince

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

ListSince

type AtomMapping

type AtomMapping struct {
	MutexIn  sync.RWMutex
	In       map[Atom]Atom
	MutexOut sync.RWMutex
	Out      map[Atom]Atom
}

func NewAtomMapping

func NewAtomMapping() *AtomMapping

NewAtomMapping

type CacheItem

type CacheItem struct {
	ID      int16
	Encoded bool
	Name    Atom
}

CacheItem

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 {
	AtomMapping   *AtomMapping
	FlagBigPidRef bool
}

DecodeOptions

type EncodeOptions

type EncodeOptions struct {
	AtomCache         *AtomCacheOut
	SenderAtomCache   map[Atom]CacheItem
	EncodingAtomCache *EncodingAtomCache
	AtomMapping       *AtomMapping

	// FlagBigPidRef 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.
	FlagBigPidRef bool

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

	NodeName string
	PeerName string
}

EncodeOptions

type EncodingAtomCache

type EncodingAtomCache struct {
	L []CacheItem

	HasLongAtom bool
	// contains filtered or unexported fields
}

EncodingAtomCache

func TakeEncodingAtomCache

func TakeEncodingAtomCache() *EncodingAtomCache

TakeEncodingAtomCache

func (*EncodingAtomCache) Append

func (l *EncodingAtomCache) Append(a CacheItem) uint8

Append

func (*EncodingAtomCache) Delete

func (l *EncodingAtomCache) Delete(atom Atom)

Delete

func (*EncodingAtomCache) Len

func (l *EncodingAtomCache) Len() int

Len

func (*EncodingAtomCache) Reset

func (l *EncodingAtomCache) Reset()

Reset

type Export

type Export struct {
	Module   Atom
	Function Atom
	Arity    int
}

Export

type Function

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

Function

type InvalidStructKeyError

type InvalidStructKeyError struct {
	Term Term
}

func (*InvalidStructKeyError) Error

func (s *InvalidStructKeyError) Error() string

type List

type List []Term

List

func (List) Element

func (l List) Element(i int) Term

Element

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

Map

func (Map) Element

func (m Map) Element(k Term) Term

Element

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
}

Pid

func (Pid) String

func (p Pid) String() string

String

type Port

type Port struct {
	Node     Atom
	ID       uint32
	Creation uint32
}

Port

type ProplistElement

type ProplistElement struct {
	Name  Atom
	Value Term
}

ProplistElement

type Ref

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

Ref

func (Ref) String

func (r Ref) String() string

String

type RegisterTypeOptions

type RegisterTypeOptions struct {
	Name   Atom
	Strict bool
}

RegisterTypeOptins defines custom name for the registering type. Leaving the Name option empty makes the name automatically generated. Strict option defines whether the decoding process causes panic if the decoding value doesn't fit the destination object.

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{}

Term

func Decode

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

Decode

type Tuple

type Tuple []Term

Tuple

func (Tuple) Element

func (t Tuple) Element(i int) Term

Element

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