Expand description
§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
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);
Re-exports§
pub use bytes;
pub use bytes::Buf;
pub use bytes::BufMut;
pub use bytes::Bytes;
pub use bytes::BytesMut;
Macros§
- impl_
max_ encoded_ len - Implement
MaxEncodedLen
andMaxEncodedLenAssoc
for a type.
Structs§
Enums§
- Error
- RLP error type.
- Payload
View - Structured representation of an RLP payload.
Constants§
- EMPTY_
LIST_ CODE - RLP prefix byte for a 0-length array.
- EMPTY_
STRING_ CODE - RLP prefix byte for 0-length string.
Traits§
- Decodable
- A type that can be decoded from an RLP blob.
- Encodable
- A type that can be encoded via RLP.
- MaxEncoded
Len - Defines the max length of an
Encodable
type as a const generic. - MaxEncoded
LenAssoc - Defines the max length of an
Encodable
type as an associated constant.
Functions§
- decode_
exact - Decodes the entire input, ensuring no trailing bytes remain.
- encode
- Encode a value.
- encode_
fixed_ size arrayvec
- Encode a type with a known maximum size.
- encode_
iter - Encode all items from an iterator.
- encode_
list - Encode a list of items.
- length_
of_ length - Determine the length in bytes of the length prefix of an RLP item.
- list_
length - Calculate the length of a list.
Type Aliases§
- Result
- RLP result type.
Derive Macros§
- RlpDecodable
derive
- Derives
Decodable
for the type whose implementation expects an rlp-list input:<rlp-header, fields...>
- RlpDecodable
Wrapper derive
- Derives
Decodable
for the type whose implementation expects only the individual fields encoded:<fields...>
- RlpEncodable
derive
- Derives
Encodable
for the type which encodes the all fields as list:<rlp-header, fields...>
- RlpEncodable
Wrapper derive
- Derives
Encodable
for thenewtype
which encodes its single field as-is, without a header:<field>
- RlpMax
Encoded Len derive
- Derives
MaxEncodedLen
for types of constant size.