Documentation
¶
Index ¶
- Variables
- func GenEncodeTypeNum(typeNum uint64) (string, error)
- func GenNaturalNumberDecode(code string) (string, error)
- func GenNaturalNumberEncode(code string, isTlv bool) (string, error)
- func GenNaturalNumberLen(code string, isTlv bool) (string, error)
- func GenSwitchWire() (string, error)
- func GenSwitchWirePlan() (string, error)
- func GenTlvNumberDecode(code string) (string, error)
- func GenTypeNumLen(typeNum uint64) (string, error)
- type BaseTlvField
- func (*BaseTlvField) GenEncodeInto() (string, error)
- func (*BaseTlvField) GenEncoderStruct() (string, error)
- func (*BaseTlvField) GenEncodingLength() (string, error)
- func (*BaseTlvField) GenEncodingWirePlan() (string, error)
- func (*BaseTlvField) GenFromDict() (string, error)
- func (*BaseTlvField) GenInitContext() (string, error)
- func (*BaseTlvField) GenInitEncoder() (string, error)
- func (*BaseTlvField) GenParsingContextStruct() (string, error)
- func (*BaseTlvField) GenReadFrom() (string, error)
- func (*BaseTlvField) GenSkipProcess() (string, error)
- func (*BaseTlvField) GenToDict() (string, error)
- func (f *BaseTlvField) Name() string
- func (f *BaseTlvField) TypeNum() uint64
- type BinaryField
- func (f *BinaryField) GenEncodeInto() (string, error)
- func (f *BinaryField) GenEncodingLength() (string, error)
- func (f *BinaryField) GenEncodingWirePlan() (string, error)
- func (f *BinaryField) GenFromDict() (string, error)
- func (f *BinaryField) GenReadFrom() (string, error)
- func (f *BinaryField) GenSkipProcess() (string, error)
- func (f *BinaryField) GenToDict() (string, error)
- type BoolField
- func (f *BoolField) GenEncodeInto() (string, error)
- func (f *BoolField) GenEncodingLength() (string, error)
- func (f *BoolField) GenEncodingWirePlan() (string, error)
- func (f *BoolField) GenFromDict() (string, error)
- func (f *BoolField) GenReadFrom() (string, error)
- func (f *BoolField) GenSkipProcess() (string, error)
- func (f *BoolField) GenToDict() (string, error)
- type ByteField
- type FixedUintField
- func (f *FixedUintField) GenEncodeInto() (string, error)
- func (f *FixedUintField) GenEncodingLength() (string, error)
- func (f *FixedUintField) GenEncodingWirePlan() (string, error)
- func (f *FixedUintField) GenFromDict() (string, error)
- func (f *FixedUintField) GenReadFrom() (string, error)
- func (f *FixedUintField) GenSkipProcess() (string, error)
- func (f *FixedUintField) GenToDict() (string, error)
- type Generator
- type InterestNameField
- func (f *InterestNameField) GenEncodeInto() (string, error)
- func (f *InterestNameField) GenEncoderStruct() (string, error)
- func (f *InterestNameField) GenEncodingLength() (string, error)
- func (f *InterestNameField) GenEncodingWirePlan() (string, error)
- func (f *InterestNameField) GenInitContext() (string, error)
- func (f *InterestNameField) GenInitEncoder() (string, error)
- func (f *InterestNameField) GenParsingContextStruct() (string, error)
- func (f *InterestNameField) GenReadFrom() (string, error)
- func (f *InterestNameField) GenSkipProcess() (string, error)
- type MapField
- func (f *MapField) GenEncodeInto() (string, error)
- func (f *MapField) GenEncoderStruct() (string, error)
- func (f *MapField) GenEncodingLength() (string, error)
- func (f *MapField) GenEncodingWirePlan() (string, error)
- func (f *MapField) GenFromDict() (string, error)
- func (f *MapField) GenInitContext() (string, error)
- func (f *MapField) GenInitEncoder() (string, error)
- func (f *MapField) GenParsingContextStruct() (string, error)
- func (f *MapField) GenReadFrom() (string, error)
- func (f *MapField) GenSkipProcess() (string, error)
- func (f *MapField) GenToDict() (string, error)
- type NameField
- func (f *NameField) GenEncodeInto() (string, error)
- func (f *NameField) GenEncoderStruct() (string, error)
- func (f *NameField) GenEncodingLength() (string, error)
- func (f *NameField) GenEncodingWirePlan() (string, error)
- func (f *NameField) GenFromDict() (string, error)
- func (f *NameField) GenInitEncoder() (string, error)
- func (f *NameField) GenReadFrom() (string, error)
- func (f *NameField) GenSkipProcess() (string, error)
- func (f *NameField) GenToDict() (string, error)
- type NaturalField
- func (f *NaturalField) GenEncodeInto() (string, error)
- func (f *NaturalField) GenEncodingLength() (string, error)
- func (f *NaturalField) GenEncodingWirePlan() (string, error)
- func (f *NaturalField) GenFromDict() (string, error)
- func (f *NaturalField) GenReadFrom() (string, error)
- func (f *NaturalField) GenSkipProcess() (string, error)
- func (f *NaturalField) GenToDict() (string, error)
- type OffsetMarker
- func (f *OffsetMarker) GenEncodeInto() (string, error)
- func (f *OffsetMarker) GenEncoderStruct() (string, error)
- func (f *OffsetMarker) GenEncodingLength() (string, error)
- func (f *OffsetMarker) GenParsingContextStruct() (string, error)
- func (f *OffsetMarker) GenReadFrom() (string, error)
- func (f *OffsetMarker) GenSkipProcess() (string, error)
- type ProcedureArgument
- type RangeMarker
- func (f *RangeMarker) GenEncodeInto() (string, error)
- func (f *RangeMarker) GenEncoderStruct() (string, error)
- func (f *RangeMarker) GenEncodingLength() (string, error)
- func (f *RangeMarker) GenParsingContextStruct() (string, error)
- func (f *RangeMarker) GenReadFrom() (string, error)
- func (f *RangeMarker) GenSkipProcess() (string, error)
- type SequenceField
- func (f *SequenceField) GenEncodeInto() (string, error)
- func (f *SequenceField) GenEncoderStruct() (string, error)
- func (f *SequenceField) GenEncodingLength() (string, error)
- func (f *SequenceField) GenEncodingWirePlan() (string, error)
- func (f *SequenceField) GenFromDict() (string, error)
- func (f *SequenceField) GenInitContext() (string, error)
- func (f *SequenceField) GenInitEncoder() (string, error)
- func (f *SequenceField) GenParsingContextStruct() (string, error)
- func (f *SequenceField) GenReadFrom() (string, error)
- func (f *SequenceField) GenSkipProcess() (string, error)
- func (f *SequenceField) GenToDict() (string, error)
- type SignatureField
- func (f *SignatureField) GenEncodeInto() (string, error)
- func (f *SignatureField) GenEncoderStruct() (string, error)
- func (f *SignatureField) GenEncodingLength() (string, error)
- func (f *SignatureField) GenEncodingWirePlan() (string, error)
- func (f *SignatureField) GenInitContext() (string, error)
- func (f *SignatureField) GenInitEncoder() (string, error)
- func (f *SignatureField) GenParsingContextStruct() (string, error)
- func (f *SignatureField) GenReadFrom() (string, error)
- func (f *SignatureField) GenSkipProcess() (string, error)
- type StringField
- func (f *StringField) GenEncodeInto() (string, error)
- func (f *StringField) GenEncodingLength() (string, error)
- func (f *StringField) GenEncodingWirePlan() (string, error)
- func (f *StringField) GenFromDict() (string, error)
- func (f *StringField) GenReadFrom() (string, error)
- func (f *StringField) GenSkipProcess() (string, error)
- func (f *StringField) GenToDict() (string, error)
- type StructField
- func (f *StructField) GenEncodeInto() (string, error)
- func (f *StructField) GenEncoderStruct() (string, error)
- func (f *StructField) GenEncodingLength() (string, error)
- func (f *StructField) GenEncodingWirePlan() (string, error)
- func (f *StructField) GenFromDict() (string, error)
- func (f *StructField) GenInitContext() (string, error)
- func (f *StructField) GenInitEncoder() (string, error)
- func (f *StructField) GenParsingContextStruct() (string, error)
- func (f *StructField) GenReadFrom() (string, error)
- func (f *StructField) GenSkipProcess() (string, error)
- func (f *StructField) GenToDict() (string, error)
- type TimeField
- type TlvField
- func CreateField(className string, name string, typeNum uint64, annotation string, ...) (TlvField, error)
- func NewBinaryField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)
- func NewBoolField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)
- func NewByteField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewFixedUintField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewInterestNameField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewMapField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
- func NewNameField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)
- func NewNaturalField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewOffsetMarker(name string, _ uint64, _ string, model *TlvModel) (TlvField, error)
- func NewProcedureArgument(name string, _ uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewRangeMarker(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
- func NewSequenceField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
- func NewSignatureField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
- func NewStringField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewStructField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
- func NewTimeField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
- func NewWireField(name string, typeNum uint64, _ string, model *TlvModel) (TlvField, error)
- func ParseField(name string, typeNum uint64, fieldStr string, model *TlvModel) (TlvField, error)
- type TlvModel
- func (m *TlvModel) GenEncodeInto(buf *bytes.Buffer) error
- func (m *TlvModel) GenEncoderStruct(buf *bytes.Buffer) error
- func (m *TlvModel) GenFromDict(buf *bytes.Buffer) error
- func (m *TlvModel) GenInitContext(buf *bytes.Buffer) error
- func (m *TlvModel) GenInitEncoder(buf *bytes.Buffer) error
- func (m *TlvModel) GenParsingContextStruct(buf *bytes.Buffer) error
- func (m *TlvModel) GenReadFrom(buf *bytes.Buffer) error
- func (m *TlvModel) GenToDict(buf *bytes.Buffer) error
- func (m *TlvModel) Generate(buf *bytes.Buffer) error
- func (m *TlvModel) ProcessOption(option string)
- type WireField
- func (f *WireField) GenEncodeInto() (string, error)
- func (f *WireField) GenEncoderStruct() (string, error)
- func (f *WireField) GenEncodingLength() (string, error)
- func (f *WireField) GenEncodingWirePlan() (string, error)
- func (f *WireField) GenInitEncoder() (string, error)
- func (f *WireField) GenReadFrom() (string, error)
- func (f *WireField) GenSkipProcess() (string, error)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidField = errors.New("invalid TlvField. Please check the annotation (including type and arguments)")
var ErrWrongTypeNumber = errors.New("invalid type number")
Functions ¶
func GenEncodeTypeNum ¶
(AI GENERATED DESCRIPTION): Generates Go source that writes a given type number into a buffer using the NDN TLV variable‑length encoding (1, 3, 5, or 9 bytes depending on the value).
func GenNaturalNumberDecode ¶
(AI GENERATED DESCRIPTION): Generates a Go code snippet that reads `l` bytes from a `reader`, assembles them into a `uint64`, and stores the result in the variable named by the supplied `code` string.
func GenNaturalNumberEncode ¶
(AI GENERATED DESCRIPTION): Generates a Go code snippet that encodes a natural number into a buffer using either TLV or NATS encoding, updating the buffer position accordingly.
func GenNaturalNumberLen ¶
(AI GENERATED DESCRIPTION): Generates a Go code snippet that updates a length counter by adding the encoding length of a natural number field, using TLV encoding when `isTlv` is true and plain Nat encoding otherwise.
func GenSwitchWire ¶
(AI GENERATED DESCRIPTION): Advances the wire index, resets the read position, and sets the current buffer to the next segment or nil if no more segments remain.
func GenSwitchWirePlan ¶
(AI GENERATED DESCRIPTION): Generates a code snippet that appends the current segment length to the wire plan (`wirePlan = append(wirePlan, l)`) and resets the length counter (`l = 0`).
func GenTlvNumberDecode ¶
(AI GENERATED DESCRIPTION): Generates a Go snippet that reads a TLV number from a reader into the supplied variable and returns an ErrFailToParse on any read error.
func GenTypeNumLen ¶
(AI GENERATED DESCRIPTION): Generates the Go code snippet that increments a length counter by the number of bytes required to encode the supplied type number in NDN’s variable‑length TLV format.
Types ¶
type BaseTlvField ¶
type BaseTlvField struct {
// contains filtered or unexported fields
}
BaseTlvField is a base class for all TLV fields. Golang's inheritance is not supported, so we use this class to disable optional functions.
func (*BaseTlvField) GenEncodeInto ¶
func (*BaseTlvField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates and returns the binary TLV encoding of the BaseTlvField as a string, producing an error if the encoding process fails.
func (*BaseTlvField) GenEncoderStruct ¶
func (*BaseTlvField) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates an encoder struct string for BaseTlvField; currently returns an empty string and no error.
func (*BaseTlvField) GenEncodingLength ¶
func (*BaseTlvField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Calculates the length of the BaseTlvField’s TLV encoding and returns it as a string (or an error if the length cannot be determined).
func (*BaseTlvField) GenEncodingWirePlan ¶
func (*BaseTlvField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates an encoding wire‑plan string for a BaseTlvField, returning that string and an error if plan generation fails.
func (*BaseTlvField) GenFromDict ¶
func (*BaseTlvField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates a TLV‑encoded string from the BaseTlvField’s internal dictionary representation.
func (*BaseTlvField) GenInitContext ¶
func (*BaseTlvField) GenInitContext() (string, error)
(AI GENERATED DESCRIPTION): Generates the initial context for a `BaseTlvField`, returning an empty string and no error.
func (*BaseTlvField) GenInitEncoder ¶
func (*BaseTlvField) GenInitEncoder() (string, error)
(AI GENERATED DESCRIPTION): Initializes the encoder for a BaseTlvField, returning an empty string and nil error.
func (*BaseTlvField) GenParsingContextStruct ¶
func (*BaseTlvField) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates the parsing‑context struct string for a BaseTlvField, which currently returns an empty string and no error.
func (*BaseTlvField) GenReadFrom ¶
func (*BaseTlvField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates a Go code snippet to read a BaseTlvField from a TLV‑encoded payload.
func (*BaseTlvField) GenSkipProcess ¶
func (*BaseTlvField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates a comment (“// base - skip”) indicating that processing of the base TLV field should be skipped.
func (*BaseTlvField) GenToDict ¶
func (*BaseTlvField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates a dictionary‑formatted string representation of the BaseTlvField, returning any error that occurs during the conversion.
func (*BaseTlvField) Name ¶
func (f *BaseTlvField) Name() string
(AI GENERATED DESCRIPTION): Returns the name of the TLV field represented by this BaseTlvField instance.
func (*BaseTlvField) TypeNum ¶
func (f *BaseTlvField) TypeNum() uint64
(AI GENERATED DESCRIPTION): Returns the TLV type number (`typeNum`) stored in the `BaseTlvField` instance.
type BinaryField ¶
type BinaryField struct {
BaseTlvField
}
BinaryField represents a binary string field of type Buffer or []byte. BinaryField always makes a copy during encoding.
func (*BinaryField) GenEncodeInto ¶
func (f *BinaryField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that encodes a non‑nil binary field into a buffer, writing its type number, length, and data payload.
func (*BinaryField) GenEncodingLength ¶
func (f *BinaryField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Computes the TLV‑encoded length of a binary field, adding the type number and length prefix bytes plus the field’s data length only when the field is non‑nil.
func (*BinaryField) GenEncodingWirePlan ¶
func (f *BinaryField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Returns the wire‑encoding plan for a binary field by delegating to GenEncodingLength.
func (*BinaryField) GenFromDict ¶
func (f *BinaryField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that extracts a binary field from a dictionary, assigns it to the struct’s field (or nil if missing), and emits an error on type mismatch.
func (*BinaryField) GenReadFrom ¶
func (f *BinaryField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates code that allocates a byte slice for the binary field and reads the full data from the reader into that slice.
func (*BinaryField) GenSkipProcess ¶
func (f *BinaryField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates a statement that sets the BinaryField’s value to `nil` during skip processing.
func (*BinaryField) GenToDict ¶
func (f *BinaryField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that inserts a non‑nil binary field into a map as a key/value pair.
type BoolField ¶
type BoolField struct {
BaseTlvField
}
BoolField represents a boolean field.
func (*BoolField) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates code that, when executed, encodes a BoolField as a zero‑length TLV only if the field’s value is true, writing the field’s type number followed by a zero length.
func (*BoolField) GenEncodingLength ¶
(AI GENERATED DESCRIPTION): Generates Go code that computes the encoding length of a BoolField by adding the type number and zero‑length value bytes only when the field’s boolean value is true.
func (*BoolField) GenEncodingWirePlan ¶
(AI GENERATED DESCRIPTION): Generates an encoding plan for a BoolField by delegating to its GenEncodingLength method.
func (*BoolField) GenFromDict ¶
(AI GENERATED DESCRIPTION): Generates Go code to extract a boolean value from a dictionary, assign it to the struct field, default to `false` if the key is missing, and return an error if the value is of an incompatible type.
func (*BoolField) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates Go code that sets the Boolean field to true and skips over the field’s payload bytes during deserialization.
func (*BoolField) GenSkipProcess ¶
(AI GENERATED DESCRIPTION): Generates a line of code that assigns `false` to the named boolean field when processing is skipped.
type ByteField ¶ added in v1.5.0
type ByteField struct {
BaseTlvField
}
ByteField represents a pointer to the wire address of a byte.
func (*ByteField) GenEncodeInto ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Generates code that encodes an optional single‑byte field into a buffer, writing the field’s type number, a length byte of 1, and the byte value if the field is present.
func (*ByteField) GenEncodingLength ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Generates Go code that adds the length of a non‑nil byte field (including its type number and length header) to a running total when encoding a TLV message.
func (*ByteField) GenEncodingWirePlan ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Generates the wire‑encoding plan for a byte field by delegating to its `GenEncodingLength` method.
func (*ByteField) GenReadFrom ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Generates code that reads a single byte from a reader, assigns it to the field, and converts an EOF into an unexpected‑EOF error.
func (*ByteField) GenSkipProcess ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Generates Go code that assigns `nil` to the field when the field is skipped during decoding.
type FixedUintField ¶
type FixedUintField struct {
BaseTlvField
// contains filtered or unexported fields
}
FixedUintField represents a fixed-length unsigned integer.
func (*FixedUintField) GenEncodeInto ¶
func (f *FixedUintField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go source that encodes a fixed‑length unsigned integer field into a buffer, writing its type number and value (in big‑endian order) and optionally guarding against missing values.
func (*FixedUintField) GenEncodingLength ¶
func (f *FixedUintField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that calculates the encoding length for a fixed unsigned integer field, adding the field’s type number and length to the total only if the field is required or its optional value is set.
func (*FixedUintField) GenEncodingWirePlan ¶
func (f *FixedUintField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates the wire‑encoding plan string for a FixedUintField by delegating to its GenEncodingLength method, returning the plan and any error.
func (*FixedUintField) GenFromDict ¶
func (f *FixedUintField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates a code block that extracts a fixed‑length unsigned integer from a dictionary, assigns it to a struct field (as a pointer if optional), and returns type‑mismatch or missing‑key errors.
func (*FixedUintField) GenReadFrom ¶
func (f *FixedUintField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that reads a fixed‑length unsigned integer field from an io.Reader into a target struct field, handling optional values and EOF errors.
func (*FixedUintField) GenSkipProcess ¶
func (f *FixedUintField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates a code snippet that, when the field is optional, unsets its value, or if mandatory, assigns a skip‑required error.
func (*FixedUintField) GenToDict ¶
func (f *FixedUintField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that inserts the unsigned integer field into a map, writing it directly for mandatory fields or only when non‑nil for optional ones.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
func NewGenerator ¶
func NewGenerator() *Generator
(AI GENERATED DESCRIPTION): Creates a new Generator with an empty model slice, a compiled regex for parsing TLV tags, and an empty imports map.
func (*Generator) Generate ¶
(AI GENERATED DESCRIPTION): Generates a Go source file for the given package by emitting a header with imports and then writing the generated code for each model into the generator’s buffer.
func (*Generator) ProcessDecl ¶
This is the entry point of the codegen module
type InterestNameField ¶
type InterestNameField struct {
BaseTlvField
// contains filtered or unexported fields
}
InterestNameField represents the Name field in an Interest, which may contain a ParametersSha256DigestComponent. Requires needDigest as input, indicating whether ParametersSha256Digest component is required. It will modify the input Name value and generate a final Name value.
func (*InterestNameField) GenEncodeInto ¶
func (f *InterestNameField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that encodes an Interest’s name field (type, length, and components) into a buffer, tracks the portion to be covered by the signature, and updates the encoder’s state accordingly.
func (*InterestNameField) GenEncoderStruct ¶
func (f *InterestNameField) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates the encoder struct field declarations for an Interest name field, producing variables for its length, digest‑need flag, wire index, and position.
func (*InterestNameField) GenEncodingLength ¶
func (f *InterestNameField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that computes the encoding length of the InterestNameField by adding the field’s type number, length prefix, and value length to the total only when the field is non‑nil.
func (*InterestNameField) GenEncodingWirePlan ¶
func (f *InterestNameField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates the encoding wire plan for an `InterestNameField` by delegating to its `GenEncodingLength` method.
func (*InterestNameField) GenInitContext ¶
func (f *InterestNameField) GenInitContext() (string, error)
(AI GENERATED DESCRIPTION): Generates the initial context string for an Interest name field, which currently returns an empty string and no error since no special initialization is required.
func (*InterestNameField) GenInitEncoder ¶
func (f *InterestNameField) GenInitEncoder() (string, error)
(AI GENERATED DESCRIPTION): Initializes the encoder for an Interest name field by resetting its indices, stripping any existing digest component, optionally adding a SHA‑256 digest component, and computing the total encoded length.
func (*InterestNameField) GenParsingContextStruct ¶
func (f *InterestNameField) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a struct definition snippet for an InterestNameField that tracks its parsing state, including a wire index (int) and current position (uint).
func (*InterestNameField) GenReadFrom ¶
func (f *InterestNameField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates code to read an Interest’s name from the packet, decoding each component and capturing the byte range that must be covered by the packet’s signature.
func (*InterestNameField) GenSkipProcess ¶
func (f *InterestNameField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that sets the InterestNameField’s value to nil, effectively skipping its processing.
type MapField ¶
type MapField struct {
BaseTlvField
KeyField TlvField
ValField TlvField
KeyFieldType string
ValFieldType string
}
func (*MapField) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates an encoded string representation of the MapField by delegating to its general encoding routine.
func (*MapField) GenEncoderStruct ¶
(AI GENERATED DESCRIPTION): Generates a Go source snippet that defines an encoder map for a MapField, mapping each key to a pointer to a nested struct that encodes the field’s value.
func (*MapField) GenEncodingLength ¶
(AI GENERATED DESCRIPTION): Generates the Go code that computes the encoding length of a MapField.
func (*MapField) GenEncodingWirePlan ¶
(AI GENERATED DESCRIPTION): Generates an encoding‑wire plan string for a map field by delegating to the generic encoding routine.
func (*MapField) GenFromDict ¶
(AI GENERATED DESCRIPTION): Generates Go code for a `MapField` from a dictionary input (currently unimplemented).
func (*MapField) GenInitContext ¶
(AI GENERATED DESCRIPTION): Delegates the generation of initialization context to the MapField's value field.
func (*MapField) GenInitEncoder ¶
(AI GENERATED DESCRIPTION): Generates Go source code that initializes an encoder for a map field, allocating a map of per‑value encoders and invoking the value field’s initialization logic for each entry.
func (*MapField) GenParsingContextStruct ¶
(AI GENERATED DESCRIPTION): Generates a parsing‑context struct for a map field by delegating to its value field, since the map’s size is unknown until parsing.
func (*MapField) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates code that reads a TLV‑encoded map field, initializing the map and inserting each decoded key/value pair into it.
func (*MapField) GenSkipProcess ¶
(AI GENERATED DESCRIPTION): Generates a placeholder comment for skipping map field processing after parsing, ensuring that no nil assignment occurs.
type NameField ¶
type NameField struct {
BaseTlvField
}
NameField represents a name field.
func (*NameField) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates Go code that serializes a NameField by writing its type number, length, and each component into a byte buffer.
func (*NameField) GenEncoderStruct ¶
(AI GENERATED DESCRIPTION): Generates a struct field declaration for the length of a `NameField`, returning the string "`<fieldName>_length uint`".
func (*NameField) GenEncodingLength ¶
(AI GENERATED DESCRIPTION): Generates Go code that calculates the encoded length of a NameField, adding its type number, length prefix, and the field’s own length when the field is set.
func (*NameField) GenEncodingWirePlan ¶
(AI GENERATED DESCRIPTION): Generates the wire‑encoding plan for a NameField by delegating to its GenEncodingLength routine.
func (*NameField) GenFromDict ¶
(AI GENERATED DESCRIPTION): Generates Go code that extracts a Name field from a dictionary, performing a type assertion to enc.Name, assigning the value to the struct field or nil, and returns the generated code string or an error.
func (*NameField) GenInitEncoder ¶
(AI GENERATED DESCRIPTION): Generates code that, when a name field is present, computes and sets the encoder’s length field by summing the encoding lengths of each component of that name.
func (*NameField) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates Go code that reads a name value from a reader into the struct’s Name field.
func (*NameField) GenSkipProcess ¶
(AI GENERATED DESCRIPTION): Generates Go code that skips processing a name field by setting the corresponding field in the value struct to nil.
type NaturalField ¶
type NaturalField struct {
BaseTlvField
// contains filtered or unexported fields
}
NaturalField represents a natural number field.
func (*NaturalField) GenEncodeInto ¶
func (f *NaturalField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go source that writes the natural field’s type number and value into an encoding buffer, including an optional presence check when the field is marked optional.
func (*NaturalField) GenEncodingLength ¶
func (f *NaturalField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that computes the encoding length of a NaturalField, handling optional values by wrapping the length calculation in an `if` check.
func (*NaturalField) GenEncodingWirePlan ¶
func (f *NaturalField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates the encoding wire plan for a NaturalField by delegating to its GenEncodingLength method.
func (*NaturalField) GenFromDict ¶
func (f *NaturalField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that extracts an optional or required uint64 field from a dictionary, performs type checking, assigns the value to the field (or unsets it if optional), and emits errors for missing or incompatible entries.
func (*NaturalField) GenReadFrom ¶
func (f *NaturalField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that reads a natural‑number field from a buffer, decoding it into a temporary variable and setting the field when optional, or decoding directly into the field when mandatory.
func (*NaturalField) GenSkipProcess ¶
func (f *NaturalField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates code to handle skipping a field during encoding: if the field is optional it emits code to unset it, otherwise it produces an error indicating a required field was skipped.
func (*NaturalField) GenToDict ¶
func (f *NaturalField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that adds a field to a dictionary, inserting the value directly for required fields or inserting it only if present for optional fields.
type OffsetMarker ¶
type OffsetMarker struct {
BaseTlvField
// contains filtered or unexported fields
}
OffsetMarker is a marker that marks a position in the wire.
func (*OffsetMarker) GenEncodeInto ¶
func (f *OffsetMarker) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates code that writes the encoder’s current wire index (if `noCopy` is true) and position into the offset marker’s fields.
func (*OffsetMarker) GenEncoderStruct ¶
func (f *OffsetMarker) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates Go struct field declarations for an `OffsetMarker`, emitting a field for the value, an optional wire‑index field when `noCopy` is true, and a field for the marker’s position.
func (*OffsetMarker) GenEncodingLength ¶
func (f *OffsetMarker) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates a Go code snippet that assigns the current encoding length `l` to the encoder’s field named by `f.name` (e.g., `encoder.foo = int(l)`).
func (*OffsetMarker) GenParsingContextStruct ¶
func (f *OffsetMarker) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a parsing context struct string for the offset marker by returning its name followed by the type `int`.
func (*OffsetMarker) GenReadFrom ¶
func (f *OffsetMarker) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates the code to read an `OffsetMarker` by delegating to its skip‑processing logic.
func (*OffsetMarker) GenSkipProcess ¶
func (f *OffsetMarker) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates code that stores the current start position into the context variable named by `f.name`.
type ProcedureArgument ¶
type ProcedureArgument struct {
BaseTlvField
// contains filtered or unexported fields
}
ProcedureArgument is a variable used during encoding and decoding procedure.
func (*ProcedureArgument) GenEncoderStruct ¶
func (f *ProcedureArgument) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a string representing a struct field by concatenating the argument’s name and type, returning it for use in an encoder struct definition.
func (*ProcedureArgument) GenParsingContextStruct ¶
func (f *ProcedureArgument) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a parsing‑context struct field declaration by concatenating the procedure argument’s name and type into a string.
type RangeMarker ¶
type RangeMarker struct {
BaseTlvField
// contains filtered or unexported fields
}
RangeMarker is a marker that catches a range in the wire from an OffsetMarker to current position. It is necessary because the offset given by OffsetMarker is not necessarily from the beginning of the outmost TLV, when parsing. It is the same with OffsetMarker for encoding.
func (*RangeMarker) GenEncodeInto ¶
func (f *RangeMarker) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that updates the encoder’s position for a RangeMarker and, if `noCopy` is set, also assigns the current wire index.
func (*RangeMarker) GenEncoderStruct ¶
func (f *RangeMarker) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates the Go struct definition string for a RangeMarker encoder, including fields for the marker name, an optional wire index if `noCopy` is set, and a position index.
func (*RangeMarker) GenEncodingLength ¶
func (f *RangeMarker) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates the code that assigns the encoder’s field (named by f.name) the value int(l).
func (*RangeMarker) GenParsingContextStruct ¶
func (f *RangeMarker) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a Go struct field definition for the range marker’s name, declaring it as an `int` field in the parsing context.
func (*RangeMarker) GenReadFrom ¶
func (f *RangeMarker) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates the read operation for a RangeMarker by delegating to GenSkipProcess, effectively producing a skip‑processing block.
func (*RangeMarker) GenSkipProcess ¶
func (f *RangeMarker) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates code that assigns the starting position to a context field and updates a signature‑covered range by calling `reader.Range` with that position.
type SequenceField ¶
type SequenceField struct {
BaseTlvField
SubField TlvField
FieldType string
}
SequenceField represents a slice field of another supported field type.
func (*SequenceField) GenEncodeInto ¶
func (f *SequenceField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Encodes the SequenceField into its serialized string representation, returning the resulting encoding and any error.
func (*SequenceField) GenEncoderStruct ¶
func (f *SequenceField) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates the Go struct declaration for a sequence field’s encoder, producing a slice of anonymous structs each containing the subfield’s encoding.
func (*SequenceField) GenEncodingLength ¶
func (f *SequenceField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates code that computes the encoding length of a Sequence field.
func (*SequenceField) GenEncodingWirePlan ¶
func (f *SequenceField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates a plan for encoding a SequenceField and returns the resulting string (or an error).
func (*SequenceField) GenFromDict ¶
func (f *SequenceField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Returns a placeholder error string indicating that the SequenceField GenFromDict method is not yet implemented.
func (*SequenceField) GenInitContext ¶
func (f *SequenceField) GenInitContext() (string, error)
(AI GENERATED DESCRIPTION): Delegates the generation of initialization context to the underlying subfield’s GenInitContext method.
func (*SequenceField) GenInitEncoder ¶
func (f *SequenceField) GenInitEncoder() (string, error)
(AI GENERATED DESCRIPTION): Generates the code to initialize a sequence field’s encoder by allocating a slice of sub‑field encoders and iterating over each element to set up pseudo encoders and values for encoding.
func (*SequenceField) GenParsingContextStruct ¶
func (f *SequenceField) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a parsing context struct for a sequence field by delegating to its subfield, since the number of elements is unknown before parsing.
func (*SequenceField) GenReadFrom ¶
func (f *SequenceField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that deserializes a sequence field by initializing the slice if nil, reading one element into a temporary struct, appending it to the slice, and decrementing the progress counter.
func (*SequenceField) GenSkipProcess ¶
func (f *SequenceField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates a comment indicating that a sequence field is to be skipped during processing, ensuring it is not assigned a nil value.
func (*SequenceField) GenToDict ¶
func (f *SequenceField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates a Go code snippet that serializes a sequence field into a dictionary by iterating over its elements and embedding each subfield’s dictionary representation.
type SignatureField ¶
type SignatureField struct {
BaseTlvField
// contains filtered or unexported fields
}
SignatureField represents SignatureValue field It handles the signature covered part, and the position of the signature. Requires estimated length of the signature as input, which should be >= the real length. When estimated length is 0, the signature is not encoded.
func (*SignatureField) GenEncodeInto ¶
func (f *SignatureField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates the encoding logic for a signature field, writing its type number, length, and covered data into the encoder while handling optional copying and wire switching.
func (*SignatureField) GenEncoderStruct ¶
func (f *SignatureField) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates encoder‑struct fields for a signature field by adding an `int` wire‑index field and a `uint` estimated‑length field named after the signature.
func (*SignatureField) GenEncodingLength ¶
func (f *SignatureField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates code that, if the signature field’s estimated length is non‑zero, adds the field’s type number, length prefix, and content size to the total encoding length.
func (*SignatureField) GenEncodingWirePlan ¶
func (f *SignatureField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that plans the wire encoding of the signature field, calculating its length and assigning its wire index in the encoding plan.
func (*SignatureField) GenInitContext ¶
func (f *SignatureField) GenInitContext() (string, error)
(AI GENERATED DESCRIPTION): Generates code that initializes the signature‑covered field in the context by assigning it an empty `enc.Wire` slice.
func (*SignatureField) GenInitEncoder ¶
func (f *SignatureField) GenInitEncoder() (string, error)
(AI GENERATED DESCRIPTION): Initializes the encoder for a signature field by setting its wire index to –1.
func (*SignatureField) GenParsingContextStruct ¶
func (f *SignatureField) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a Go struct definition that represents the parsing context for a signature field, returning the source code string (or an error if generation fails).
func (*SignatureField) GenReadFrom ¶
func (f *SignatureField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates code that reads a signature field from a binary reader, assigns it to the struct’s field, and records the byte range covered in the signature context.
func (*SignatureField) GenSkipProcess ¶
func (f *SignatureField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates code that sets the signature field to nil, effectively skipping its processing.
type StringField ¶
type StringField struct {
BaseTlvField
// contains filtered or unexported fields
}
StringField represents a UTF-8 encoded string.
func (*StringField) GenEncodeInto ¶
func (f *StringField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that encodes a string field into a buffer by writing its type number, length, and byte data, handling optional values if present.
func (*StringField) GenEncodingLength ¶
func (f *StringField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates code that calculates the encoded length of a string field, adding its type tag, length prefix, and the string bytes, and handling optional fields by checking for presence before including them.
func (*StringField) GenEncodingWirePlan ¶
func (f *StringField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates the wire‑encoding plan for a string field by returning its encoding‑length representation.
func (*StringField) GenFromDict ¶
func (f *StringField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that extracts a string value from a dictionary, assigns it to the target field (or unsets it if optional), and returns errors for missing or incompatible types.
func (*StringField) GenReadFrom ¶
func (f *StringField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates Go source that reads a string of length `l` from a reader and assigns it to the field (using `Set` for optional fields).
func (*StringField) GenSkipProcess ¶
func (f *StringField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates the code snippet that either unsets an optional string field or produces a skip‑required error when a required string field is omitted.
func (*StringField) GenToDict ¶
func (f *StringField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that inserts a StringField into a dictionary, setting the field directly or conditionally based on whether the field is optional.
type StructField ¶
type StructField struct {
BaseTlvField
StructType string
// contains filtered or unexported fields
}
StructField represents a struct field of another TlvModel.
func (*StructField) GenEncodeInto ¶
func (f *StructField) GenEncodeInto() (string, error)
(AI GENERATED DESCRIPTION): Generates a code block that encodes a non‑nil struct field into a buffer, emitting type and length prefixes and performing either a direct encode or an in‑place nested encode to avoid copying.
func (*StructField) GenEncoderStruct ¶
func (f *StructField) GenEncoderStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates the Go code snippet declaring an encoder variable named `<field_name>_encoder` of type `<StructType>Encoder`.
func (*StructField) GenEncodingLength ¶
func (f *StructField) GenEncodingLength() (string, error)
(AI GENERATED DESCRIPTION): Generates code that, when a struct field is non‑nil, adds its type number, length prefix, and nested encoder length to the total encoding size.
func (*StructField) GenEncodingWirePlan ¶
func (f *StructField) GenEncodingWirePlan() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code to compute the wire‑length of a struct field during encoding, handling nested encoders and inner no‑copy logic.
func (*StructField) GenFromDict ¶
func (f *StructField) GenFromDict() (string, error)
(AI GENERATED DESCRIPTION): Generates code to read a value from a map by key, type‑assert it to the field’s struct type, assign it (or nil if absent), and set an error if the type is incompatible.
func (*StructField) GenInitContext ¶
func (f *StructField) GenInitContext() (string, error)
(AI GENERATED DESCRIPTION): Generates the Go statement that initializes the context for the struct field.
func (*StructField) GenInitEncoder ¶
func (f *StructField) GenInitEncoder() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that initializes a sub‑encoder for a struct field when the field’s value is non‑nil.
func (*StructField) GenParsingContextStruct ¶
func (f *StructField) GenParsingContextStruct() (string, error)
(AI GENERATED DESCRIPTION): Generates a declaration string for a parsing‑context field by concatenating the struct field’s name and type into the form “\<name\>_context \<Type\>ParsingContext”.
func (*StructField) GenReadFrom ¶
func (f *StructField) GenReadFrom() (string, error)
(AI GENERATED DESCRIPTION): Generates code that reads and parses a struct field’s value from a reader using the field’s context, assigning the parsed result to the struct and capturing any error.
func (*StructField) GenSkipProcess ¶
func (f *StructField) GenSkipProcess() (string, error)
(AI GENERATED DESCRIPTION): Generates code that assigns `nil` to the struct field named `f.name`, thereby skipping its processing.
func (*StructField) GenToDict ¶
func (f *StructField) GenToDict() (string, error)
(AI GENERATED DESCRIPTION): Generates Go code that, if the struct field is non‑nil, inserts its dictionary representation (via ToDict()) into a map.
type TimeField ¶
type TimeField struct {
BaseTlvField
// contains filtered or unexported fields
}
TimeField represents a time field, recorded as milliseconds.
func (*TimeField) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates Go source code that encodes a TimeField into a packet by writing its type number and the time value (converted to milliseconds) as a natural number, and includes conditional logic for optional fields.
func (*TimeField) GenEncodingLength ¶
(AI GENERATED DESCRIPTION): Generates Go source that computes the NDN wire‑encoding length of a TimeField, emitting the type‑number length plus the natural‑number length of the time value (in milliseconds) and handling optional fields with an `if` check.
func (*TimeField) GenEncodingWirePlan ¶
(AI GENERATED DESCRIPTION): Generates the wire‑encoding plan for a time field by delegating to its encoding‑length generation logic.
func (*TimeField) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates a code snippet that reads a natural‐number time value from a binary stream, interprets it as milliseconds, and assigns it to the struct’s time field (using a setter for optional fields).
func (*TimeField) GenSkipProcess ¶
(AI GENERATED DESCRIPTION): Generates code for skipping a TimeField during encoding: if optional it unsets the field, otherwise it assigns an ErrSkipRequired error.
type TlvField ¶
type TlvField interface {
Name() string
TypeNum() uint64
// codegen encoding length of the field
// - in(value): struct being encoded
// - out(l): length variable to update
GenEncodingLength() (string, error)
GenEncodingWirePlan() (string, error)
GenEncodeInto() (string, error)
GenEncoderStruct() (string, error)
GenInitEncoder() (string, error)
GenParsingContextStruct() (string, error)
GenInitContext() (string, error)
GenReadFrom() (string, error)
GenSkipProcess() (string, error)
GenToDict() (string, error)
GenFromDict() (string, error)
}
func CreateField ¶
func CreateField(className string, name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates a TlvField by mapping the class name prefix to its corresponding constructor, returning an error if the field type is unsupported.
func NewBinaryField ¶
(AI GENERATED DESCRIPTION): Creates a BinaryField TLV instance with the specified name and type number.
func NewBoolField ¶
(AI GENERATED DESCRIPTION): Creates a BoolField with the specified name and type number and returns it as a TlvField.
func NewByteField ¶ added in v1.5.0
(AI GENERATED DESCRIPTION): Creates a ByteField initialized with the given name and type number, returning it as a TlvField.
func NewFixedUintField ¶
func NewFixedUintField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates a FixedUintField with the given name and type number, parsing the annotation to set its byte length (byte, uint16, uint32, or uint64) and whether it is optional.
func NewInterestNameField ¶
func NewInterestNameField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates an InterestNameField with the given name, type number, and signature‑coverage annotation, returning ErrInvalidField if the annotation is empty.
func NewMapField ¶
(AI GENERATED DESCRIPTION): Creates a MapField TLV element by parsing the annotation to generate the corresponding key and value subfields.
func NewNameField ¶
(AI GENERATED DESCRIPTION): Creates and returns a NameField TlvField initialized with the provided name and type number.
func NewNaturalField ¶
(AI GENERATED DESCRIPTION): Creates a NaturalField TLV descriptor with the given name and type number, marking it as optional when the annotation string equals "optional".
func NewOffsetMarker ¶
NewOffsetMarker creates an offset marker field.
func NewProcedureArgument ¶
NewProcedureArgument creates a ProcedureArgument field.
func NewRangeMarker ¶
func NewRangeMarker(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
NewOffsetMarker creates an range marker field.
func NewSequenceField ¶
func NewSequenceField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates a SequenceField TLV that wraps a subfield defined by the annotation string, using the supplied name and type number.
func NewSignatureField ¶
func NewSignatureField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates a new SignatureField TLV field, parsing the annotation string to set the startPoint and sigCovered attributes, and returns an error if the annotation format is invalid.
func NewStringField ¶
(AI GENERATED DESCRIPTION): Creates a new `StringField` TlvField with the given name and type number, and marks it optional if the annotation equals `"optional"`.
func NewStructField ¶
func NewStructField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)
(AI GENERATED DESCRIPTION): Creates a new StructField by parsing the annotation into a struct type and optional “nocopy” flag, validating that the flag is permitted by the model, and initializing the field with the supplied name and type number.
func NewTimeField ¶
(AI GENERATED DESCRIPTION): Creates a TimeField with the given name and type number, marking it optional when the annotation is `"optional"`.
func NewWireField ¶
(AI GENERATED DESCRIPTION): Creates a new WireField with the specified name and type number, copying the model’s NoCopy setting to determine whether the field’s bytes should be copied, and returns it.
func ParseField ¶
(AI GENERATED DESCRIPTION): Parses a field string (optionally containing an annotation after a colon) and creates a TlvField using the supplied name, type number, annotation, and model.
type TlvModel ¶
type TlvModel struct {
Name string
// PrivMethods indicates whether generated methods are private. False by default.
// Enabled by `private` annotation.
PrivMethods bool
// NoCopy indicates whether to avoid copying []byte into wire. False by default.
// Enabled by `nocopy` annotation.
NoCopy bool
// GenDict indicates whether to generate ToDict/FromDict for this model.
GenDict bool
// Ordered indicates whether fields require ordering. False by default.
// Enabled by `ordered` annotation.
Ordered bool
// WithParsingContext is true if any field has a non-trivial GenParsingContextStruct()
WithParsingContext bool
// Fields are the TLV fields of the structure.
Fields []TlvField
}
TlvModel represents a TLV encodable structure.
func (*TlvModel) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates Go source that implements encoding a TLV model into its wire representation, writing the encoder methods into the supplied buffer.
func (*TlvModel) GenEncoderStruct ¶
(AI GENERATED DESCRIPTION): Generates a Go struct definition that encodes a TLV model, including a length field, an optional wire plan slice, and nested encoder fields for each component.
func (*TlvModel) GenFromDict ¶
(AI GENERATED DESCRIPTION): Generates Go source that defines a `DictTo<StructName>` function, converting a `map[string]any` into a typed struct by applying each field’s custom parsing logic.
func (*TlvModel) GenInitContext ¶
(AI GENERATED DESCRIPTION): Generates the Init method for the model’s parsing context, writing code that initializes each field defined in the TLV model.
func (*TlvModel) GenInitEncoder ¶
(AI GENERATED DESCRIPTION): Generates the Init method for a TLV encoder, initializing each field, computing the total encoding length, and building a wire‑plan slice for models that do not copy payload data.
func (*TlvModel) GenParsingContextStruct ¶
(AI GENERATED DESCRIPTION): Generates a Go struct named `<ModelName>ParsingContext` containing field declarations derived from the model’s fields and writes the resulting code into the supplied buffer.
func (*TlvModel) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates the Parse method for a TlvModel, producing Go code that reads a TLV‑encoded buffer into the model struct while respecting field ordering, critical‑field rules, and skipping unknown or unhandled tags.
func (*TlvModel) GenToDict ¶
(AI GENERATED DESCRIPTION): Generates a `ToDict` method that serializes a model instance into a `map[string]any` by converting each field to a dictionary entry.
func (*TlvModel) Generate ¶
(AI GENERATED DESCRIPTION): Generates Go source code for a TLV model, emitting encoder structs, optional parsing context, initialization, encode/decode logic, public API helpers, and dictionary conversion routines.
func (*TlvModel) ProcessOption ¶
(AI GENERATED DESCRIPTION): Sets the corresponding boolean configuration flags of a TlvModel based on the supplied option string, panicking if the option is unrecognized.
type WireField ¶
type WireField struct {
BaseTlvField
// contains filtered or unexported fields
}
WireField represents a binary string field of type Wire or [][]byte.
func (*WireField) GenEncodeInto ¶
(AI GENERATED DESCRIPTION): Generates code to encode a slice of wire elements, writing the field’s type number, length, and each element’s payload, with an optional copy‑or‑switch optimization.
func (*WireField) GenEncoderStruct ¶
(AI GENERATED DESCRIPTION): Generates a string declaring a uint field named `<wireField>_length` to be included in an encoder struct.
func (*WireField) GenEncodingLength ¶
(AI GENERATED DESCRIPTION): Generates Go code that, when run, adds the encoding length of the field to the total length only if the field is non‑nil.
func (*WireField) GenEncodingWirePlan ¶
(AI GENERATED DESCRIPTION): Generates the Go code snippet that encodes a field into the wire format, inserting length prefixes and looping over elements when `noCopy` is set, otherwise just producing the encoding‑length calculation.
func (*WireField) GenInitEncoder ¶
(AI GENERATED DESCRIPTION): Generates Go code that, during packet encoding, sums the byte lengths of each element in a field’s slice and assigns that total to the encoder’s corresponding length field.
func (*WireField) GenReadFrom ¶
(AI GENERATED DESCRIPTION): Generates code that reads a wire‑encoded field of length l into the struct’s field and assigns any read error to `err`.
func (*WireField) GenSkipProcess ¶
(AI GENERATED DESCRIPTION): Generates a code snippet that assigns `nil` to the specified field, effectively skipping its processing.