pub struct RlpStream { /* private fields */ }
Expand description
Appendable rlp encoder.
Implementations§
Source§impl RlpStream
impl RlpStream
Sourcepub fn new_with_buffer(buffer: BytesMut) -> Self
pub fn new_with_buffer(buffer: BytesMut) -> Self
Initializes instance of empty Stream
.
Sourcepub fn new_list_with_buffer(buffer: BytesMut, len: usize) -> Self
pub fn new_list_with_buffer(buffer: BytesMut, len: usize) -> Self
Initializes the Stream
as a list.
Sourcepub fn append_empty_data(&mut self) -> &mut Self
pub fn append_empty_data(&mut self) -> &mut Self
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]);
Sourcepub fn append_raw(&mut self, bytes: &[u8], item_count: usize) -> &mut Self
pub fn append_raw(&mut self, bytes: &[u8], item_count: usize) -> &mut Self
Appends raw (pre-serialised) RLP data. Use with caution. Chainable.
Sourcepub fn append<E>(&mut self, value: &E) -> &mut Selfwhere
E: Encodable,
pub fn append<E>(&mut self, value: &E) -> &mut Selfwhere
E: Encodable,
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']);
Sourcepub fn append_iter<I>(&mut self, value: I) -> &mut Selfwhere
I: IntoIterator<Item = u8>,
pub fn append_iter<I>(&mut self, value: I) -> &mut Selfwhere
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']);
Sourcepub fn append_list<E, K>(&mut self, values: &[K]) -> &mut Self
pub fn append_list<E, K>(&mut self, values: &[K]) -> &mut Self
Appends list of values to the end of stream, chainable.
Sourcepub fn append_internal<E>(&mut self, value: &E) -> &mut Selfwhere
E: Encodable,
pub fn append_internal<E>(&mut self, value: &E) -> &mut Selfwhere
E: Encodable,
Appends value to the end of stream, but do not count it as an appended item. It’s useful for wrapper types
Sourcepub 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]);
Sourcepub 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.
Sourcepub fn append_raw_checked(
&mut self,
bytes: &[u8],
item_count: usize,
max_size: usize,
) -> bool
pub fn append_raw_checked( &mut self, bytes: &[u8], item_count: usize, max_size: usize, ) -> bool
Appends raw (pre-serialised) RLP data. Checks for size overflow.
Sourcepub fn estimate_size(&self, add: usize) -> usize
pub fn estimate_size(&self, add: usize) -> usize
Calculate total RLP size for appended payload.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns current RLP size in bytes for the data pushed into the list.
pub fn is_empty(&self) -> bool
Sourcepub 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']);
Sourcepub 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']);
pub fn encoder(&mut self) -> BasicEncoder<'_>
Sourcepub 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.