#ethereum #rlp #serialization

no-std alloy-rlp

Implementation of Ethereum RLP serialization

7 releases

0.3.4 Dec 22, 2023
0.3.3 Sep 23, 2023
0.3.2 Jul 26, 2023
0.2.0 Jun 23, 2023
0.1.0 Jun 13, 2023

#999 in Magic Beans

Download history 9730/week @ 2023-10-30 10081/week @ 2023-11-06 10375/week @ 2023-11-13 9745/week @ 2023-11-20 11620/week @ 2023-11-27 13617/week @ 2023-12-04 14062/week @ 2023-12-11 17979/week @ 2023-12-18 13914/week @ 2023-12-25 21633/week @ 2024-01-01 31382/week @ 2024-01-08 39771/week @ 2024-01-15 39244/week @ 2024-01-22 39767/week @ 2024-01-29 39610/week @ 2024-02-05 39239/week @ 2024-02-12

160,250 downloads per month
Used in 37 crates (9 directly)

MIT/Apache

41KB
953 lines

alloy-rlp

This crate provides Ethereum RLP (de)serialization functionality. RLP is commonly used for Ethereum EL datastructures, and its documentation can be found at ethereum.org.

Usage

We strongly recommend deriving RLP traits via the RlpEncodable and RlpDecodable derive macros.

Trait methods can then be accessed via the Encodable and Decodable traits.

Example

# #[cfg(feature = "derive")] {
use alloy_rlp::{RlpEncodable, RlpDecodable, Decodable, Encodable};

#[derive(Debug, RlpEncodable, RlpDecodable, PartialEq)]
pub struct MyStruct {
    pub a: u64,
    pub b: Vec<u8>,
}

let my_struct = MyStruct {
    a: 42,
    b: vec![1, 2, 3],
};

let mut buffer = Vec::<u8>::new();
let encoded = my_struct.encode(&mut buffer);
let decoded = MyStruct::decode(&mut buffer.as_slice()).unwrap();
assert_eq!(my_struct, decoded);
# }

Dependencies

~130–295KB