Skip to main content

decode_node_find

Function decode_node_find 

Source
pub fn decode_node_find(
    buf: &[u8; 4096],
    target: &[u8],
) -> Result<Option<Vec<u8>>>
Expand description

Find-only leaf decode: scan a leaf page for target and copy out ONLY the matched value as an owned Vec<u8> — never the whole 2N-entry node.

This is the read-path fast lane for crate::btree::BTree::get / get_via_snapshot. The page must be a leaf; an internal-node tag is rejected as Error::Corruption (a read never calls this on an internal node — get_via_snapshot gates on peek_node_kind and BTree::get descends to a leaf first).

§Safety / corruption posture

This path keeps EVERY per-slot integrity check that decode_node applies to the slots it actually reads: the leaf header invariants (level == 0, key_count <= LEAF_SLOT_CAP), the slot-offset range check, read_length_prefixed’s checked_add overflow guard and payload-end bound, the key.len() <= max_key_len() cap, and the inline strictly-ascending-key check. A tampered page therefore yields Error::Corruption identically to the full decode. The ONLY check it skips is the whole-node windows(2) ordering re-walk in validate_node_release, which is redundant because the inline ascending check is re-derived on every key the scan compares. No data-derived index touches buf[i] raw — every such access goes through read_length_prefixed’s checked slicing.

§Errors

Error::Corruption on any malformed header, slot, or varint; Error::BTreeInvariantViolated if the leaf header invariants fail.