Documentation ¶
Overview ¶
Package tlv implements NDN Type-Length-Value (TLV) encoding.
Index ¶
- Variables
- func Decode(wire []byte, u Unmarshaler) error
- func Encode(fields ...Field) (wire []byte, e error)
- func EncodeFrom(fields ...Fielder) (wire []byte, e error)
- func EncodeValueOnly(f Fielder) ([]byte, error)
- type DecodingBuffer
- type DecodingElement
- func (de DecodingElement) IsCriticalType() bool
- func (de DecodingElement) Unmarshal(u Unmarshaler) error
- func (de DecodingElement) UnmarshalNNI(max uint64, err *error, rangeErr error) (v uint64)
- func (de DecodingElement) UnmarshalValue(u encoding.BinaryUnmarshaler) error
- func (de DecodingElement) WireAfter() []byte
- type Element
- type EncodingBuffer
- type Field
- func Bytes(b []byte) Field
- func FieldError(e error) Field
- func FieldFunc(f func([]byte) ([]byte, error)) Field
- func TLV(typ uint32, values ...Field) Field
- func TLVBytes(typ uint32, value []byte) Field
- func TLVFrom(typ uint32, values ...Fielder) Field
- func TLVNNI[V constraints.Integer](typ uint32, v V) Field
- type Fielder
- type NNI
- type Unmarshaler
- type VarNum
Constants ¶
This section is empty.
Variables ¶
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") ErrRange = errors.New("out of range") ErrErrorField = errors.New("Error(nil) field") )
Error conditions.
Functions ¶
func Decode ¶
func Decode(wire []byte, u Unmarshaler) error
Decode unmarshals a buffer that contains a single TLV.
func EncodeFrom ¶
EncodeFrom encodes a sequence of Fielders.
func EncodeValueOnly ¶
EncodeValueOnly returns TLV-VALUE of a Fielder created by TLV, TLVFrom, TLVBytes, or TLVNNI.
Types ¶
type DecodingBuffer ¶
type DecodingBuffer []byte
DecodingBuffer recognizes TLV elements.
func (DecodingBuffer) EOF ¶
func (d DecodingBuffer) EOF() bool
EOF returns true if decoder is at end of input.
func (*DecodingBuffer) Element ¶
func (d *DecodingBuffer) Element() (de DecodingElement, e error)
Element recognizes one TLV element from the buffer.
func (*DecodingBuffer) Elements ¶
func (d *DecodingBuffer) Elements() (list []DecodingElement)
Elements recognizes TLV elements from the buffer. Bytes that cannot be recognized as TLV elements are left in the decoder.
func (DecodingBuffer) ErrUnlessEOF ¶
func (d DecodingBuffer) ErrUnlessEOF() error
ErrUnlessEOF returns an error if there is unconsumed input.
type DecodingElement ¶
DecodingElement represents an TLV element during decoding.
func (DecodingElement) IsCriticalType ¶
func (de DecodingElement) IsCriticalType() bool
IsCriticalType returns true if the TLV-TYPE is considered critical for evolvability purpose.
func (DecodingElement) Unmarshal ¶
func (de DecodingElement) Unmarshal(u Unmarshaler) error
Unmarshal unmarshals TLV into a value.
func (DecodingElement) UnmarshalNNI ¶
func (de DecodingElement) UnmarshalNNI(max uint64, err *error, rangeErr error) (v uint64)
UnmarshalNNI unmarshals TLV-VALUE as NNI and checks it's within [0:max] range.
This function has an unusual set of parameters to allow for more compact calling code:
if pkt.Field = uint32(de.UnmarshalNNI(math.MaxUint32, &e, tlv.ErrRange)); e != nil { return e }
func (DecodingElement) UnmarshalValue ¶
func (de DecodingElement) UnmarshalValue(u encoding.BinaryUnmarshaler) error
UnmarshalValue unmarshals TLV-VALUE into a value.
func (DecodingElement) WireAfter ¶
func (de DecodingElement) 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. Zero value is invalid.
type EncodingBuffer ¶
type EncodingBuffer struct {
// contains filtered or unexported fields
}
EncodingBuffer is an encoding buffer. Zero value is an empty buffer.
func (*EncodingBuffer) Append ¶
func (eb *EncodingBuffer) Append(f Field)
Append appends a field. If there's an error, it is saved in the EncodingBuffer.
func (EncodingBuffer) Output ¶
func (eb EncodingBuffer) Output() ([]byte, error)
Output returns encoding output and first error.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
Field is an encodable field. Zero value encodes to nothing.
func FieldError ¶
FieldError creates a Field that generates an error.
func TLVBytes ¶
TLVBytes creates a Field that encodes to TLV element from TLV-TYPE and TLV-VALUE byte slice.
func TLVFrom ¶
TLVFrom creates a Field that encodes to TLV element from TLV-TYPE and TLV-VALUE Fielders.
func TLVNNI ¶
func TLVNNI[V constraints.Integer](typ uint32, v V) Field
TLVNNI creates a Field that encodes to TLV element from TLV-TYPE and TLV-VALUE NonNegativeInteger.
type Fielder ¶
type Fielder interface {
Field() Field
}
Fielder is the interface implemented by an object that can encode itself to a Field.
type NNI ¶
type NNI uint64
NNI is a non-negative integer.
func (*NNI) UnmarshalBinary ¶
UnmarshalBinary decodes this number.
type Unmarshaler ¶
Unmarshaler is the interface implemented by an object that can decode an TLV element representation of itself.