tlv

package
v0.0.0-...-989978f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2020 License: MIT, NIST-PD-fallback Imports: 5 Imported by: 0

Documentation

Overview

Package tlv implements Type-Length-Value (TLV) encoding in Named Data Networking (NDN).

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIncomplete = errors.New("incomplete input")
	ErrTail       = errors.New("junk after end of TLV")
	ErrType       = errors.New("TLV-TYPE out of range")
	ErrCritical   = errors.New("unrecognized critical TLV-TYPE")
)

Simple error conditions.

Functions

func Decode

func Decode(wire []byte, u Unmarshaler) error

Decode unmarshals a buffer that contains a single TLV.

func Encode

func Encode(values ...interface{}) (wire []byte, e error)

Encode encodes a sequence of values. Each value can be []byte, Marshaler, encoding.BinaryMarshaler, or slice of them.

func EncodeTlv

func EncodeTlv(typ uint32, values ...interface{}) (typ1 uint32, value []byte, e error)

EncodeTlv encodes a sequence of values into []byte. It can be used to implement Marshaler.

Types

type Decoder

type Decoder []byte

Decoder recognizes TLV elements.

func (Decoder) EOF

func (d Decoder) EOF() bool

EOF returns true if decoder is at end of input.

func (*Decoder) Element

func (d *Decoder) Element() (de DecoderElement, e error)

Element recognizes one TLV element from start of input.

func (*Decoder) Elements

func (d *Decoder) Elements() (list []DecoderElement)

Elements recognizes TLV elements from start of input. Bytes that cannot be recognized as TLV elements are left in the decoder.

func (Decoder) ErrUnlessEOF

func (d Decoder) ErrUnlessEOF() error

ErrUnlessEOF returns an error if there is unconsumed input.

func (Decoder) Rest

func (d Decoder) Rest() []byte

Rest returns unconsumed input.

type DecoderElement

type DecoderElement struct {
	Element
	Wire  []byte
	After []byte
}

DecoderElement represents an TLV element during decoding.

func (DecoderElement) IsCriticalType

func (de DecoderElement) IsCriticalType() bool

IsCriticalType returns true if the TLV-TYPE is considered critical for evolvability purpose.

func (DecoderElement) Unmarshal

func (de DecoderElement) Unmarshal(u Unmarshaler) error

Unmarshal unmarshals TLV into a value.

func (DecoderElement) UnmarshalNNI

func (de DecoderElement) UnmarshalNNI(ptr interface{}) error

UnmarshalNNI unmarshals TLV-VALUE as NNI, written to a pointer of integer type.

func (DecoderElement) UnmarshalValue

func (de DecoderElement) UnmarshalValue(u encoding.BinaryUnmarshaler) error

UnmarshalValue unmarshals TLV-VALUE into a value.

func (DecoderElement) WireAfter

func (de DecoderElement) WireAfter() []byte

WireAfter returns Wire+After.

type Element

type Element struct {
	// Type is the TLV-TYPE.
	Type uint32
	// Value is the TLV-VALUE.
	Value []byte
}

Element represents a TLV element. The zero Element is invalid.

func MakeElement

func MakeElement(typ uint32, value []byte) (element Element)

MakeElement constructs Element from TLV-TYPE and TLV-VALUE. typ can be any integer type.

func MakeElementNNI

func MakeElementNNI(typ uint32, value interface{}) Element

MakeElementNNI creates Element from TLV-TYPE and TLV-VALUE encoding as NNI.

func (*Element) Decode

func (element *Element) Decode(wire []byte) (rest []byte, e error)

Decode extracts an element from the buffer.

func (Element) Length

func (element Element) Length() int

Length returns TLV-LENGTH.

func (Element) MarshalTlv

func (element Element) MarshalTlv() (typ uint32, value []byte, e error)

MarshalTlv implements Marshaler interface.

func (Element) Size

func (element Element) Size() int

Size returns encoded size.

func (*Element) UnmarshalTlv

func (element *Element) UnmarshalTlv(typ uint32, value []byte) error

UnmarshalTlv implements Unmarshaler interface.

type Marshaler

type Marshaler interface {
	MarshalTlv() (typ uint32, value []byte, e error)
}

Marshaler is the interface implemented by an object that can encode itself into an TLV element.

type NNI

type NNI uint64

NNI is a non-negative integer.

func (NNI) MarshalBinary

func (n NNI) MarshalBinary() (wire []byte, e error)

MarshalBinary encodes this number.

func (NNI) Size

func (n NNI) Size() int

Size returns the wire encoding size.

func (*NNI) UnmarshalBinary

func (n *NNI) UnmarshalBinary(wire []byte) error

UnmarshalBinary decodes this number.

type Unmarshaler

type Unmarshaler interface {
	UnmarshalTlv(typ uint32, value []byte) error
}

Unmarshaler is the interface implemented by an object that can decode an TLV element representation of itself.

type VarNum

type VarNum uint64

VarNum represents a number in variable size encoding for TLV-TYPE or TLV-LENGTH.

func (*VarNum) Decode

func (n *VarNum) Decode(wire []byte) (rest []byte, e error)

Decode extracts a VarNum from the buffer.

func (VarNum) Encode

func (n VarNum) Encode(buf []byte) []byte

Encode appends this number to a buffer.

func (VarNum) Size

func (n VarNum) Size() int

Size returns the wire encoding size.

Jump to

Keyboard shortcuts

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