Skip to main content

Module value_codec

Module value_codec 

Source
Expand description

Large-value codec for the vector B-tree large-value path.

Self-contained byte-slice codec: knows nothing about pages, MVCC, or overflow chains. encode runs LZ4 and only keeps the compressed bytes if they are strictly smaller than the input — otherwise it returns the input verbatim under a Raw flag, so callers never pay negative-savings storage.

The flag is a single byte. The algorithm (LZ4) lives behind this interface so it can change later without touching callers.

Enums§

ValueCodecError
Errors returned by decode. Encoding is infallible — the codec always has a Raw fallback when LZ4 would grow the input.
ValueFlag
One-byte tag stored alongside the encoded payload. Distinguishes raw passthrough from compressed bytes so decode knows what to do without re-running compression.

Functions§

decode
Decode a (flag, bytes) pair produced by encode back to the original input bytes.
encode
Encode input for storage. Returns the flag indicating which representation is stored, plus the bytes themselves. When LZ4 would not shrink the input (including the 4-byte length header), the codec returns (Raw, input.to_vec()) — never a longer payload.
would_encode_to
Predicate companion to encode: would the encoded form fit in limit bytes? Returns the on-disk size the codec would use, without committing to a spill decision. Callers compare the returned size to their page budget and choose to spill or inline without re-running compression — encode is idempotent so re-running after a yes answer is cheap, but this keeps the budget check decoupled from the commit.