Documentation

RLP Encoding

Recursive Length Prefix — the canonical serialization format of the VirBiCoin protocol.

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):

InputPrefixEncoding
Single byte in [0x00, 0x7f]noneThe byte is its own encoding
String 0–55 bytes long0x80 + lenPrefix byte followed by the string
String longer than 55 bytes0xb7 + lenOfLenPrefix, then the length, then the string
List with 0–55 bytes of payload0xc0 + lenPrefix byte followed by the concatenated items
List with more than 55 bytes of payload0xf7 + lenOfLenPrefix, then the payload length, then the items

Examples

ValueRLP (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

See also