12 releases

0.3.9 Oct 23, 2024
0.3.7 Jun 28, 2024
0.3.4 Dec 22, 2023
0.3.3 Sep 23, 2023
0.3.2 Jul 26, 2023

#3 in #rlp

Download history 57005/week @ 2024-07-30 71262/week @ 2024-08-06 77789/week @ 2024-08-13 68290/week @ 2024-08-20 79136/week @ 2024-08-27 88498/week @ 2024-09-03 75554/week @ 2024-09-10 77703/week @ 2024-09-17 81147/week @ 2024-09-24 91484/week @ 2024-10-01 92411/week @ 2024-10-08 97795/week @ 2024-10-15 102124/week @ 2024-10-22 93765/week @ 2024-10-29 98401/week @ 2024-11-05 66989/week @ 2024-11-12

382,616 downloads per month
Used in 268 crates (50 directly)

MIT/Apache

47KB
1K SLoC

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–290KB