Skip to main content

Module buffer

Module buffer 

Source
Expand description

Typesafe writer + reader for the host <-> wasm binary handshake.

Spec: docs/internal/adr/wasm-binary-layout-v1-2026-05-16.md.

BufferBuilder writes scalar fields by name into a pre-allocated byte buffer sized by a crate::layout::OffsetTable; BufferReader reads the same fields back. The intermediate Vec<u8> is exactly what the host hands the wasm module (run_main(in_ptr, in_len, out_ptr)) once Phase 2.b flips the wasm signature; in Phase 2.a the binary path is dormant but the writer/reader infrastructure is already in place so host code can be wired ahead of the codegen flip.

Type safety is enforced at runtime by checking the schema’s declared type for each field against the writer call (e.g. write_int on a Bool slot is BufferError::TypeMismatch). Static enforcement via codegen-generated wrappers is a Phase 3 follow-up.

Structs§

BufferBuilder
Type-checked writer over a record buffer with an optional tail area.
BufferReader
Type-checked reader over a record buffer plus optional tail area.
ListRecordWriter
Phase 10-c: in-flight List<Schema> element writer.

Enums§

BufferError
Failure modes when writing / reading typed fields against a buffer.

Functions§

write_nested_pointer_array_list
Marshal a List<List<String>> / List<List<Schema>> (F5: a doubly- nested pointer-array list, where each outer element is itself a pointer-array list) into field_name’s tail area. inner_element is the innermost element type (String / Schema / a deeper List<…>), matching the marshal_list_list_in dispatch contract; items are the outer Value::List rows (each itself a List<inner_element>). The whole nested structure is written at child-buffer-relative offsets and the field’s pointer slot patched to the outer header — the relocation walker’s PtrArrayElem::InnerList descriptor rebases the inner pointer arrays on the later arena rebase.
write_nested_scalar_list
Marshal a nested List<List<scalar>> arg / schema field into field_name’s tail area, given the inner element TypeRepr and the outer Value::List items (each element itself a Value::List of inline-fixed scalars). Shared by both compiled backends so they emit byte-identical input buffers. Inner pointer-array element lists (List<List<String>> / List<List<Schema>>) are rejected by the layout pass before reaching here; this routine only handles the inline-fixed innermost elements (Int / Float / Bool).