View Source DiodeClient.Rlp (Diode Client v1.1.3)

Encoding and Decoding of Recursive Length Prefix (RLP) https://eth.wiki/fundamentals/rlp

RLP is easy to decode and encode and has only two types of data: list() and binaries() for small binaries and lists there is very space efficient encoding. But primarily it allows native storing of binary data which is the main reason it's used within the Diode Network.

By convention maps are stored like keyword lists in Erlang as a list of key, value pairs such as: [[key1, value1], [key2, value2]]

To ease working with maps they are automatically encoded to a keyword list and there is the Rlpx.list2map to convert them back:

    iex> alias DiodeClient.{Rlp, Rlpx}
    iex> Rlp.encode!(%{key: "value"})
    <<203, 202, 131, 107, 101, 121, 133, 118, 97, 108, 117, 101>>
    iex> Rlp.encode!(%{key: "value"}) |> Rlp.decode!()
    [["key", "value"]]
    iex> Rlp.encode!(%{key: "value"}) |> Rlp.decode!()
    [["key", "value"]]
    iex> Rlp.encode!(%{key: "value"}) |> Rlp.decode! |> Rlpx.list2map
    %{"key" => "value"}

Link to this section Summary

Link to this section Types

Specs

rlp() :: binary() | [rlp()]

Link to this section Functions

Specs

decode(binary()) :: {rlp(), binary()}

Specs

decode!(binary()) :: rlp()
Link to this function

encode!(term, opts \\ [])

View Source

Encode an Elixir term to RLP. Integers are converted to binaries using :binary.encode_unsigned/1

If you want to encode integers as signed values pass encode!(term, unsigned: false)

Link to this function

encode_to_iolist!(term, opts \\ [])

View Source