Expand description
MessagePack encoding/decoding for tree nodes
Blobs are stored raw (not wrapped) for efficiency. Tree nodes are MessagePack-encoded.
Determinism: Unlike CBOR, MessagePack doesn’t have a built-in canonical encoding. We ensure deterministic output by:
- Using fixed struct field order (Rust declaration order via serde)
- Converting HashMap metadata to BTreeMap before encoding (sorted keys)
- Sorting directory links by BUD-16 name order before encoding
File-node link order is preserved because chunk order is semantic.
Format uses short keys for compact encoding:
- t: type (1 = File, 2 = Dir, 3 = Fanout) - node type
- l: links array
- h: hash (in link)
- t: type (in link, 0 = Blob, 1 = File, 2 = Dir, 3 = Fanout)
- n: name (in link, optional)
- s: size (in link)
- m: metadata (optional)
Enums§
- Codec
Error - Error type for codec operations
Functions§
- decode_
tree_ node - Decode MessagePack to a tree node
- encode_
and_ hash - Encode a tree node and compute its hash
- encode_
tree_ node - Encode a tree node to MessagePack
- get_
node_ type - Get the type of data (Blob, File, Dir, or Fanout) Returns LinkType::Blob for raw blobs that aren’t tree nodes
- is_
directory_ node - Check if data is a directory-like tree node (node_type == Dir or Fanout) Note: Prefer try_decode_tree_node() to avoid double decoding
- is_
tree_ node - Check if data is a MessagePack-encoded tree node (vs raw blob) Tree-shaped data with unsupported types still counts as a tree node so callers that subsequently decode it surface a codec error instead of reinterpreting the bytes as a raw blob. Note: Prefer try_decode_tree_node() to avoid double decoding
- try_
decode_ tree_ node - Try to decode data as a tree node Returns Some(TreeNode) if valid tree node, None otherwise This is preferred over is_tree_node() to avoid double decoding