Rlp
The Rlp module implementing Ethereum's Recursive Length Prefix
for arbitrary data encoding and decoding.
Constants
An empty array is defined as 0xC0.
An empty string is defined as 0x80.
The size limit of large data objects to be encoded is 256 ** 8.
The size limit of small data objects to be encoded is 56.
The offset for array list encoding is 192.
The offset for string literal encoding is 128.
The version of the Rlp module shard.
Class methods
Decodes arbitrary data structures from a given binary recursive length prefix data stream.
Parameters:
rlp(Bytes): the encodedRlpdata to decode.
Rlp.decode Bytes[195, 193, 192, 192]
# => [[[]], []]
NOTE: The returned data only restores the data structure. It's up to the protocol to determine the meaning of the data as defined in Ethereum's design rationale.
Decodes arbitrary data structures from a given hex-encoded recursive length prefix data stream.
Parameters:
hex(String): the encodedRlpdata to decode.
Rlp.decode "c7c0c1c0c3c0c1c0"
# => [[], [[]], [[], [[]]]]
NOTE: The returned data only restores the data structure. It's up to the protocol to determine the meaning of the data as defined in Ethereum's design rationale.
RLP-encodes binary Bytes data.
Parameters:
b(Bytes): the binaryBytesdata to encode.
Rlp.encode Bytes[15, 66, 64]
# => Bytes[131, 15, 66, 64]
RLP-encodes nested Array data.
Parameters:
l(Array): the nestedArraydata to encode.
Rlp.encode [[""], [""]]
# => Bytes[196, 193, 128, 193, 128]
RLP-encodes String literals.
Parameters:
s(String): theStringliteral to encode.
Rlp.encode "dog"
# => Bytes[131, 100, 111, 103]
RLP-encodes scalar Int numbers.
Parameters:
i(Int): the scalarIntnumber to encode.
Rlp.encode 1_000_000
# => Bytes[131, 15, 66, 64]
RLP-encodes Char characters.
Parameters:
c(Char): theCharcharacter to encode.
Rlp.encode 'x'
# => Bytes[120]
RLP-encodes boolean Bool values.
Parameters:
o(Bool): the booleanBoolvalue to encode.
Rlp.encode true
# => Bytes[1]