tlv

package
v0.1.0-testnet Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const MaxValueBytes = 256

Variables

View Source
var ErrDataNotFound = errors.New("data read hit EOF before specified length was reached")
View Source
var ErrTagEmpty = errors.New("tag contained no parsed data")
View Source
var ErrTagNotFound = errors.New("tag not found in TLV collection")
View Source
var ErrValueLengthExceedsMax = errors.New("value exceeds max allowable length")

Functions

func EncodeTLVList

func EncodeTLVList(tlvList ...TLV) []byte

Takes a list of TLVs and encodes them as serialized bytes in FIFO order

Types

type TLV

type TLV struct {
	Tag    byte
	Length int
	Value  []byte
}

func NewTLV

func NewTLV(tag byte, value []byte) (TLV, error)

Create a TLV struct from a tag identifier and a value represented as bytes

func (*TLV) Encode

func (tlv *TLV) Encode() []byte

Encode a TLV structure as serialized bytes

func (TLV) String

func (tlv TLV) String() string

type TLVCollection

type TLVCollection map[byte][][]byte

func ParseTLVPacket

func ParseTLVPacket(data []byte, constructedTags ...byte) (TLVCollection, error)

Parses a TLV encoded response structure Returning a flattened map where the keys are tags and the value is a slice of raw bytes, one entry for each tag instance found. For any "constructedTags" passed, the parser will recurse into the value of that tag to find internal TLV's and append them to the collection as flattened entries

func (TLVCollection) FindTag

func (coll TLVCollection) FindTag(tag byte) (value []byte, err error)

FindTag takes a tag as input and returns the first instance of the tag's value

func (TLVCollection) FindTags

func (coll TLVCollection) FindTags(tag byte) (value [][]byte, err error)

Findtags takes a tag as input and returns all instances of the tag's values as a slice of slice of byte

func (TLVCollection) GetRemainingTLVs

func (coll TLVCollection) GetRemainingTLVs(tags []byte) (remaining []TLV)

Removes tags from a collection, returning the remaining TLV's Useful for slicing out extended TLVs after the known ones are parsed

type TLVList

type TLVList []TLV

func (TLVList) String

func (tlvlist TLVList) String() string

Jump to

Keyboard shortcuts

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