tlv

package
v0.0.0-...-f83d8fb Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const MaxValueLength = math.MaxInt32

MaxValueLength denotes the maximum length of the value in bytes.

Variables

This section is empty.

Functions

func WriteBinary

func WriteBinary(w io.Writer, t TypeCode, v []byte) error

WriteBinary TLV-encodes the binary data and writes it to m.

Types

type CallbackFunc

type CallbackFunc func(value []byte) error

CallbackFunc specifies the type of callbacks.

type Registry

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

func New

func New() *Registry

func (*Registry) Handle

func (r *Registry) Handle(rd io.Reader) error

Handle reads the next TLV-encoded message from r and calls the corresponding callback with its value. It returns an error when the message is encoded incorrectly.

func (*Registry) Register

func (r *Registry) Register(t TypeCode, m encoding.BinaryMarshaler, callback CallbackFunc)

Register registers a new type for the TLV-encoder. The type of m will be stored to allow type code selection with Write. The callback is called when a new value of that type is received. Register can be used to re-define the callback of a type, but it panics when a different t is registered for the same type.

func (*Registry) Write

Write TLV-encodes m and writes it to m.

type TypeCode

type TypeCode = byte

TypeCode specifies the type code.

Jump to

Keyboard shortcuts

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