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 fixed0first element of child-row keys.- bytes (
&[u8]) — node subspaces are addressed by the raw allocated prefix bytes, and theversion/layer/hcarow 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):
| Code | Meaning |
|---|---|
0x00 | terminator of a byte/string payload (after escaping) |
0x01 | BYTES element |
0x02 | STRING element |
0x0b | start of the integer band (NEGINTSTART); i64 values pack into 0x14±len with len ≤ 8, so i64 codes stay within 0x0c..=0x1c |
0x14 | INT zero; 0x14+len / 0x14-len carry positive / negative integers |
0x1d | end of the integer band (POSINTEND; not produced by i64 packing) |
0xff | escape: 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 ± lencarries other integers. - CODE_
STRING - Code for a STRING element.
- ESCAPE
- Escape byte: inside a payload,
0x00 0xffstands for one0x00.
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.Noneon a bad code byte or an unterminated payload. - pack_
bytes - Pack a byte string as a top-level BYTES element.
- pack_
i64 - Pack an
i64as 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))fillingbytesexactly. - unpack_
element_ full - Decode a top-level BYTES or STRING element that fills
bytesexactly, 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
bytesexactly. - unpack_
string_ full - Decode a top-level STRING element that fills
bytesexactly, as UTF-8.