serlp-0.1.2 has been yanked.
A (de)serializer for RLP encoding in ETH
Cargo.toml
serlp = "0.1"
serde = { version = "1.0", features = ['derive'] }
Not Supported Types
- bool
- float numbers
- enum
Example code
You can find more examples here
use ;
use ;
use serde_bytes;
Design principle
Accroding to the ETH Yellow Paper, all supported data structure can be represented with either recursive list of byte arrays or byte arrays
. So we can transform all Rust's compound types, for example, tuple, struct and list, into lists. And then encode them as exactly described in the paper
For example, the structure in example code, can be internally treated as the following form:
[
"This is a tooooooooooooo loooooooooooooooooooong tag",
[
114514,
[191, -9810],
[
[[], [[]], [[], [[]]]]
]
],
"哼.啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊"
]