compiler

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToSnakeCase

func ToSnakeCase(name string) string

Types

type CompiledField

type CompiledField struct {
	Name          string
	GoName        string
	CName         string
	Description   string
	Type          schema.FieldType
	Offset        int
	Size          int
	Alignment     int
	IsVariable    bool
	PaddingBefore int
}

CompiledField holds the computed layout for a single field.

type CompiledMessage

type CompiledMessage struct {
	Name            string
	TypeID          uint16
	Fields          []*CompiledField
	FixedFields     []*CompiledField
	VariableFields  []*CompiledField
	TotalFixedSize  int
	StructAlignment int
	PaddingBlocks   int
}

CompiledMessage holds the computed memory layout for a single message type.

func CompileMessage

func CompileMessage(msg *schema.Message) *CompiledMessage

CompileMessage computes the memory layout for a single message, including offsets, padding, and alignment. It automatically optimizes the field order by sorting them by alignment requirement in descending order to minimize internal padding gaps before computing the final offsets. Then returns a CompiledMessage with all fields properly aligned and sized.

For Example:

Input Message Fields (from schema):
- key: string       (Size: 4, Align: 4) -> uint32 length prefix
- count: int32      (Size: 4, Align: 4)
- offset: uint64    (Size: 8, Align: 8)
- isEOF: bool       (Size: 1, Align: 1)

Optimized Field Layout (Sorted by Alignment Descending):
Field Name | Offset | Size | Alignment | Padding Before
--------------------------------------------------------
offset     | 0      | 8    | 8         | 0
count      | 8      | 4    | 4         | 0
key        | 12     | 4    | 4         | 0
isEOF      | 16     | 1    | 1         | 0
--------------------------------------------------------
Total Fixed Size: 24 bytes (17 bytes data + 7 bytes trailing padding)
Struct Alignment: 8 bytes

type CompiledSchema

type CompiledSchema struct {
	PackageName string
	Messages    []*CompiledMessage
}

CompiledSchema holds the fully resolved layout information for all messages.

func Compile

func Compile(s *schema.Schema, packageName string) *CompiledSchema

Compile takes a parsed schema and computes memory layouts with alignment. Uses `CompileMessage` to compute the layout for each message in the schema.

Jump to

Keyboard shortcuts

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