pub fn encode_sparse_response(
resp: &SparseResponse,
) -> Result<Vec<u8>, SparseWireError>Expand description
Encode a SparseResponse to the canonical wire bytes.
Layout:
offset size field
0 4 magic = SPARSE_WIRE_MAGIC ("MSP1")
4 1 version = SPARSE_WIRE_VERSION
5 32 tree_hash
37 32 bitmap_root
69 32 filter_hash
101 8 leaf_count (u64 LE)
109 4 entries_len (u32 LE) — count of TreeEntry items
113 ... TreeEntry stream, each entry:
u16 LE name_len (1..=255)
name_len bytes (name; arbitrary bytes)
u8 mode (EntryMode)
[u8; 32] object_hash
... 4 bitmap_len (u32 LE)
... N bitmap_bytesNames are u16-LE length-prefixed rather than the u32 used by
SPEC-OBJECTS — names are bounded at 255 bytes, so a u16 prefix is
already overkill, and the four-byte saving per entry adds up over a
large tree. The decoder rejects name_len == 0 and name_len > 255
to keep the bound enforced.
§Errors
SparseWireError::TooManyLeaves—manifest.leaf_count > MAX_LEAVES.SparseWireError::InvalidEntryName— an entry name is empty or255 bytes. Defensive: callers should reject before encoding.
SparseWireError::TooLarge— the encoded buffer would exceedSPARSE_WIRE_MAX_BYTES.