Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToSnakeCase ¶
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.
Click to show internal directories.
Click to hide internal directories.