pub struct RlpStream { /* private fields */ }
Expand description
Appendable rlp encoder.
Implementations
sourceimpl RlpStream
impl RlpStream
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 drain(self) -> Vec<u8>
pub fn drain(self) -> Vec<u8>
Drain the object and return the underlying ElasticArray. Panics if it is not finished.
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 Self where
E: Encodable,
pub fn append<E>(&mut self, value: &E) -> &mut Self where
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 Self where
I: IntoIterator<Item = u8>,
pub fn append_iter<I>(&mut self, value: I) -> &mut Self 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']);
sourcepub fn append_list<E, K>(&mut self, values: &[K]) -> &mut Self where
E: Encodable,
K: Borrow<E>,
pub fn append_list<E, K>(&mut self, values: &[K]) -> &mut Self where
E: Encodable,
K: Borrow<E>,
Appends list of values to the end of stream, chainable.
sourcepub fn append_internal<E>(&mut self, value: &E) -> &mut Self where
E: Encodable,
pub fn append_internal<E>(&mut self, value: &E) -> &mut Self 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
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']);
sourcepub fn as_raw(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
pub fn as_raw(&self) -> &[u8]ⓘNotable traits for &'_ mut [u8]impl<'_> Write for &'_ mut [u8]impl<'_> Read for &'_ [u8]
Get raw encoded bytes
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.
sourcepub fn complete_unbounded_list(&mut self)
👎 Deprecated since 0.4.3: use finalize_unbounded_list instead
pub fn complete_unbounded_list(&mut self)
use finalize_unbounded_list instead
Finalize current unbounded list. Panics if no unbounded list has been opened.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RlpStream
impl Send for RlpStream
impl Sync for RlpStream
impl Unpin for RlpStream
impl UnwindSafe for RlpStream
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more