tlv

package
v0.0.0-...-edc748c Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 10 Imported by: 0

README

TLV

Binary encoding scheme based on the Type-length-value scheme. 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

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 interface {
	GetByte(key uint8) (b byte, exists bool)
	GetBytes(key uint8) (b []byte, exists bool)

	SetByte(key uint8, value byte)
	SetBytes(key uint8, value []byte)

	Remove(key uint8)

	Bytes() []byte

	// NoEntries returns the number of nodes in the container
	NoEntries() int
}

func NewContainer

func NewContainer() Container

func UnmarshalTLVContainer

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

type ContainerMock

type ContainerMock struct {
	mock.Mock
}

func NewContainerMock

func NewContainerMock() *ContainerMock

func (*ContainerMock) Bytes

func (c *ContainerMock) Bytes() []byte

func (*ContainerMock) GetByte

func (c *ContainerMock) GetByte(key uint8) (b byte, exists bool)

func (*ContainerMock) GetBytes

func (c *ContainerMock) GetBytes(key uint8) (b []byte, exists bool)

func (*ContainerMock) NoEntries

func (c *ContainerMock) NoEntries() int

func (*ContainerMock) Remove

func (c *ContainerMock) Remove(key uint8)

func (*ContainerMock) SetByte

func (c *ContainerMock) SetByte(key uint8, value byte)

func (*ContainerMock) SetBytes

func (c *ContainerMock) SetBytes(key uint8, value []byte)

func (*ContainerMock) Size

func (c *ContainerMock) Size() int

type ContainerStub

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

func NewContainerStub

func NewContainerStub() *ContainerStub

func (*ContainerStub) Bytes

func (c *ContainerStub) Bytes() []byte

func (*ContainerStub) GetByte

func (c *ContainerStub) GetByte(key uint8) (b byte, exists bool)

func (*ContainerStub) GetBytes

func (c *ContainerStub) GetBytes(key uint8) (b []byte, exists bool)

func (*ContainerStub) NoEntries

func (c *ContainerStub) NoEntries() int

func (*ContainerStub) Remove

func (c *ContainerStub) Remove(key uint8)

func (*ContainerStub) SetByte

func (c *ContainerStub) SetByte(key uint8, value byte)

func (*ContainerStub) SetBytes

func (c *ContainerStub) SetBytes(key uint8, value []byte)

func (*ContainerStub) Size

func (c *ContainerStub) Size() int

type ErrInvalidTLV8EncodedBuffer

type ErrInvalidTLV8EncodedBuffer string

func (ErrInvalidTLV8EncodedBuffer) Error

type Item

type Item struct {
	Type  uint8
	Value []byte
}

Jump to

Keyboard shortcuts

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