# `X402.RLP`
[🔗](https://github.com/cardotrejos/x402/blob/v0.9.0/lib/x402/rlp.ex#L1)

Minimal pure [RLP](https://ethereum.org/en/developers/docs/data-structures-and-encoding/rlp/)
(Recursive Length Prefix) encoding.

Provides exactly the encoding surface `X402.Transaction` needs to build
EIP-1559 typed transactions: binaries, non-negative integers (encoded as
their minimal big-endian byte representation, so `0` encodes as the empty
string), and nested lists thereof. There is no decoder — the library never
needs to parse RLP, and settlement tests decode raw transactions with their
own reference decoder to prove the encoding.

## Examples

    iex> X402.RLP.encode("dog")
    <<0x83, "dog">>

    iex> X402.RLP.encode(["cat", "dog"])
    <<0xC8, 0x83, "cat", 0x83, "dog">>

    iex> X402.RLP.encode(0)
    <<0x80>>

    iex> X402.RLP.encode(1024)
    <<0x82, 0x04, 0x00>>

# `item`

```elixir
@type item() :: binary() | non_neg_integer() | [item()]
```

An RLP-encodable item: a binary, a non-negative integer, or a list of items.

# `encode`
*since 0.6.0* 

```elixir
@spec encode(item()) :: binary()
```

RLP-encodes a binary, a non-negative integer, or a (nested) list of items.

Integers are encoded as their minimal big-endian byte representation per
the Ethereum convention (`0` becomes the empty byte string, so leading
zero bytes never appear).

## Examples

    iex> X402.RLP.encode("")
    <<0x80>>

    iex> X402.RLP.encode(<<0x7F>>)
    <<0x7F>>

    iex> X402.RLP.encode(15)
    <<0x0F>>

    iex> X402.RLP.encode([])
    <<0xC0>>

    iex> X402.RLP.encode([[], [[]], [[], [[]]]])
    <<0xC7, 0xC0, 0xC1, 0xC0, 0xC3, 0xC0, 0xC1, 0xC0>>

---

*Consult [api-reference.md](api-reference.md) for complete listing*
