RLP (Recursive Length Prefix) is the serialization format used throughout the VirBiCoin protocol — for blocks, transactions and the node-to-node wire protocol. Its only purpose is to encode arbitrarily nested arrays of binary data; it does not attempt to encode numbers, booleans or other higher-level types. Those are defined by the structures that use RLP.
Data model
RLP encodes two kinds of values:
- Strings — sequences of bytes (a byte array).
- Lists — sequences of items, where each item is itself a string or a list, recursively.
Encoding rules
The encoding is defined by four cases, selected by the first byte (the prefix):
| Input | Prefix | Encoding |
|---|---|---|
Single byte in [0x00, 0x7f] | none | The byte is its own encoding |
| String 0–55 bytes long | 0x80 + len | Prefix byte followed by the string |
| String longer than 55 bytes | 0xb7 + lenOfLen | Prefix, then the length, then the string |
| List with 0–55 bytes of payload | 0xc0 + len | Prefix byte followed by the concatenated items |
| List with more than 55 bytes of payload | 0xf7 + lenOfLen | Prefix, then the payload length, then the items |
Examples
| Value | RLP (hex) |
|---|---|
The string "dog" | 83 64 6f 67 |
The empty string "" | 80 |
The empty list [] | c0 |
The list ["cat", "dog"] | c8 83 63 61 74 83 64 6f 67 |
Inspecting RLP with gvbc tools
The toolsuite includes rlpdump, which converts a binary RLP blob into a human-readable, hierarchical representation:
rlpdump --hex CE0183FFFFFFC4C304050583616263