#rlp #ethereum #serialization

no-std alloy-rlp

Implementation of Ethereum RLP serialization

10 releases

0.3.7 Jun 28, 2024
0.3.6 Jun 28, 2024
0.3.5 May 22, 2024
0.3.4 Dec 22, 2023
0.1.0 Jun 13, 2023

#1241 in Magic Beans

Download history 46883/week @ 2024-03-17 47581/week @ 2024-03-24 60618/week @ 2024-03-31 56159/week @ 2024-04-07 52480/week @ 2024-04-14 51363/week @ 2024-04-21 43827/week @ 2024-04-28 43475/week @ 2024-05-05 48819/week @ 2024-05-12 44636/week @ 2024-05-19 51923/week @ 2024-05-26 48699/week @ 2024-06-02 45089/week @ 2024-06-09 52330/week @ 2024-06-16 58608/week @ 2024-06-23 21491/week @ 2024-06-30

180,002 downloads per month
Used in 157 crates (37 directly)

MIT/Apache

45KB
988 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