Struct ethers::utils::rlp::RlpStream [−]
pub struct RlpStream { /* fields omitted */ }
Expand description
Appendable rlp encoder.
Implementations
impl RlpStream
impl RlpStream
pub fn new_with_buffer(buffer: BytesMut) -> RlpStream
pub fn new_with_buffer(buffer: BytesMut) -> RlpStream
Initializes instance of empty Stream
.
pub fn new_list_with_buffer(buffer: BytesMut, len: usize) -> RlpStream
pub fn new_list_with_buffer(buffer: BytesMut, len: usize) -> RlpStream
Initializes the Stream
as a list.
pub fn append_empty_data(&mut self) -> &mut RlpStream
pub fn append_empty_data(&mut self) -> &mut RlpStream
Apends null to the end of stream, chainable.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(2);
stream.append_empty_data().append_empty_data();
let out = stream.out();
assert_eq!(out, vec![0xc2, 0x80, 0x80]);
Appends raw (pre-serialised) RLP data. Use with caution. Chainable.
Appends value to the end of stream, chainable.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(2);
stream.append(&"cat").append(&"dog");
let out = stream.out();
assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
pub fn append_iter<I>(&mut self, value: I) -> &mut RlpStream where
I: IntoIterator<Item = u8>,
pub fn append_iter<I>(&mut self, value: I) -> &mut RlpStream where
I: IntoIterator<Item = u8>,
Appends iterator to the end of stream, chainable.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(2);
stream.append(&"cat").append_iter("dog".as_bytes().iter().cloned());
let out = stream.out();
assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
pub fn append_list<E, K>(&mut self, values: &[K]) -> &mut RlpStream where
E: Encodable,
K: Borrow<E>,
pub fn append_list<E, K>(&mut self, values: &[K]) -> &mut RlpStream where
E: Encodable,
K: Borrow<E>,
Appends list of values to the end of stream, chainable.
pub fn append_internal<E>(&mut self, value: &E) -> &mut RlpStream where
E: Encodable,
pub fn append_internal<E>(&mut self, value: &E) -> &mut RlpStream where
E: Encodable,
Appends value to the end of stream, but do not count it as an appended item. It’s useful for wrapper types
pub fn begin_list(&mut self, len: usize) -> &mut RlpStream
pub fn begin_list(&mut self, len: usize) -> &mut RlpStream
Declare appending the list of given size, chainable.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(2);
stream.begin_list(2).append(&"cat").append(&"dog");
stream.append(&"");
let out = stream.out();
assert_eq!(out, vec![0xca, 0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g', 0x80]);
pub fn begin_unbounded_list(&mut self) -> &mut RlpStream
pub fn begin_unbounded_list(&mut self) -> &mut RlpStream
Declare appending the list of unknown size, chainable.
Appends raw (pre-serialised) RLP data. Checks for size overflow.
pub fn estimate_size(&self, add: usize) -> usize
pub fn estimate_size(&self, add: usize) -> usize
Calculate total RLP size for appended payload.
pub fn clear(&mut self)
pub fn clear(&mut self)
Clear the output stream so far.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(3);
stream.append(&"cat");
stream.clear();
stream.append(&"dog");
let out = stream.out();
assert_eq!(out, vec![0x83, b'd', b'o', b'g']);
pub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if stream doesnt expect any more items.
use rlp::RlpStream;
let mut stream = RlpStream::new_list(2);
stream.append(&"cat");
assert_eq!(stream.is_finished(), false);
stream.append(&"dog");
assert_eq!(stream.is_finished(), true);
let out = stream.out();
assert_eq!(out, vec![0xc8, 0x83, b'c', b'a', b't', 0x83, b'd', b'o', b'g']);
Get raw encoded bytes
pub fn out(self) -> BytesMut
pub fn out(self) -> BytesMut
Streams out encoded bytes.
panic! if stream is not finished.
pub fn encoder(&mut self) -> BasicEncoder<'_>
pub fn finalize_unbounded_list(&mut self)
pub fn finalize_unbounded_list(&mut self)
Finalize current unbounded list. Panics if no unbounded list has been opened.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RlpStream
impl UnwindSafe for RlpStream
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more