Skip to main content

Module codec

Module codec 

Source
Expand description

Compact binary encoding for UBT nodes.

All node types use a 1-byte type tag prefix:

TagTypeSize
0x00Empty1 byte
0x01Internal65 bytes (tag + two 32B hashes)
0x02Stem64 + N×32 bytes (tag + stem + bitmap + values)
0x03Leaf33 bytes (tag + 32B value)

§StemNode layout

[1B type=0x02] [31B stem] [32B bitmap] [N×32B values]

Bitmap: 256 bits, bit i set = subindex i present. Bit ordering: byte[i/8] & (1 << (i%8)). Values in ascending subindex order, only for set bits.

Enums§

DecodedNode
A decoded node from the wire format.

Constants§

EMPTY_NODE_TAG
Type tag for empty nodes.
INTERNAL_NODE_TAG
Type tag for internal nodes (two child hashes).
LEAF_NODE_TAG
Type tag for leaf nodes (single value).
STEM_NODE_TAG
Type tag for stem nodes (bitmap + values).

Functions§

decode_internal_node
Decode an internal node from [0x01] [32B left_hash] [32B right_hash].
decode_leaf_node
Decode a leaf node from [0x03] [32B value].
decode_node
Decode any node type by dispatching on the type tag.
decode_stem_node
Decode a StemNode from compact binary format.
encode_empty_node
Encode an empty node as [0x00].
encode_internal_node
Encode an internal node as [0x01] [32B left_hash] [32B right_hash].
encode_leaf_node
Encode a leaf node as [0x03] [32B value].
encode_stem_node
Encode a StemNode into compact binary format.
encoded_stem_size
Returns the encoded size of a stem node without allocating.