codegen

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidField = errors.New("invalid TlvField. Please check the annotation (including type and arguments)")
View Source
var ErrWrongTypeNumber = errors.New("invalid type number")

Functions

func GenEncodeTypeNum

func GenEncodeTypeNum(typeNum uint64) (string, error)

func GenNaturalNumberDecode

func GenNaturalNumberDecode(code string) (string, error)

func GenNaturalNumberEncode

func GenNaturalNumberEncode(code string, isTlv bool) (string, error)

func GenNaturalNumberLen

func GenNaturalNumberLen(code string, isTlv bool) (string, error)

func GenSwitchWire

func GenSwitchWire() (string, error)

func GenSwitchWirePlan

func GenSwitchWirePlan() (string, error)

func GenTlvNumberDecode

func GenTlvNumberDecode(code string) (string, error)

func GenTypeNumLen

func GenTypeNumLen(typeNum uint64) (string, error)

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)

func (*BaseTlvField) GenEncoderStruct

func (*BaseTlvField) GenEncoderStruct() (string, error)

func (*BaseTlvField) GenEncodingLength

func (*BaseTlvField) GenEncodingLength() (string, error)

func (*BaseTlvField) GenEncodingWirePlan

func (*BaseTlvField) GenEncodingWirePlan() (string, error)

func (*BaseTlvField) GenFromDict

func (*BaseTlvField) GenFromDict() (string, error)

func (*BaseTlvField) GenInitContext

func (*BaseTlvField) GenInitContext() (string, error)

func (*BaseTlvField) GenInitEncoder

func (*BaseTlvField) GenInitEncoder() (string, error)

func (*BaseTlvField) GenParsingContextStruct

func (*BaseTlvField) GenParsingContextStruct() (string, error)

func (*BaseTlvField) GenReadFrom

func (*BaseTlvField) GenReadFrom() (string, error)

func (*BaseTlvField) GenSkipProcess

func (*BaseTlvField) GenSkipProcess() (string, error)

func (*BaseTlvField) GenToDict

func (*BaseTlvField) GenToDict() (string, error)

func (*BaseTlvField) Name

func (f *BaseTlvField) Name() string

func (*BaseTlvField) TypeNum

func (f *BaseTlvField) TypeNum() uint64

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)

func (*BinaryField) GenEncodingLength

func (f *BinaryField) GenEncodingLength() (string, error)

func (*BinaryField) GenEncodingWirePlan

func (f *BinaryField) GenEncodingWirePlan() (string, error)

func (*BinaryField) GenFromDict

func (f *BinaryField) GenFromDict() (string, error)

func (*BinaryField) GenReadFrom

func (f *BinaryField) GenReadFrom() (string, error)

func (*BinaryField) GenSkipProcess

func (f *BinaryField) GenSkipProcess() (string, error)

func (*BinaryField) GenToDict

func (f *BinaryField) GenToDict() (string, error)

type BoolField

type BoolField struct {
	BaseTlvField
}

BoolField represents a boolean field.

func (*BoolField) GenEncodeInto

func (f *BoolField) GenEncodeInto() (string, error)

func (*BoolField) GenEncodingLength

func (f *BoolField) GenEncodingLength() (string, error)

func (*BoolField) GenEncodingWirePlan

func (f *BoolField) GenEncodingWirePlan() (string, error)

func (*BoolField) GenFromDict

func (f *BoolField) GenFromDict() (string, error)

func (*BoolField) GenReadFrom

func (f *BoolField) GenReadFrom() (string, error)

func (*BoolField) GenSkipProcess

func (f *BoolField) GenSkipProcess() (string, error)

func (*BoolField) GenToDict

func (f *BoolField) GenToDict() (string, error)

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)

func (*FixedUintField) GenEncodingLength

func (f *FixedUintField) GenEncodingLength() (string, error)

func (*FixedUintField) GenEncodingWirePlan

func (f *FixedUintField) GenEncodingWirePlan() (string, error)

func (*FixedUintField) GenFromDict added in v0.0.4

func (f *FixedUintField) GenFromDict() (string, error)

func (*FixedUintField) GenReadFrom

func (f *FixedUintField) GenReadFrom() (string, error)

func (*FixedUintField) GenSkipProcess

func (f *FixedUintField) GenSkipProcess() (string, error)

func (*FixedUintField) GenToDict added in v0.0.4

func (f *FixedUintField) GenToDict() (string, error)

type Generator

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

func NewGenerator

func NewGenerator() *Generator

func (*Generator) Generate

func (g *Generator) Generate(packName string)

func (*Generator) ProcessDecl

func (g *Generator) ProcessDecl(node ast.Node) bool

func (*Generator) Result

func (g *Generator) Result(filename string) []byte

Result returns the gofmt-ed contents of the Generator's buffer.

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)

func (*InterestNameField) GenEncoderStruct

func (f *InterestNameField) GenEncoderStruct() (string, error)

func (*InterestNameField) GenEncodingLength

func (f *InterestNameField) GenEncodingLength() (string, error)

func (*InterestNameField) GenEncodingWirePlan

func (f *InterestNameField) GenEncodingWirePlan() (string, error)

func (*InterestNameField) GenInitContext

func (f *InterestNameField) GenInitContext() (string, error)

func (*InterestNameField) GenInitEncoder

func (f *InterestNameField) GenInitEncoder() (string, error)

func (*InterestNameField) GenParsingContextStruct

func (f *InterestNameField) GenParsingContextStruct() (string, error)

func (*InterestNameField) GenReadFrom

func (f *InterestNameField) GenReadFrom() (string, error)

func (*InterestNameField) GenSkipProcess

func (f *InterestNameField) GenSkipProcess() (string, error)

type MapField added in v0.0.4

type MapField struct {
	BaseTlvField

	KeyField     TlvField
	ValField     TlvField
	KeyFieldType string
	ValFieldType string
}

func (*MapField) GenEncodeInto added in v0.0.4

func (f *MapField) GenEncodeInto() (string, error)

func (*MapField) GenEncoderStruct added in v0.0.4

func (f *MapField) GenEncoderStruct() (string, error)

func (*MapField) GenEncodingLength added in v0.0.4

func (f *MapField) GenEncodingLength() (string, error)

func (*MapField) GenEncodingWirePlan added in v0.0.4

func (f *MapField) GenEncodingWirePlan() (string, error)

func (*MapField) GenFromDict added in v0.0.4

func (f *MapField) GenFromDict() (string, error)

func (*MapField) GenInitContext added in v0.0.4

func (f *MapField) GenInitContext() (string, error)

func (*MapField) GenInitEncoder added in v0.0.4

func (f *MapField) GenInitEncoder() (string, error)

func (*MapField) GenParsingContextStruct added in v0.0.4

func (f *MapField) GenParsingContextStruct() (string, error)

func (*MapField) GenReadFrom added in v0.0.4

func (f *MapField) GenReadFrom() (string, error)

func (*MapField) GenSkipProcess added in v0.0.4

func (f *MapField) GenSkipProcess() (string, error)

func (*MapField) GenToDict added in v0.0.4

func (f *MapField) GenToDict() (string, error)

type NameField

type NameField struct {
	BaseTlvField
}

NameField represents a name field.

func (*NameField) GenEncodeInto

func (f *NameField) GenEncodeInto() (string, error)

func (*NameField) GenEncoderStruct

func (f *NameField) GenEncoderStruct() (string, error)

func (*NameField) GenEncodingLength

func (f *NameField) GenEncodingLength() (string, error)

func (*NameField) GenEncodingWirePlan

func (f *NameField) GenEncodingWirePlan() (string, error)

func (*NameField) GenFromDict

func (f *NameField) GenFromDict() (string, error)

func (*NameField) GenInitEncoder

func (f *NameField) GenInitEncoder() (string, error)

func (*NameField) GenReadFrom

func (f *NameField) GenReadFrom() (string, error)

func (*NameField) GenSkipProcess

func (f *NameField) GenSkipProcess() (string, error)

func (*NameField) GenToDict

func (f *NameField) GenToDict() (string, error)

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)

func (*NaturalField) GenEncodingLength

func (f *NaturalField) GenEncodingLength() (string, error)

func (*NaturalField) GenEncodingWirePlan

func (f *NaturalField) GenEncodingWirePlan() (string, error)

func (*NaturalField) GenFromDict

func (f *NaturalField) GenFromDict() (string, error)

func (*NaturalField) GenReadFrom

func (f *NaturalField) GenReadFrom() (string, error)

func (*NaturalField) GenSkipProcess

func (f *NaturalField) GenSkipProcess() (string, error)

func (*NaturalField) GenToDict

func (f *NaturalField) GenToDict() (string, error)

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)

func (*OffsetMarker) GenEncoderStruct

func (f *OffsetMarker) GenEncoderStruct() (string, error)

func (*OffsetMarker) GenEncodingLength

func (f *OffsetMarker) GenEncodingLength() (string, error)

func (*OffsetMarker) GenParsingContextStruct

func (f *OffsetMarker) GenParsingContextStruct() (string, error)

func (*OffsetMarker) GenReadFrom

func (f *OffsetMarker) GenReadFrom() (string, error)

func (*OffsetMarker) GenSkipProcess

func (f *OffsetMarker) GenSkipProcess() (string, error)

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)

func (*ProcedureArgument) GenParsingContextStruct

func (f *ProcedureArgument) GenParsingContextStruct() (string, error)

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)

func (*RangeMarker) GenEncoderStruct

func (f *RangeMarker) GenEncoderStruct() (string, error)

func (*RangeMarker) GenEncodingLength

func (f *RangeMarker) GenEncodingLength() (string, error)

func (*RangeMarker) GenParsingContextStruct

func (f *RangeMarker) GenParsingContextStruct() (string, error)

func (*RangeMarker) GenReadFrom

func (f *RangeMarker) GenReadFrom() (string, error)

func (*RangeMarker) GenSkipProcess

func (f *RangeMarker) GenSkipProcess() (string, error)

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)

func (*SequenceField) GenEncoderStruct

func (f *SequenceField) GenEncoderStruct() (string, error)

func (*SequenceField) GenEncodingLength

func (f *SequenceField) GenEncodingLength() (string, error)

func (*SequenceField) GenEncodingWirePlan

func (f *SequenceField) GenEncodingWirePlan() (string, error)

func (*SequenceField) GenFromDict

func (f *SequenceField) GenFromDict() (string, error)

func (*SequenceField) GenInitContext

func (f *SequenceField) GenInitContext() (string, error)

func (*SequenceField) GenInitEncoder

func (f *SequenceField) GenInitEncoder() (string, error)

func (*SequenceField) GenParsingContextStruct

func (f *SequenceField) GenParsingContextStruct() (string, error)

func (*SequenceField) GenReadFrom

func (f *SequenceField) GenReadFrom() (string, error)

func (*SequenceField) GenSkipProcess

func (f *SequenceField) GenSkipProcess() (string, error)

func (*SequenceField) GenToDict

func (f *SequenceField) GenToDict() (string, error)

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)

func (*SignatureField) GenEncoderStruct

func (f *SignatureField) GenEncoderStruct() (string, error)

func (*SignatureField) GenEncodingLength

func (f *SignatureField) GenEncodingLength() (string, error)

func (*SignatureField) GenEncodingWirePlan

func (f *SignatureField) GenEncodingWirePlan() (string, error)

func (*SignatureField) GenInitContext

func (f *SignatureField) GenInitContext() (string, error)

func (*SignatureField) GenInitEncoder

func (f *SignatureField) GenInitEncoder() (string, error)

func (*SignatureField) GenParsingContextStruct

func (f *SignatureField) GenParsingContextStruct() (string, error)

func (*SignatureField) GenReadFrom

func (f *SignatureField) GenReadFrom() (string, error)

func (*SignatureField) GenSkipProcess

func (f *SignatureField) GenSkipProcess() (string, error)

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)

func (*StringField) GenEncodingLength

func (f *StringField) GenEncodingLength() (string, error)

func (*StringField) GenEncodingWirePlan

func (f *StringField) GenEncodingWirePlan() (string, error)

func (*StringField) GenFromDict

func (f *StringField) GenFromDict() (string, error)

func (*StringField) GenReadFrom

func (f *StringField) GenReadFrom() (string, error)

func (*StringField) GenSkipProcess

func (f *StringField) GenSkipProcess() (string, error)

func (*StringField) GenToDict

func (f *StringField) GenToDict() (string, error)

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)

func (*StructField) GenEncoderStruct

func (f *StructField) GenEncoderStruct() (string, error)

func (*StructField) GenEncodingLength

func (f *StructField) GenEncodingLength() (string, error)

func (*StructField) GenEncodingWirePlan

func (f *StructField) GenEncodingWirePlan() (string, error)

func (*StructField) GenFromDict

func (f *StructField) GenFromDict() (string, error)

func (*StructField) GenInitContext

func (f *StructField) GenInitContext() (string, error)

func (*StructField) GenInitEncoder

func (f *StructField) GenInitEncoder() (string, error)

func (*StructField) GenParsingContextStruct

func (f *StructField) GenParsingContextStruct() (string, error)

func (*StructField) GenReadFrom

func (f *StructField) GenReadFrom() (string, error)

func (*StructField) GenSkipProcess

func (f *StructField) GenSkipProcess() (string, error)

func (*StructField) GenToDict

func (f *StructField) GenToDict() (string, error)

type TimeField

type TimeField struct {
	BaseTlvField
	// contains filtered or unexported fields
}

TimeField represents a time field, recorded as milliseconds.

func (*TimeField) GenEncodeInto

func (f *TimeField) GenEncodeInto() (string, error)

func (*TimeField) GenEncodingLength

func (f *TimeField) GenEncodingLength() (string, error)

func (*TimeField) GenEncodingWirePlan

func (f *TimeField) GenEncodingWirePlan() (string, error)

func (*TimeField) GenReadFrom

func (f *TimeField) GenReadFrom() (string, error)

func (*TimeField) GenSkipProcess

func (f *TimeField) GenSkipProcess() (string, error)

type TlvField

type TlvField interface {
	Name() string
	TypeNum() uint64

	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)

func NewBinaryField

func NewBinaryField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)

func NewBoolField

func NewBoolField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)

func NewFixedUintField

func NewFixedUintField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)

func NewInterestNameField

func NewInterestNameField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)

func NewMapField added in v0.0.4

func NewMapField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)

func NewNameField

func NewNameField(name string, typeNum uint64, _ string, _ *TlvModel) (TlvField, error)

func NewNaturalField

func NewNaturalField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)

func NewOffsetMarker

func NewOffsetMarker(name string, _ uint64, _ string, model *TlvModel) (TlvField, error)

NewOffsetMarker creates an offset marker field.

func NewProcedureArgument

func NewProcedureArgument(name string, _ uint64, annotation string, _ *TlvModel) (TlvField, error)

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)

func NewSignatureField

func NewSignatureField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)

func NewStringField

func NewStringField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)

func NewStructField

func NewStructField(name string, typeNum uint64, annotation string, model *TlvModel) (TlvField, error)

func NewTimeField

func NewTimeField(name string, typeNum uint64, annotation string, _ *TlvModel) (TlvField, error)

func NewWireField

func NewWireField(name string, typeNum uint64, _ string, model *TlvModel) (TlvField, error)

func ParseField

func ParseField(name string, typeNum uint64, fieldStr string, model *TlvModel) (TlvField, error)

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

	// 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

func (m *TlvModel) GenEncodeInto(buf *bytes.Buffer) error

func (*TlvModel) GenEncoderStruct

func (m *TlvModel) GenEncoderStruct(buf *bytes.Buffer) error

func (*TlvModel) GenFromDict

func (m *TlvModel) GenFromDict(buf *bytes.Buffer) error

func (*TlvModel) GenInitContext

func (m *TlvModel) GenInitContext(buf *bytes.Buffer) error

func (*TlvModel) GenInitEncoder

func (m *TlvModel) GenInitEncoder(buf *bytes.Buffer) error

func (*TlvModel) GenParsingContextStruct

func (m *TlvModel) GenParsingContextStruct(buf *bytes.Buffer) error

func (*TlvModel) GenReadFrom

func (m *TlvModel) GenReadFrom(buf *bytes.Buffer) error

func (*TlvModel) GenToDict

func (m *TlvModel) GenToDict(buf *bytes.Buffer) error

func (*TlvModel) Generate

func (m *TlvModel) Generate(buf *bytes.Buffer) error

func (*TlvModel) ProcessOption

func (m *TlvModel) ProcessOption(option string)

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

func (f *WireField) GenEncodeInto() (string, error)

func (*WireField) GenEncoderStruct

func (f *WireField) GenEncoderStruct() (string, error)

func (*WireField) GenEncodingLength

func (f *WireField) GenEncodingLength() (string, error)

func (*WireField) GenEncodingWirePlan

func (f *WireField) GenEncodingWirePlan() (string, error)

func (*WireField) GenInitEncoder

func (f *WireField) GenInitEncoder() (string, error)

func (*WireField) GenReadFrom

func (f *WireField) GenReadFrom() (string, error)

func (*WireField) GenSkipProcess

func (f *WireField) GenSkipProcess() (string, error)

Jump to

Keyboard shortcuts

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