Skip to main content

Module tuple

Module tuple 

Source
Expand description

The tuple byte encoding the flat directory layout uses for its row keys.

This is a port of the subset of the FoundationDB tuple packing format that the directory layout produces and consumes: integer elements, byte-string elements, string (UTF-8) elements, and depth-0 tuples of them. It replicates the encoding of the foundationdb-tuple crate at the version the fdb backend is built against, so that keys produced here are byte-identical to the keys the FoundationDB directory layer would write for the same paths.

What is ported, and why it is sufficient:

  • i64 — the allocated prefixes, the HCA window starts and candidate values, and the fixed 0 first element of child-row keys.
  • bytes (&[u8]) — node subspaces are addressed by the raw allocated prefix bytes, and the version / layer / hca row tags are byte strings in the layer’s own code.
  • string (&str) — directory segment names in child-row keys.
  • depth-0 tuples — the only multi-element key the layout builds is (0i64, name) for child rows.

What is not ported: None, bool, f64, versionstamps, and nested (depth > 0) elements. The layout never produces or consumes them; a row whose encoding needs one of them cannot be a valid row of this layout, and the strict decoders here reject it.

Element codes (matching the foundationdb-tuple crate):

CodeMeaning
0x00terminator of a byte/string payload (after escaping)
0x01BYTES element
0x02STRING element
0x0bstart of the integer band (NEGINTSTART); i64 values pack into 0x14±len with len ≤ 8, so i64 codes stay within 0x0c..=0x1c
0x14INT zero; 0x14+len / 0x14-len carry positive / negative integers
0x1dend of the integer band (POSINTEND; not produced by i64 packing)
0xffescape: inside a byte/string payload, 0x00 is written as 0x00 0xff

Byte/string payloads carry no length prefix: they end at the first unescaped 0x00. An element is therefore self-delimiting, which is what makes the row keys decodable one element at a time.

Constants§

CODE_BYTES
Code for a BYTES element.
CODE_INT_ZERO
Code for the integer 0; 0x14 ± len carries other integers.
CODE_STRING
Code for a STRING element.
ESCAPE
Escape byte: inside a payload, 0x00 0xff stands for one 0x00.

Functions§

first_bytes_element
Decode the first element of a key and return its payload, without requiring the rest to be well-formed.
first_element_payload
Decode the leading BYTES or STRING element of key (up to its terminator) and return the unescaped payload (owned); the bytes after the terminator are ignored. None on a bad code byte or an unterminated payload.
pack_bytes
Pack a byte string as a top-level BYTES element.
pack_i64
Pack an i64 as a top-level tuple element.
pack_string
Pack a string as a top-level STRING element (UTF-8 bytes with the same escaping as pack_bytes).
unescape_payload
Unescape a payload (the element bytes without the terminator).
unpack_child_name
Decode the child-row key trailing a node subspace: a depth-0 tuple (0i64, STRING(name)) filling bytes exactly.
unpack_element_full
Decode a top-level BYTES or STRING element that fills bytes exactly, returning the unescaped payload (owned: escapes shorten the payload, so it is not a slice of the input).
unpack_i64_full
Decode a top-level integer element that fills bytes exactly.
unpack_string_full
Decode a top-level STRING element that fills bytes exactly, as UTF-8.