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)
Format uses short keys for compact encoding:
- t: type (1 = File, 2 = Dir) - node type
- l: links array
- h: hash (in link)
- t: type (in link, 0 = Blob, 1 = File, 2 = Dir)
- 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, or Dir) Returns LinkType::Blob for raw blobs that aren’t tree nodes
- is_
directory_ node - Check if data is a directory tree node (node_type == Dir) 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 nodes decode successfully with type = File or Dir 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