tlv8

package
v0.0.0-...-a127847 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: MIT Imports: 3 Imported by: 0

README

TLV8

Binary encoding scheme based on the Type-length-value scheme. The 8 in TLV8 denotes it uses 8-bits for the Type and Length field. The purpose of this is to strike a balance between expandability and space constraints due to OpenSPA's limited protocol payload size.

Encoding scheme (a single TLV8 item):

| Type (1 byte) | Length (1 byte) | Value |
  • Length: the length of the Value field
  • Value: binary data that is encoded dependent on the Type

Encoding rules:

  • A length of 0 is valid, which means the Value portion of the field is skipped
  • Encoded values of length <= 255 (2^8) should fit into a single TLV8 item
  • Encoded values of length > 255 need to be fragmented
  • A fragmented item requires containing multiple sequential TLV8 items, each TLV8 item containing that fragmented items value length
  • A fragmented item requires all but the last item to be of length 255
  • Multiple non-fragmented TLV8 items with the same Type are allowed only if seperated by a TLV8 item of a different type (or the Type separator, see rule below)
  • Type 0x00 is a separator and has the implicit length of 0

Documentation

Overview

Package tlv8 implements TLV with 1 bytes for the type and 1 byte for the length.

Type field can be anything from 1-255. Type=0 is reserved, internally it is used as a separator between two TLV8 items of the same type.

The library is not safe for concurrency. It is up to the caller to ensure multiple calls from different goroutines are not being triggered to the same Container

Index

Constants

View Source
const (
	ErrNoSeparator               = ErrInvalidTLV8EncodedBuffer("no separator between two items")
	ErrBadFragment               = ErrInvalidTLV8EncodedBuffer("bad fragment")
	ErrOutOfBounds               = ErrInvalidTLV8EncodedBuffer("out of bounds dues to bad length field")
	ErrFragmentItemInvalidLength = ErrInvalidTLV8EncodedBuffer("fragment item invalid length")
	ErrTooShort                  = ErrInvalidTLV8EncodedBuffer("too short")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

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

func NewContainer

func NewContainer() Container

func Parse

func Parse(b []byte) (Container, error)

func (*Container) Add

func (c *Container) Add(i Item)

func (*Container) AddMultiple

func (c *Container) AddMultiple(i []Item)

func (*Container) Bytes

func (c *Container) Bytes() ([]byte, error)

func (*Container) Get

func (c *Container) Get(itemType uint8) []Item

func (*Container) GetAll

func (c *Container) GetAll() []Item

func (*Container) GetFirst

func (c *Container) GetFirst(itemType uint8) (Item, bool)

func (*Container) Output

func (c *Container) Output(w io.Writer) error

type ErrInvalidTLV8EncodedBuffer

type ErrInvalidTLV8EncodedBuffer string

func (ErrInvalidTLV8EncodedBuffer) Error

type Item

type Item struct {
	Type  uint8
	Value []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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