alloy-rlp

Crates.ioalloy-rlp
lib.rsalloy-rlp
version0.3.5
sourcesrc
created_at2023-06-13 02:30:14.29668
updated_at2024-05-22 18:35:43.377344
descriptionImplementation of Ethereum RLP serialization
homepagehttps://github.com/alloy-rs/rlp/tree/main/crates/rlp
repositoryhttps://github.com/alloy-rs/rlp
max_upload_size
id888615
size43,335
core (github:alloy-rs:core)

documentation

README

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);
# }
Commit count: 39

cargo fmt