Skip to main content

Module layout

Module layout 

Source
Expand description

Deterministic struct layout. Because the layout is a pure function of the schema, a schema id fully determines every byte offset — the schema acts as one shared “vtable” for every message that uses it, which is what makes per-message zero-copy access possible without per-object tables.

Two layout disciplines:

  • Fixed (sparse and dense structs): every field has a constant slot offset. Sparse structs prefix a presence bitmap; dense structs omit it.
  • Packed (sparse data, small wire): only present fields get slots, laid down in size-class order after the presence bitmap. A field’s offset is recovered in O(1) from the bitmap with popcount rank queries — no per-object vtable, no wasted slots. See PackedLayout.

Structs§

FixedLayout
Fixed layout: constant slot offset per field. bitmap_bytes is 0 for a dense struct (no presence bitmap), otherwise ceil(field_count / 8).
PackedField
PackedLayout
Packed layout: the block is a presence bitmap followed by slots for the present fields only, grouped into size classes (8/4/2/1 bytes) in that order. Block size and every slot offset depend on which fields are present, so both are computed per message from the bitmap — in O(1) via popcount. Limited to 64 fields so the bitmap fits one u64 rank word.

Enums§

StructLayout

Functions§

align_up
compute
Compute the layout for a struct’s fields (which must be ID-sorted, as they are in a validated schema).
map_entry_layout
Layout of one map<K, V> entry block. An entry is exactly a dense 2-field struct — key at implicit field id 0, value at id 1 — so every implementation derives the same key/value slot offsets, stride, and alignment from K and V alone, no schema type needed. slots[0] is the key offset, slots[1] the value; size is the entry stride.
slot_size_align
Size and alignment of a field slot within a struct block. Heap types (string/bytes/list/struct) occupy a u32 absolute-offset slot.
union_payload_offset
Byte offset of a union’s payload within its block: the u32 tag sits at offset 0, then the payload slot at its natural alignment. Every implementation derives it the same way from the selected variant type.