Expand description
Rust code generation: compile a Schema into typed readers and writers.
The generated reader is the novel part — an identity fast path:
every message carries its writer-schema hash, so the generated read()
compares it against the generation-time SCHEMA_ID constant. On a match
(the overwhelmingly common case) every getter is a bounds-checked load at
a constant offset computed here from the deterministic layout — the
same code shape flatc emits. On a mismatch it transparently falls back to
the resolver-driven plan path, keeping full schema evolution. Compile the
happy path, interpret the evolution path.
The generated writer is a direct single-pass encoder over typed …Args
structs — no dynamic Value tree.
Codegen v1 supports: all scalars, strings, bytes, enums (as raw u32),
nested structs, list<scalar>, list<string>, list<struct>. Not yet:
list<bytes>, list<enum>, nested lists (use the dynamic API for those).
Functions§
- generate_
cpp - Compile a schema to a single self-contained C++ header of structs with
to_verit/from_verit, over the header-onlyveritate.hppport. Like the other emitters it maps each struct to/from the dynamicValue/reader form and supports every schema shape (all struct modes, all list element types). Fields arestd::optional<T>(absent =std::nullopt). The embedded canonical schema + 128-bit id are the cross-language contract. - generate_
go - Compile a schema to a Go package of typed structs with
ToVerit/<Type>FromVeritover the stdlib-onlyveritateport. A small reflect runtime maps each struct to/from the port’sStructvalue form, so every schema the dynamic reader supports is supported here too. Optional fields are pointers (nil = absent). The embedded canonical schema + 128-bit id are the cross-language contract. - generate_
python - Compile a schema to a Python module of
@dataclasses withto_verit/from_verit, over the pure-stdlibveritateport. Unlike the Rust emitter, this supports every schema the dynamic reader does (all struct modes, all list element types) — the dataclasses map to/from the{field_id: value}form the port already speaks. The embedded canonical schema + 128-bit id are the cross-language contract. - generate_
rust - Generate a self-contained Rust module (as source text) for
schema. Include it withmod foo;/#[path = "..."] mod foo;— it depends only on theveritcrate’s public API. - generate_
ts - Compile a schema to a TypeScript module of classes with
toVerit/fromVeritover the pure-veritate.tsport. Like the Python emitter it supports every schema the dynamic reader does; classes map to/from the port’sst([[id, value]])form. The embedded canonical schema + 128-bit id are the cross-language contract. Runs under Node’s type stripping (the port is imported as./veritate.ts), so no separate compile step is needed.