Atom

binary.layout()

Freezes a reusable record layout.

Signature

binary.layout(fields[, packing])

Parameters

Nonempty dictionary whose text keys name fields and whose values describe their layouts, and optional positive power-of-two signed packing cap. Default uses natural alignment.

Returns

Layout value.

Behavior

Resolves nested definitions. The cap limits alignment of current fields. Nested layouts keep their own internal offsets.

Errors

Cyclic or empty layout, excessive nesting, invalid field types or packing.

Example

Atom
use binary
row = binary.layout({tag = u8, value = u32}, 1)
assert(binary.offset(row, 'value') == 1)