encoding

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 15 Imported by: 46

Documentation

Index

Constants

View Source
const (
	ParamShaNameConvention  = "params-sha256"
	DigestShaNameConvention = "sha256digest"
)
View Source
const VersionImmutable = uint64(0)

VersionImmutable is the version number for immutable objects. A version number of 0 will be used on the wire.

View Source
const VersionUnixMicro = uint64(1<<63 - 16)

VersionUnixMicro is the version number for objects with a unix timestamp. A version number of microseconds since the unix epoch will be used on the wire. Current unix time must be positive, or usage will panic.

Variables

View Source
var (
	HEX_LOWER = []rune("0123456789abcdef")
	HEX_UPPER = []rune("0123456789ABCDEF")
)
View Source
var DISABLE_ALT_URI = os.Getenv("NDN_NAME_ALT_URI") == "0"
View Source
var ErrBufferOverflow = fmt.Errorf("buffer overflow when parsing. One of the TLV Length is wrong")
View Source
var ErrIncorrectDigest = fmt.Errorf("the sha256 digest is missing or incorrect")

Functions

func IsAlphabet

func IsAlphabet(r rune) bool

(AI GENERATED DESCRIPTION): Checks whether a rune is an English alphabet letter (either lowercase a‑z or uppercase A‑Z).

Types

type Buffer

type Buffer []byte

Buffer is a buffer of bytes

func ShrinkLength

func ShrinkLength(buf Buffer, shrink int) Buffer

Shrink length reduce the L by `shrink“ in a TLV encoded buffer `buf`

Precondition:
  `buf` starts with proper Type and Length numbers.
  Length > `shrink`.
  May crash otherwise.

Returns the new buffer containing reduced TL header. May start from the middle of original buffer, but always goes to the end.

type BufferReader

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

func NewBufferReader

func NewBufferReader(buf Buffer) *BufferReader

(AI GENERATED DESCRIPTION): Initializes a BufferReader with the supplied Buffer, setting the starting position to zero.

func (*BufferReader) Delegate

func (r *BufferReader) Delegate(l int) ParseReader

(AI GENERATED DESCRIPTION): Creates a new `ParseReader` that reads the next `l` bytes of the buffer (advancing the current position) or returns an empty reader if the requested length is out of bounds.

func (*BufferReader) Length

func (r *BufferReader) Length() int

(AI GENERATED DESCRIPTION): Returns the number of bytes currently stored in the BufferReader’s internal buffer.

func (*BufferReader) Pos

func (r *BufferReader) Pos() int

(AI GENERATED DESCRIPTION): Returns the current read position of the BufferReader.

func (*BufferReader) Range

func (r *BufferReader) Range(start, end int) Wire

(AI GENERATED DESCRIPTION): Returns a Wire slice of the buffer between `start` (inclusive) and `end` (exclusive), or nil if the indices are out of bounds.

func (*BufferReader) Read

func (r *BufferReader) Read(b []byte) (int, error)

(AI GENERATED DESCRIPTION): Copies data from the BufferReader's internal buffer into the supplied byte slice, advancing the read position and returning io.EOF when the buffer is fully consumed.

func (*BufferReader) ReadBuf

func (r *BufferReader) ReadBuf(l int) (Buffer, error)

(AI GENERATED DESCRIPTION): ReadBuf reads l bytes from the internal buffer, advancing the read position, and returns an io.ErrUnexpectedEOF error if the buffer does not contain enough data.

func (*BufferReader) ReadByte

func (r *BufferReader) ReadByte() (byte, error)

(AI GENERATED DESCRIPTION): Returns the next byte from the internal buffer, or io.EOF if the end of the buffer has been reached.

func (*BufferReader) ReadWire

func (r *BufferReader) ReadWire(l int) (Wire, error)

(AI GENERATED DESCRIPTION): Reads `l` bytes from the reader’s internal buffer, returns them as a `Wire`, advances the read position, and signals `EOF` or `UnexpectedEOF` if the buffer does not contain enough data.

func (*BufferReader) Seek

func (r *BufferReader) Seek(offset int64, whence int) (int64, error)

(AI GENERATED DESCRIPTION): Adjusts the reader’s internal position within its buffer according to the given offset and whence, enforcing bounds and returning an error for invalid parameters.

func (*BufferReader) Skip

func (r *BufferReader) Skip(n int) error

(AI GENERATED DESCRIPTION): Advances the reader’s current position by n bytes, erroring if the resulting index would be negative or beyond the buffer’s length.

func (*BufferReader) UnreadByte

func (r *BufferReader) UnreadByte() error

(AI GENERATED DESCRIPTION): Decrements the reader's position by one byte so the next read returns the same byte again, returning an error if the position is already at the start of the buffer.

type Component

type Component struct {
	Typ TLNum
	Val []byte
}

func ComponentFromBytes

func ComponentFromBytes(buf []byte) (Component, error)

(AI GENERATED DESCRIPTION): Parses a byte slice into a Component by creating a BufferView and reading the component, returning the Component and any parsing error.

func ComponentFromStr

func ComponentFromStr(s string) (Component, error)

(AI GENERATED DESCRIPTION): Parses the given string into a Component value, returning the parsed component and an error if the string cannot be interpreted as a component.

func ComponentFromTlvStr added in v1.5.0

func ComponentFromTlvStr(s string) (Component, error)

ComponentFromTlvStr parses the output of TlvStr into a Component.

func NewByteOffsetComponent

func NewByteOffsetComponent(off uint64) Component

(AI GENERATED DESCRIPTION): Creates a byte‑offset name component with the given offset value.

func NewBytesComponent

func NewBytesComponent(typ TLNum, val []byte) Component

(AI GENERATED DESCRIPTION): Constructs a new Component with the specified TLNum type and raw byte slice value.

func NewGenericBytesComponent added in v1.5.0

func NewGenericBytesComponent(val []byte) Component

(AI GENERATED DESCRIPTION): Creates a name component of type GenericNameComponent using the supplied byte slice.

func NewGenericComponent added in v1.5.0

func NewGenericComponent(val string) Component

(AI GENERATED DESCRIPTION): Creates a generic name component with the supplied string value.

func NewKeywordComponent added in v1.5.0

func NewKeywordComponent(val string) Component

(AI GENERATED DESCRIPTION): Creates a keyword name component initialized with the supplied string value.

func NewNumberComponent

func NewNumberComponent(typ TLNum, val uint64) Component

(AI GENERATED DESCRIPTION): Creates a new Component with the specified TLNum type, encoding the given uint64 value as a natural-number byte slice.

func NewSegmentComponent

func NewSegmentComponent(seg uint64) Component

(AI GENERATED DESCRIPTION): Creates a name component that represents a segment number, returning a Component with the given segment value.

func NewSequenceNumComponent

func NewSequenceNumComponent(seq uint64) Component

(AI GENERATED DESCRIPTION): Creates a name component that represents a sequence number, using the supplied uint64 value.

func NewStringComponent

func NewStringComponent(typ TLNum, val string) Component

(AI GENERATED DESCRIPTION): Creates a Component with the specified TLNum type and a string value encoded into a byte slice.

func NewTimestampComponent

func NewTimestampComponent(t uint64) Component

(AI GENERATED DESCRIPTION): Creates a timestamp name component that holds the supplied 64‑bit unsigned integer.

func NewVersionComponent

func NewVersionComponent(v uint64) Component

(AI GENERATED DESCRIPTION): Creates a name component of type *Version* containing the supplied unsigned integer value.

func ParseComponent

func ParseComponent(buf Buffer) (Component, int)

(AI GENERATED DESCRIPTION): Parses a TLV‑encoded component from the supplied buffer, extracting its type and value and returning the component together with the total number of bytes consumed.

func (Component) Append added in v1.4.3

func (c Component) Append(rest ...Component) Name

(AI GENERATED DESCRIPTION): Constructs a Name consisting of this component followed by the provided components.

func (Component) Bytes

func (c Component) Bytes() []byte

(AI GENERATED DESCRIPTION): Returns the fully encoded byte slice representation of the Component.

func (Component) CanonicalString

func (c Component) CanonicalString() string

(AI GENERATED DESCRIPTION): Returns a canonical string representation of a name component, prefixing the component type number and “=” for non‑generic types and then appending the component’s value formatted as text.

func (Component) Clone

func (c Component) Clone() Component

(AI GENERATED DESCRIPTION): Creates a copy of a Component, duplicating its type and cloning the underlying value slice.

func (Component) Compare

func (c Component) Compare(rhs ComponentPattern) int

(AI GENERATED DESCRIPTION): Compares this Component to another ComponentPattern, returning –1, 0, or 1 according to component type, value length, and byte‑wise value ordering, with Components always considered less than non‑Component patterns.

func (Component) ComponentPatternTrait

func (c Component) ComponentPatternTrait() ComponentPattern

(AI GENERATED DESCRIPTION): Returns the receiver component as a `ComponentPattern`, allowing it to satisfy the `ComponentPattern` interface.

func (Component) EncodeInto

func (c Component) EncodeInto(buf Buffer) int

(AI GENERATED DESCRIPTION): Encodes a component's type and value into the supplied buffer—writing the type, the value’s length, and the value bytes—and returns the total number of bytes written.

func (Component) EncodingLength

func (c Component) EncodingLength() int

(AI GENERATED DESCRIPTION): Calculates the total byte length needed to encode a component by adding the length of its type, the length of its value’s length field, and the value’s own byte length.

func (Component) Equal

func (c Component) Equal(rhs ComponentPattern) bool

(AI GENERATED DESCRIPTION): Compares a Component with another ComponentPattern for equality by checking type and value, correctly handling both value and pointer implementations of Component.

func (Component) FromMatching

func (c Component) FromMatching(m Matching) (*Component, error)

(AI GENERATED DESCRIPTION): Creates a new Component instance from the current component, ignoring the supplied matching argument.

func (Component) Hash

func (c Component) Hash() uint64

Hash returns the hash of the component

func (Component) IsByteOffset added in v1.5.0

func (c Component) IsByteOffset() bool

(AI GENERATED DESCRIPTION): Checks whether the component is a byte‑offset name component.

func (Component) IsGeneric added in v1.5.0

func (c Component) IsGeneric(text string) bool

(AI GENERATED DESCRIPTION): Returns true if the component is a generic name component whose value equals the supplied text.

func (Component) IsKeyword added in v1.5.0

func (c Component) IsKeyword(keyword string) bool

(AI GENERATED DESCRIPTION): Checks if the component is a keyword component whose value exactly matches the supplied keyword string.

func (Component) IsMatch

func (c Component) IsMatch(value Component) bool

(AI GENERATED DESCRIPTION): Determines whether the component matches another component by value equality.

func (Component) IsSegment added in v1.5.0

func (c Component) IsSegment() bool

(AI GENERATED DESCRIPTION): Determines whether the component represents a segment name component.

func (Component) IsSequenceNum added in v1.5.0

func (c Component) IsSequenceNum() bool

(AI GENERATED DESCRIPTION): Checks if the component represents a sequence number (i.e., its type equals `TypeSequenceNumNameComponent`).

func (Component) IsTimestamp added in v1.5.0

func (c Component) IsTimestamp() bool

(AI GENERATED DESCRIPTION): Determines whether the component is a timestamp name component.

func (Component) IsVersion added in v1.5.0

func (c Component) IsVersion() bool

(AI GENERATED DESCRIPTION): Checks whether the component’s type indicates it is a version component in a name.

func (Component) Length

func (c Component) Length() TLNum

(AI GENERATED DESCRIPTION): Returns the byte length of a Component’s value as a TLNum.

func (Component) Match

func (Component) Match(value Component, m Matching)

(AI GENERATED DESCRIPTION): Matches the receiver Component against the provided value and records any match results in the supplied Matching object.

func (Component) NumberVal

func (c Component) NumberVal() uint64

NumberVal returns the value of the component as a number

func (Component) String

func (c Component) String() string

(AI GENERATED DESCRIPTION): Returns the serialized string representation of the Component.

func (Component) TlvStr added in v1.5.0

func (c Component) TlvStr() string

TlvStr returns the TLV encoding of a Component as a string. This is a lot faster than converting to a URI string.

func (Component) WriteTo added in v1.4.3

func (c Component) WriteTo(sb *strings.Builder) int

(AI GENERATED DESCRIPTION): Writes a component’s type and value into the supplied `strings.Builder` as a `type=value` pair—using a special formatter for known component types (or numeric type IDs if alternative URI formatting is disabled)—and returns the number of bytes written.

type ComponentPattern

type ComponentPattern interface {
	// ComponentPatternTrait returns the type trait of Component or Pattern
	// This is used to make ComponentPattern a union type of Component or Pattern
	// Component | Pattern does not work because we need a mixed list NamePattern
	ComponentPatternTrait() ComponentPattern

	// String returns the string of the component, with naming conventions.
	// Since naming conventions are not standardized, this should not be used for purposes other than logging.
	// please use CanonicalString() for stable string representation.
	String() string

	// CanonicalString returns the string representation of the component without naming conventions.
	CanonicalString() string

	// Compare returns an integer comparing two components lexicographically.
	// It compares the type number first, and then its value.
	// A component is always less than a pattern.
	// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
	Compare(ComponentPattern) int

	// Equal returns the two components/patterns are the same.
	Equal(ComponentPattern) bool

	// IsMatch returns if the Component value matches with the current component/pattern.
	IsMatch(value Component) bool

	// Match matches the current pattern/component with the value, and put the matching into the Matching map.
	Match(value Component, m Matching)

	// FromMatching initiates the pattern from the Matching map.
	FromMatching(m Matching) (*Component, error)
}

func ComponentPatternFromStr

func ComponentPatternFromStr(s string) (ComponentPattern, error)

(AI GENERATED DESCRIPTION): Parses a string into a ComponentPattern, interpreting angle‑bracketed syntax as a generic or typed component pattern (e.g., `<foo>` or `<Type=foo>`) and delegating plain strings to the standard component parser.

type ErrFailToParse

type ErrFailToParse struct {
	TypeNum TLNum
	Err     error
}

func (ErrFailToParse) Error

func (e ErrFailToParse) Error() string

(AI GENERATED DESCRIPTION): Generates an error string indicating that parsing of a specific field failed, displaying the field’s type number and the underlying error.

func (ErrFailToParse) Unwrap

func (e ErrFailToParse) Unwrap() error

(AI GENERATED DESCRIPTION): Unwrap returns the underlying error stored in the ErrFailToParse error wrapper.

type ErrFormat

type ErrFormat struct {
	Msg string
}

func (ErrFormat) Error

func (e ErrFormat) Error() string

(AI GENERATED DESCRIPTION): Returns the stored error message string of an ErrFormat error instance.

type ErrIncompatibleType

type ErrIncompatibleType struct {
	Name    string
	ValType string
	TypeNum TLNum
	Value   any
}

func (ErrIncompatibleType) Error

func (e ErrIncompatibleType) Error() string

(AI GENERATED DESCRIPTION): Formats an error message for an incompatible field type, showing the field name, type number, expected type, and the actual value that caused the mismatch.

type ErrNotFound

type ErrNotFound struct {
	Key string
}

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

(AI GENERATED DESCRIPTION): Returns an error string indicating that the specified key was not found.

type ErrSkipRequired

type ErrSkipRequired struct {
	Name    string
	TypeNum TLNum
}

func (ErrSkipRequired) Error

func (e ErrSkipRequired) Error() string

(AI GENERATED DESCRIPTION): Formats an error message indicating that a required field (identified by its name and type number) is missing from the input.

type ErrUnexpected

type ErrUnexpected struct {
	Err error
}

func (ErrUnexpected) Error

func (e ErrUnexpected) Error() string

(AI GENERATED DESCRIPTION): Formats and returns a descriptive error string for an unexpected parsing error, prefixing the underlying error message.

func (ErrUnexpected) Unwrap

func (e ErrUnexpected) Unwrap() error

(AI GENERATED DESCRIPTION): Retrieves the underlying error wrapped by ErrUnexpected.

type ErrUnrecognizedField

type ErrUnrecognizedField struct {
	TypeNum TLNum
}

func (ErrUnrecognizedField) Error

func (e ErrUnrecognizedField) Error() string

(AI GENERATED DESCRIPTION): Formats and returns an error message indicating that an unrecognized field with a critical type number exists, including that type number.

type Matching

type Matching map[string][]byte

type Name

type Name []Component

func NameFromBytes

func NameFromBytes(buf []byte) (Name, error)

NameFromBytes parses a URI byte slice into a Name

func NameFromStr

func NameFromStr(s string) (Name, error)

NameFromStr parses a URI string into a Name

func NameFromTlvStr added in v1.5.0

func NameFromTlvStr(s string) (Name, error)

NameFromFStr parses the output of FStr into a Name.

func (Name) Append added in v1.4.3

func (n Name) Append(rest ...Component) Name

Append appends one or more components to a shallow copy of the name. Using this function is recommended over the in-built `append`. A copy will not be created for chained appends.

func (Name) At added in v1.5.0

func (n Name) At(i int) Component

Get the ith component of a Name. If i is out of range, a zero component is returned. Negative values start from the end.

func (Name) Bytes

func (n Name) Bytes() []byte

Bytes returns the encoded bytes of a Name

func (Name) BytesInner added in v1.5.0

func (n Name) BytesInner() []byte

BytesInner returns the encoded bytes of a Name **excluding** the TL prefix.

func (Name) Clone

func (n Name) Clone() Name

Clone returns a deep copy of a Name

func (Name) Compare

func (n Name) Compare(rhs Name) int

(AI GENERATED DESCRIPTION): Compares two `Name` values lexicographically by sequentially comparing each component, returning –1, 0, or 1 to indicate whether the left name is less than, equal to, or greater than the right name.

func (Name) EncodeInto

func (n Name) EncodeInto(buf Buffer) int

EncodeInto encodes a Name into a Buffer **excluding** the TL prefix. Please use Bytes() to get the fully encoded name.

func (Name) EncodingLength

func (n Name) EncodingLength() int

EncodingLength computes a Name's length after encoding **excluding** the TL prefix.

func (Name) Equal

func (n Name) Equal(rhs Name) bool

(AI GENERATED DESCRIPTION): Determines whether two Name objects represent the same name sequence by comparing their lengths and, if needed, performing component‑wise equality checks.

func (Name) Hash

func (n Name) Hash() uint64

Hash returns the hash of the name

func (Name) IsPrefix

func (n Name) IsPrefix(rhs Name) bool

(AI GENERATED DESCRIPTION): Returns true if the name n is a prefix of the given name rhs.

func (Name) Prefix added in v1.5.0

func (n Name) Prefix(i int) Name

Get a name prefix with the first i components. If i is zero, an empty name is returned. If i is negative, i components are removed from the end. Note that the returned name is not a deep copy.

func (Name) PrefixHash

func (n Name) PrefixHash() []uint64

PrefixHash returns the hash value of all prefixes of the name ret[n] means the hash of the prefix of length n. ret[0] is the same for all names.

func (Name) String

func (n Name) String() string

(AI GENERATED DESCRIPTION): Converts a Name into its canonical string form, prefixing each component with a slash and handling empty or root names so that an empty last component is represented by a trailing slash.

func (Name) TlvStr added in v1.5.0

func (n Name) TlvStr() string

TlvStr returns the TLV encoding of a Name as a string.

func (Name) ToFullName

func (n Name) ToFullName(rawData Wire) Name

(AI GENERATED DESCRIPTION): Adds an implicit SHA‑256 digest component to the name based on the supplied raw data, unless the name already ends with an implicit digest component.

func (Name) WithVersion added in v1.5.0

func (n Name) WithVersion(v uint64) Name

WithVersion appends a version component to the name.

type NamePattern

type NamePattern []ComponentPattern

func NamePatternFromStr

func NamePatternFromStr(s string) (NamePattern, error)

NamePatternFromStr parses a string into a NamePattern

func (NamePattern) Compare

func (n NamePattern) Compare(rhs NamePattern) int

(AI GENERATED DESCRIPTION): Compares two `NamePattern` objects lexicographically, returning –1 if the receiver is smaller, 1 if it is larger, or 0 if the two patterns are equal.

func (NamePattern) Equal

func (n NamePattern) Equal(rhs NamePattern) bool

(AI GENERATED DESCRIPTION): Checks whether two NamePattern values are equal by comparing their lengths and each corresponding element.

func (NamePattern) FromMatching

func (n NamePattern) FromMatching(m Matching) (Name, error)

(AI GENERATED DESCRIPTION): Creates a concrete Name from the NamePattern by applying each component’s matching logic to the supplied Matching context.

func (NamePattern) IsPrefix

func (n NamePattern) IsPrefix(rhs NamePattern) bool

(AI GENERATED DESCRIPTION): Checks whether the receiver NamePattern is a prefix of the specified rhs NamePattern.

func (NamePattern) Match

func (n NamePattern) Match(name Name, m Matching)

(AI GENERATED DESCRIPTION): Matches each component of a NamePattern against the corresponding component of a Name, recording the results in the provided Matching object.

func (NamePattern) String

func (n NamePattern) String() string

(AI GENERATED DESCRIPTION): Generates a string representation of a NamePattern by concatenating each component prefixed with “/”, defaulting to “/” when empty, and appending a trailing slash when the final component is an empty generic name component.

type Nat

type Nat uint64

Nat is a TLV natural number

func ParseNat

func ParseNat(buf Buffer) (val Nat, pos int, err error)

(AI GENERATED DESCRIPTION): Parses a big‑endian natural number from a 1, 2, 4, or 8‑byte buffer, returning the value, its length, or an error if the length is unsupported.

func (Nat) Bytes

func (v Nat) Bytes() []byte

(AI GENERATED DESCRIPTION): Returns a byte slice containing the encoded representation of the Nat by allocating a buffer sized to its encoding length and writing the Nat into that buffer.

func (Nat) EncodeInto

func (v Nat) EncodeInto(buf Buffer) int

(AI GENERATED DESCRIPTION): Encodes a Nat value into the provided buffer using the fewest big‑endian bytes necessary (1, 2, 4, or 8) and returns the number of bytes written.

func (Nat) EncodingLength

func (v Nat) EncodingLength() int

(AI GENERATED DESCRIPTION): Returns the minimal number of bytes (1, 2, 4, or 8) needed to represent the Nat value in a variable‑length numeric encoding.

type ParseReader

type ParseReader interface {
	io.Reader
	io.ByteScanner

	// ReadWire reads a list of buffers in place without copy.
	// It always tries to read the required length of bytes.
	ReadWire(l int) (Wire, error)

	// ReadBuf reads a continuous buffer, trying to avoid copy.
	ReadBuf(l int) (Buffer, error)

	// Range returns a wire that contains the bytes between start and end, without copy.
	Range(start, end int) Wire

	// Pos returns the current position in the buffer/wire.
	Pos() int

	// Length returns the length of the buffer/wire.
	Length() int

	// Skip skips the next n bytes.
	Skip(n int) error

	// Delegate returns a new ParseReader that starts from the current position with length l.
	// The result is equivalent to the following:
	//
	//   start := r.Pos()
	//   r.Skip(l)
	//   return r.Range(start, r.Pos())
	Delegate(l int) ParseReader
}

ParseReader is an interface operating on Buffer and Wire

type Pattern

type Pattern struct {
	Typ TLNum
	Tag string
}

func (Pattern) CanonicalString

func (p Pattern) CanonicalString() string

(AI GENERATED DESCRIPTION): Produces a canonical string representation of a Pattern, outputting `<Tag>` for generic name components and `<Typ=Tag>` for all other components.

func (Pattern) Compare

func (p Pattern) Compare(rhs ComponentPattern) int

(AI GENERATED DESCRIPTION): Compares this `Pattern` to another `ComponentPattern`, ordering first by component type and then by tag string, treating non‑Pattern components as greater.

func (Pattern) ComponentPatternTrait

func (p Pattern) ComponentPatternTrait() ComponentPattern

(AI GENERATED DESCRIPTION): Returns the Pattern value itself as a ComponentPattern, effectively casting the Pattern to the ComponentPattern interface.

func (Pattern) Equal

func (p Pattern) Equal(rhs ComponentPattern) bool

(AI GENERATED DESCRIPTION): Checks whether a `Pattern` is equal to another `ComponentPattern`, returning true only if the other is a `Pattern` (or pointer to one) with the same `Typ` and `Tag` values.

func (Pattern) FromMatching

func (p Pattern) FromMatching(m Matching) (*Component, error)

(AI GENERATED DESCRIPTION): Creates a Component from a matching value identified by the pattern’s tag, returning an ErrNotFound if the tag is absent.

func (Pattern) IsMatch

func (p Pattern) IsMatch(value Component) bool

(AI GENERATED DESCRIPTION): Checks whether a Component’s type matches the Pattern’s type.

func (Pattern) Match

func (p Pattern) Match(value Component, m Matching)

(AI GENERATED DESCRIPTION): Records the byte value of a matched component into the given matching map, using the pattern’s tag as the key.

func (Pattern) String

func (p Pattern) String() string

(AI GENERATED DESCRIPTION): Generates a human‑readable string for a `Pattern`, formatting its tag and type as `<name=tag>` if a conversion name exists, `<tag>` for a generic name component, or `<type=tag>` otherwise.

type PlaceHolder

type PlaceHolder struct{}

PlaceHolder is an empty structure that used to give names of procedure arguments.

type TLNum

type TLNum uint64

TLNum is a TLV Type or Length number

const (
	TypeInvalidComponent                TLNum = 0x00
	TypeImplicitSha256DigestComponent   TLNum = 0x01
	TypeParametersSha256DigestComponent TLNum = 0x02
	TypeGenericNameComponent            TLNum = 0x08
	TypeKeywordNameComponent            TLNum = 0x20
	TypeSegmentNameComponent            TLNum = 0x32
	TypeByteOffsetNameComponent         TLNum = 0x34
	TypeVersionNameComponent            TLNum = 0x36
	TypeTimestampNameComponent          TLNum = 0x38
	TypeSequenceNumNameComponent        TLNum = 0x3a
)
const TypeName TLNum = 0x07

func ParseTLNum

func ParseTLNum(buf Buffer) (val TLNum, pos int)

ParseTLNum parses a TLNum from a buffer. It is supposed to be used internally, so panic on index out of bounds.

func (TLNum) EncodeInto

func (v TLNum) EncodeInto(buf Buffer) int

(AI GENERATED DESCRIPTION): Encodes a TLNum value into the provided buffer using a variable-length integer format, returning the number of bytes written.

func (TLNum) EncodingLength

func (v TLNum) EncodingLength() int

(AI GENERATED DESCRIPTION): Computes the number of bytes needed to encode a TLNum value using the NDN variable‑length TLV format.

type Wire

type Wire []Buffer

Wire is a collection of Buffer. May be allocated in non-contiguous memory.

func (Wire) Join

func (w Wire) Join() []byte

(AI GENERATED DESCRIPTION): Combines multiple byte slices in a `Wire` into one contiguous byte slice.

func (Wire) Length

func (w Wire) Length() uint64

(AI GENERATED DESCRIPTION): Calculates and returns the cumulative byte length of all elements contained within the Wire.

type WireReader

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

WireReader is used for reading from a Wire. It is used when parsing a fragmented packet.

func NewWireReader

func NewWireReader(w Wire) *WireReader

(AI GENERATED DESCRIPTION): Creates a new WireReader for the supplied wire, initializing segment and position to zero and precomputing cumulative segment sizes for efficient traversal.

func (*WireReader) Delegate

func (r *WireReader) Delegate(l int) ParseReader

(AI GENERATED DESCRIPTION): Delegates the next l bytes from the current WireReader to a new ParseReader, advancing the original reader’s position and returning either a buffer or a new WireReader that spans exactly that byte range.

func (*WireReader) Length

func (r *WireReader) Length() int

(AI GENERATED DESCRIPTION): Returns the cumulative byte length of the data parsed so far by this WireReader.

func (*WireReader) Pos

func (r *WireReader) Pos() int

(AI GENERATED DESCRIPTION): Returns the current absolute read position in the wire buffer, including any accumulated segment offsets.

func (*WireReader) Range

func (r *WireReader) Range(start, end int) Wire

(AI GENERATED DESCRIPTION): Extracts and returns a Wire comprising the bytes from the original WireReader between the specified start and end offsets, preserving segment boundaries, or nil if the range is out of bounds.

func (*WireReader) Read

func (r *WireReader) Read(b []byte) (int, error)

(AI GENERATED DESCRIPTION): Reads bytes from the wire buffer into the supplied slice, advancing the read position and returning `io.EOF` once all segments have been consumed.

func (*WireReader) ReadBuf

func (r *WireReader) ReadBuf(l int) (Buffer, error)

(AI GENERATED DESCRIPTION): Reads up to `l` bytes from a segmented wire buffer, returning a contiguous `Buffer` that may span multiple segments, or `io.ErrUnexpectedEOF` if the requested data exceeds the available data.

func (*WireReader) ReadByte

func (r *WireReader) ReadByte() (byte, error)

(AI GENERATED DESCRIPTION): Reads the next byte from the wire buffer, advancing the internal position and returning `io.EOF` when the buffer is exhausted.

func (*WireReader) ReadWire

func (r *WireReader) ReadWire(l int) (Wire, error)

(AI GENERATED DESCRIPTION): Reads `l` bytes from the WireReader’s segmented buffer, returning a `Wire` slice that spans the needed segments and updates the reader’s position, or an error if the buffer ends before `l` bytes are available.

func (*WireReader) Skip

func (r *WireReader) Skip(n int) error

(AI GENERATED DESCRIPTION): Skips forward `n` bytes in the wire buffer, advancing across segment boundaries, and returns an error if `n` is negative or the skip would run past the end of the data.

func (*WireReader) UnreadByte

func (r *WireReader) UnreadByte() error

(AI GENERATED DESCRIPTION): Rewinds the WireReader by one byte, moving the read position back by a single byte across segment boundaries and returning an error if already at the very start.

type WireView added in v1.5.0

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

WireView is a parsing view of a Wire. It lives entirely on the stack and fits in a cache line.

func NewBufferView added in v1.5.0

func NewBufferView(buf Buffer) WireView

(AI GENERATED DESCRIPTION): Creates a `WireView` that wraps the supplied `Buffer` so it can be treated as a wire representation.

func NewWireView added in v1.5.0

func NewWireView(wire Wire) WireView

(AI GENERATED DESCRIPTION): Creates a WireView from the given wire segments, precomputing the total byte length of the data.

func (*WireView) CopyN added in v1.5.0

func (r *WireView) CopyN(w io.Writer, size int) (int, error)

(AI GENERATED DESCRIPTION): Copies up to `size` bytes from the `WireView` into the supplied `io.Writer`, stopping on EOF or overflow and returning the number of bytes actually written along with any error.

func (WireView) Debug added in v1.5.0

func (r WireView) Debug() []byte

Debug prints the remaining bytes in the buffer.

func (*WireView) Delegate added in v1.5.0

func (r *WireView) Delegate(size int) WireView

(AI GENERATED DESCRIPTION): Creates a sub‑view of the specified size from the current read position, advancing the original view past that region, and returns an empty view if the requested size exceeds the remaining bytes.

func (*WireView) IsEOF added in v1.5.0

func (r *WireView) IsEOF() bool

(AI GENERATED DESCRIPTION): Returns true when the current read position has reached or passed the end of the view, indicating no more data to read.

func (*WireView) Length added in v1.5.0

func (r *WireView) Length() int

(AI GENERATED DESCRIPTION): Returns the number of bytes represented by the WireView.

func (*WireView) Pos added in v1.5.0

func (r *WireView) Pos() int

(AI GENERATED DESCRIPTION): Returns the current offset within the WireView relative to its start index.

func (*WireView) Range added in v1.5.0

func (r *WireView) Range(start, end int) Wire

(AI GENERATED DESCRIPTION): Returns a sub‑Wire representing the bytes from the given start offset to the end offset within the current WireView, or an empty Wire on error.

func (*WireView) ReadBuf added in v1.5.0

func (r *WireView) ReadBuf(size int) ([]byte, error)

(AI GENERATED DESCRIPTION): Reads up to a requested number of bytes from the current position of the wire view, automatically handling segment boundaries and returning an error if the read would exceed the wire size or hit the end of the data.

func (*WireView) ReadByte added in v1.5.0

func (r *WireView) ReadByte() (byte, error)

(AI GENERATED DESCRIPTION): Retrieves the next byte from the wire view, advancing the read position across segment boundaries, and returns an EOF error if the view has been exhausted.

func (*WireView) ReadComponent added in v1.5.0

func (r *WireView) ReadComponent() (Component, error)

(AI GENERATED DESCRIPTION): Reads a TLV component from the WireView, decoding its type and length then returning the component’s type and value.

func (*WireView) ReadFull added in v1.5.0

func (r *WireView) ReadFull(cpy []byte) (int, error)

(AI GENERATED DESCRIPTION): Copies all remaining bytes from the underlying wire view into the supplied buffer, returning an error if the buffer is larger than the data available.

func (*WireView) ReadName added in v1.5.0

func (r *WireView) ReadName() (Name, error)

ReadName reads a Name from a Wire **excluding** the TL prefix.

func (*WireView) ReadTLNum added in v1.5.0

func (r *WireView) ReadTLNum() (val TLNum, err error)

ReadTLNum reads a TLNum from a wire view

func (*WireView) ReadWire added in v1.5.0

func (r *WireView) ReadWire(size int) (Wire, error)

(AI GENERATED DESCRIPTION): **ReadWire** reads the specified number of bytes from the WireView, performing bounds checking, and returns them as a Wire (a slice of byte‑segment slices).

func (*WireView) Skip added in v1.5.0

func (r *WireView) Skip(n int) error

(AI GENERATED DESCRIPTION): Skips forward n bytes in the current wire view, discarding the skipped data and returning any error that occurs.

func (*WireView) SkipGetSegCount added in v1.5.0

func (r *WireView) SkipGetSegCount(n int) (int, error)

_skip skips the next n bytes. used as utility for ReadWire to get the number of segments to read.

Directories

Path Synopsis
tests
gen_basic
Code generated by ndn tlv codegen DO NOT EDIT.
Code generated by ndn tlv codegen DO NOT EDIT.
gen_composition
Code generated by ndn tlv codegen DO NOT EDIT.
Code generated by ndn tlv codegen DO NOT EDIT.
gen_map
Code generated by ndn tlv codegen DO NOT EDIT.
Code generated by ndn tlv codegen DO NOT EDIT.
gen_signature
Code generated by ndn tlv codegen DO NOT EDIT.
Code generated by ndn tlv codegen DO NOT EDIT.

Jump to

Keyboard shortcuts

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