schema

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: GPL-3.0 Imports: 0 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteOrder

type ByteOrder int

ByteOrder represents the byte order (endianness) for a field or protocol.

const (
	BigEndian    ByteOrder = iota // Network byte order
	LittleEndian                  // Little-endian byte order
)

func (ByteOrder) String

func (bo ByteOrder) String() string

String returns the string representation of a ByteOrder.

type ChecksumConfig

type ChecksumConfig struct {
	// Algorithm is the name of the checksum algorithm (e.g. "internet-checksum", "crc16").
	Algorithm string
	// CoverFields lists the fields covered by this checksum.
	// Supports both individual field names and range notation like "field1..field2".
	CoverFields []string
}

ChecksumConfig describes a checksum field's algorithm and coverage.

type ConditionExpr

type ConditionExpr struct {
	// FieldName is the field whose value is evaluated.
	FieldName string
	// Operator is the comparison operator (e.g. ">", "<", "==", "!=", ">=", "<=").
	Operator string
	// Value is the value to compare against.
	Value any
}

ConditionExpr describes a conditional expression for optional fields.

type EmbedDef

type EmbedDef struct {
	ProtocolName string
	Condition    *ConditionExpr
}

EmbedDef describes an embedded protocol reference.

type EnumDef

type EnumDef struct {
	Name   string
	Values map[int64]string
}

EnumDef represents a standalone enum type definition.

type ExprKind

type ExprKind int

ExprKind represents the kind of expression.

const (
	ExprLiteral ExprKind = iota
	ExprFieldRef
	ExprBinary
	ExprUnary
)

type Expression

type Expression struct {
	Kind     ExprKind
	Left     *Expression
	Right    *Expression
	Operator string // +, -, *, /, &, |, ^, <<, >>
	FieldRef string // field reference
	Value    int64  // literal value
}

Expression represents a field value expression.

type FieldDef

type FieldDef struct {
	// Name is the field name.
	Name string
	// Type is the data type of the field.
	Type FieldType
	// BitWidth is the width of the field in bits (1-64).
	BitWidth int
	// ByteOrder optionally overrides the protocol-level default byte order.
	ByteOrder *ByteOrder
	// EnumMap maps integer values to human-readable names.
	EnumMap map[int]string
	// Checksum holds the checksum configuration if this is a checksum field.
	Checksum *ChecksumConfig
	// Condition holds the condition expression for conditional fields.
	Condition *ConditionExpr
	// FixedLength is the fixed byte length for bytes/string fields (e.g. bytes[16]).
	// Zero means variable length (determined by LengthRef or remaining bytes).
	FixedLength int
	// LengthRef holds the length reference for variable-length fields.
	LengthRef *LengthRef
	// DisplayFormat is the name of the display formatter (e.g. "ipv4", "mac").
	DisplayFormat string
	// DefaultValue is the default value for this field (used during encoding if not provided).
	DefaultValue any
	// RangeMin and RangeMax define the valid value range for this field.
	RangeMin *int64
	RangeMax *int64
	// IsBitfieldGroup indicates whether this FieldDef represents a bitfield group.
	IsBitfieldGroup bool
	// BitfieldFields contains the sub-fields when IsBitfieldGroup is true.
	BitfieldFields []FieldDef
}

FieldDef describes a single field in a protocol schema. A FieldDef with IsBitfieldGroup=true acts as a bitfield group container, with its sub-fields stored in BitfieldFields.

type FieldType

type FieldType int

FieldType represents the data type of a protocol field.

const (
	Uint   FieldType = iota // Unsigned integer
	Int                     // Signed integer
	Bytes                   // Byte sequence
	String                  // UTF-8 string
	Bool                    // Boolean (1 bit)
)

func (FieldType) String

func (ft FieldType) String() string

String returns the string representation of a FieldType.

type GenericParam

type GenericParam struct {
	Name       string
	Constraint string // optional constraint
}

GenericParam represents a generic type parameter.

type GenericType

type GenericType struct {
	Name   string
	Params []GenericParam
	Fields []FieldDef
}

GenericType represents a generic type definition.

type LengthRef

type LengthRef struct {
	// FieldName is the name of the field whose value determines the length.
	FieldName string
	// Scale is the multiplier applied to the referenced field's value.
	Scale int
	// Offset is added to the scaled value to compute the final byte length.
	Offset int
}

LengthRef describes a variable-length field's length reference.

type MessageDef

type MessageDef struct {
	Name     string
	Kind     string // "request", "response", "notification"
	Fields   []MessageFieldDef
	Response *MessageDef // nested response (only if transport allows)
}

MessageDef describes a single request, response, or notification.

type MessageFieldDef

type MessageFieldDef struct {
	Name     string
	Type     MessageFieldType
	Optional bool
	// Fields holds nested fields when Type is MsgObject.
	Fields []MessageFieldDef
	// ItemType holds the element type when Type is MsgArray.
	ItemType *MessageFieldDef
}

MessageFieldDef describes a field in a message definition.

type MessageFieldType

type MessageFieldType int

MessageFieldType represents the type of a field in a message protocol.

const (
	MsgString  MessageFieldType = iota // string
	MsgNumber                          // number
	MsgBoolean                         // boolean
	MsgObject                          // object (nested fields)
	MsgArray                           // array
)

func (MessageFieldType) String

func (ft MessageFieldType) String() string

String returns the string representation of a MessageFieldType.

type MessageSchema

type MessageSchema struct {
	Name         string
	Version      string
	Transport    string        // "jsonrpc", "rest", "graphql"
	TransportVer *string       // optional pinned version (e.g., "2.0")
	TransportDef *TransportDef // resolved transport definition
	Messages     []MessageDef
}

MessageSchema is the internal representation of a message protocol.

type MessageTypeDef

type MessageTypeDef struct {
	Name        string
	Fields      []TransportFieldDef
	ResponseDef *MessageTypeDef // non-nil if this type supports nested response
}

MessageTypeDef describes a message type defined by a transport (e.g., request, notification, command).

type ModuleDef

type ModuleDef struct {
	Name      string
	Public    bool
	Imports   []UseStatement
	Constants map[string]int64
	Types     map[string]*TypeAlias
	Protocols []string
}

ModuleDef represents a PSL module declaration.

type PSL2Extensions

type PSL2Extensions struct {
	Generics    []GenericType
	Unions      []UnionType
	Enums       []EnumDef
	Module      *ModuleDef
	Expressions map[string]*Expression // field name -> computed expression
}

PSL2Extensions holds all PSL 2.0 extensions for a protocol.

type ProtocolSchema

type ProtocolSchema struct {
	// Name is the protocol name (e.g. "IPv4", "UDP").
	Name string
	// Version is the protocol version string.
	Version string
	// DefaultByteOrder is the protocol-level default byte order.
	DefaultByteOrder ByteOrder
	// Constants maps constant names to their values.
	Constants map[string]int64
	// Fields is the ordered list of field definitions.
	Fields []FieldDef
	// Imports lists imported protocol/file references.
	Imports []string
	// Extends is the parent protocol name (if any).
	Extends string
	// TypeAliases maps alias names to their definitions.
	TypeAliases map[string]*TypeAlias
}

ProtocolSchema is the internal representation of a protocol defined by PDL.

type TransportDef

type TransportDef struct {
	Name         string
	Version      string
	MessageTypes []MessageTypeDef
}

TransportDef holds the full transport definition extracted from a transport PSL.

type TransportFieldDef

type TransportFieldDef struct {
	Name         string
	Type         MessageFieldType
	Optional     bool
	DefaultValue any                 // nil means required from upper layer
	AutoValue    bool                // true for "default auto" (engine-generated)
	Fields       []TransportFieldDef // nested fields for object type
}

TransportFieldDef describes a field defined in a transport message type.

type TypeAlias

type TypeAlias struct {
	Name          string
	BaseType      FieldType
	BitWidth      int
	FixedLength   int
	DisplayFormat string
}

TypeAlias defines a named type alias.

type UnionType

type UnionType struct {
	Name    string
	Options []string // protocol names or type names
}

UnionType represents a union of multiple types.

type UseStatement

type UseStatement struct {
	Module string
	Names  []string // specific names to import, empty = import all
}

UseStatement represents a selective import.

type Visibility

type Visibility int

Visibility represents field/type visibility.

const (
	Private Visibility = iota
	Public
)

Jump to

Keyboard shortcuts

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