#![cfg_attr(not(feature = "std"), no_std)]
#[cfg(not(feature = "std"))]
extern crate alloc;
mod error;
mod impls;
mod rlpin;
mod stream;
mod traits;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use bytes::BytesMut;
use core::borrow::Borrow;
#[cfg(feature = "derive")]
pub use rlp_derive::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper};
pub use self::{
error::DecoderError,
rlpin::{PayloadInfo, Prototype, Rlp, RlpIterator},
stream::RlpStream,
traits::{Decodable, Encodable},
};
pub const NULL_RLP: [u8; 1] = [0x80; 1];
pub const EMPTY_LIST_RLP: [u8; 1] = [0xC0; 1];
pub fn decode<T>(bytes: &[u8]) -> Result<T, DecoderError>
where
T: Decodable,
{
let rlp = Rlp::new(bytes);
rlp.as_val()
}
pub fn decode_list<T>(bytes: &[u8]) -> Vec<T>
where
T: Decodable,
{
let rlp = Rlp::new(bytes);
rlp.as_list().expect("trusted rlp should be valid")
}
pub fn encode<E>(object: &E) -> BytesMut
where
E: Encodable,
{
let mut stream = RlpStream::new();
stream.append(object);
stream.out()
}
pub fn encode_list<E, K>(object: &[K]) -> BytesMut
where
E: Encodable,
K: Borrow<E>,
{
let mut stream = RlpStream::new();
stream.append_list(object);
stream.out()
}