#rlp #serde #data #implemented #ethereum #format

serde-rlp

Ethereum's RLP encoding implemented as a Serde data format

5 releases

Uses old Rust 2015

0.1.4 Sep 21, 2018
0.1.3 Sep 14, 2018
0.1.2 Sep 4, 2018
0.1.1 Sep 4, 2018
0.1.0 Sep 4, 2018

#1256 in Encoding

Download history 372/week @ 2024-03-13 81/week @ 2024-03-20 117/week @ 2024-03-27 94/week @ 2024-04-03 87/week @ 2024-04-10 94/week @ 2024-04-17 81/week @ 2024-04-24 92/week @ 2024-05-01 66/week @ 2024-05-08 76/week @ 2024-05-15 80/week @ 2024-05-22 84/week @ 2024-05-29 55/week @ 2024-06-05 56/week @ 2024-06-12 75/week @ 2024-06-19 82/week @ 2024-06-26

275 downloads per month
Used in 16 crates (via raiden-network-messages)

Custom license

38KB
1K SLoC

serde-rlp

Crates.io Build Status Docs.rs

Ethereum's RLP encoding implemented as a Serde data format

This code is part of clarity - an effort to implement lightweight Ethereum transaction signing. WIP.

Releasing

To release new version of serde-rlp do the following steps:

# Do a signed tag for new version with annotation "YYYY-MM-DD, Version v$VERSION"
git tag v1.0.0 -a -s "2018-09-04, Version v1.0.0"
git push origin --follow-tags

Examples

You should be able to use this crate same way as you'd use other serialization formats in serde.

Serialize

The key to serialization is serde_rlp::ser::to_bytes which does the magic.

extern crate serde_rlp;
use serde_rlp::ser::to_bytes;

// Basic key values
let data = vec![vec!["key1", "value1"], vec!["key2", "value2"]];
let bytes = to_bytes(&data).expect("Unable to serialize data");
println!("Serialized data: {:?}", bytes);

Deserialize

To deserialize data back into an object you should use serde_rlp::de::from_bytes.

extern crate serde_rlp;
use serde_rlp::de::from_bytes;

// Deserialize string "abc" encoded as RLP
let foo: String = from_bytes(&[0x83, 0x61, 0x62, 0x63]).unwrap();
println!("{}", foo);

An useful pattern is to deserialize into Vec<Bytes>, which will correctly deserialize elements of a RLP list.

Dependencies

~0.6–1MB
~20K SLoC