Skip to main content

Module codec

Module codec 

Source
Expand description

Document codec (L4) — per-document header + postcard payload.

See docs/format.md § Document records for the authoritative byte-by-byte specification. This module is the reference implementation.

The codec sits between the typed Document API (this module) and the B+tree (L3): every stored value in a collection’s primary B-tree is the byte string produced by encode, and every Db::get decodes through decode. The catalog (L5) supplies the collection_id that the per-document header pins; the catalog itself stores CollectionDescriptors through this same codec (M5 issue #38).

§Power-of-ten posture

  • Rule 5. Encode and decode are runtime boundaries: every header field is validated explicitly before any postcard call touches caller-controlled bytes. CRC32C, collection-id, and version-range checks are the three layers of defense in decode.
  • Rule 7. No unwrap / expect on any error-bearing path; postcard errors propagate via the ? operator into Error::Codec.
  • Rule 9. Hot-path dispatch is static — all codec calls are monomorphised over T: Document. No dyn anywhere in this module.

Re-exports§

pub use crate::codec::dynamic::Dynamic;
pub use crate::codec::header::DocumentHeader;
pub use crate::codec::header::DOC_HEADER_SIZE;
pub use crate::codec::header::MAX_INLINE_DOC;
pub use crate::codec::migrate::Migrate;
pub use crate::codec::schema::DynamicSchema;
pub use crate::codec::schema::EnumVariantSchema;
pub use crate::codec::schema::Schema;
pub use crate::codec::schema::MAX_SCHEMA_DEPTH;

Modules§

dynamic
Dynamic — reflective value tree for schema migration.
header
Per-document record header — encode / decode.
migrate
Schema-evolution trait — Migrate.
schema
DynamicSchema — declarative description of a postcard-encoded payload’s shape.

Traits§

Document
The trait every user document type implements.

Functions§

decode
Decode an on-disk record into a T: Document instance.
encode
Encode doc into the on-disk record format.