tlv

package
v0.0.0-...-0ca8a0b Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package tlv implements a tag-length-value encoding scheme for use in packing flat data structures with a fixed format. Bytes are encoded in big-endian format. Currently supports serialising the integer types and byte slices.

Index

Constants

View Source
const (
	// TagUint8indicates a single byte.
	TagUint8 byte = iota + 1

	// TagInt8 indicates a signed byte.
	TagInt8

	// TagBytes indicates a variable length byte sequence.
	TagBytes

	// TagInt16 indicates a 16-bit signed integer.
	TagInt16

	// TagUint16 indicates a 16-bit unsigned integer.
	TagUint16

	// TagInt32 indicates a 32-bit signed integer.
	TagInt32

	// TagUint32 indicates a 32-bit unsigned integer.
	TagUint32

	// TagInt64 indicates a 64-bit signed integer.
	TagInt64

	// TagUint64 indicates a 64-bit signed integer.
	TagUint64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

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

A Decoder parses a TLV-encoded structure.

func NewDecoder

func NewDecoder(in []byte) *Decoder

NewDecoder creates a decoder from a byte slice.

func (*Decoder) Decode

func (dec *Decoder) Decode(v interface{}) error

Decode reads a value from the TLV.

func (*Decoder) Length

func (dec *Decoder) Length() int

Length contains the length of the remaining encoded data in the decoder.

func (*Decoder) Zero

func (dec *Decoder) Zero()

Zero wipes and resets the decoder.

type Encoder

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

Encoder is used to serialise values.

func NewFixedEncoder

func NewFixedEncoder(dataLength int, numRecords int) *Encoder

NewFixedEncoder creates a new encoder with a fixed initial size.

func (*Encoder) Bytes

func (enc *Encoder) Bytes() []byte

Bytes returns the current data in the encoder.

func (*Encoder) Encode

func (enc *Encoder) Encode(v interface{}) error

Encode writes a value into the TLV. Note that this cannot be used to write messages or signatures.

func (*Encoder) Length

func (enc *Encoder) Length() int

Length returns the length of the encoded data.

func (*Encoder) Zero

func (enc *Encoder) Zero()

Zero wipes the encoder's state and resets the encoder.

Jump to

Keyboard shortcuts

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