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§
- Fixed
Layout - Fixed layout: constant slot offset per field.
bitmap_bytesis 0 for a dense struct (no presence bitmap), otherwiseceil(field_count / 8). - Packed
Field - Packed
Layout - 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
u64rank word.
Enums§
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 fromKandValone, no schema type needed.slots[0]is the key offset,slots[1]the value;sizeis 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: theu32tag sits at offset 0, then the payload slot at its natural alignment. Every implementation derives it the same way from the selected variant type.