Skip to main content

Module value_codec

Module value_codec 

Source
Expand description

On-disk codec registry for Value.

This module is the single source of truth for the byte layout of every Value variant. Adding a new variant means:

  1. Add the variant to Value.
  2. Add the matching DataType tag (the on-disk type byte).
  3. Add an arm to encode and decode in this file.

That’s it — no other file needs to learn the layout. The inherent Value::to_bytes / Value::from_bytes methods stay as the public API, but they only delegate here.

§Why a registry

Before this module the encode / decode arms lived inside types.rs, mixed with display / coercion / hashing logic. A parallel value_type_tag helper in storage::query carried a third numbering scheme. The result was that every new variant required edits in three or more places and the tag spaces were free to drift.

With the registry there is exactly one mapping Value <-> on-disk bytes. The wire protocol keeps its own, independent VAL_* tag space (see wire/protocol.rs); the two were never identical and any future unification is out of scope.

§On-disk format

Bytes are unchanged versus the previous in-place implementation. The pinned-byte regression test [tests::pinned_bytes] guards the layout for the canonical variants (Null, Integer, Text, Bool, Blob).

Functions§

decode
Decode a single value from data, returning the value and the number of bytes consumed.
encode
Encode a value into out, appending its on-disk byte sequence.
type_for_tag
Reverse lookup for type_tag. Returns None for unknown bytes; Some(DataType::Nullable) for the dedicated null marker 0.
type_tag
On-disk tag byte for a value.

Type Aliases§

ValueKind
Alias kept for callers that prefer the registry’s own name. The on-disk tag space is owned by DataType; ValueKind reads better in registry contexts where the type name is the schema label rather than a parser concept.