Skip to main content

Module document_body_codec

Module document_body_codec 

Source
Expand description

Native binary container for document bodies (PRD-1398, ADR-0063).

Encodes a named-field document (&[(&str, &Value)]) into a compact binary container with a header offset table that enables O(1) access to any top-level field value without decoding the entire document.

§Format — version 3

[0..4]  magic        = b"RDOC"
[4]     version      = 0x03
[5..7]  num_fields   : u16 LE          (max 65 535 fields per document)
[7..]   offset table : num_fields × [key_len: u16 LE, val_offset: u32 LE]
        keys section : concatenated UTF-8 field name bytes (key_len[i] each)
        values section: concatenated value_codec-encoded bytes

val_offset is an absolute byte offset from byte 0 of the container, allowing a single value to be decoded with decode_value_at_offset after reading only the header — the rest of the payload stays untouched.

§Flag-dark

This codec is compiled and tested but not yet wired into any storage or query path. Behaviour cutover happens in a later PRD-1398 slice.

Enums§

DocBodyError
Errors produced by the document body codec.

Constants§

MAGIC
Magic bytes at the start of every document body container.
VERSION
Format version byte for the plain (inline-keys-only) container.
VERSION_DICT
Format version byte for the dictionary-aware container (PRD-1398).

Functions§

decode
Decode all fields from a document body container.
decode_value_at_offset
Decode a single value using its absolute byte offset within the container.
decode_with_dictionary
Decode all fields from a dictionary-aware (v2) document body container.
encode
Encode fields as a document body container, appending bytes to out.
encode_with_dictionary
Encode fields as a dictionary-aware (v2) document body container.
field_names
Return the top-level field names in encode order without decoding any value.
parse_dict_header
Parse a v2 container header, returning (num_fields, table) where each table entry is (key_kind, key_ref, val_offset).
parse_header
Parse the container header and return (num_fields, offset_table).
read_field_by_name
Read a single field by name without decoding any other value.

Type Aliases§

DictEntry
One parsed v2 offset-table entry: (key_kind, key_ref, val_offset).