[−][src]Struct srlp::RlpStream
Appendable srlp encoder.
Methods
impl RlpStream
[src]
pub fn new() -> Self
[src]
Initializes instance of empty Stream
.
pub fn new_list(len: usize) -> Self
[src]
Initializes the Stream
as a list.
pub fn append_empty_data(&mut self) -> &mut Self
[src]
Apends null to the end of stream, chainable.
extern crate srlp; use srlp::*; fn main () { 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]); }
pub fn drain(self) -> Vec<u8>
[src]
Drain the object and return the underlying ElasticArray. Panics if it is not finished.
pub fn append_raw<'a>(
&'a mut self,
bytes: &[u8],
item_count: usize
) -> &'a mut Self
[src]
&'a mut self,
bytes: &[u8],
item_count: usize
) -> &'a mut Self
Appends raw (pre-serialised) RLP data. Use with caution. Chainable.
pub fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where
E: Encodable,
[src]
E: Encodable,
Appends value to the end of stream, chainable.
extern crate srlp; use srlp::*; fn main () { 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<'a, I>(&'a mut self, value: I) -> &'a mut Self where
I: IntoIterator<Item = u8>,
[src]
I: IntoIterator<Item = u8>,
Appends iterator to the end of stream, chainable.
extern crate srlp; use srlp::*; fn main () { 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<'a, E, K>(&'a mut self, values: &[K]) -> &'a mut Self where
E: Encodable,
K: Borrow<E>,
[src]
E: Encodable,
K: Borrow<E>,
Appends list of values to the end of stream, chainable.
pub fn append_internal<'a, E>(&'a mut self, value: &E) -> &'a mut Self where
E: Encodable,
[src]
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
[src]
Declare appending the list of given size, chainable.
extern crate srlp; use srlp::*; fn main () { 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
[src]
Declare appending the list of unknown size, chainable.
pub fn append_raw_checked<'a>(
&'a mut self,
bytes: &[u8],
item_count: usize,
max_size: usize
) -> bool
[src]
&'a mut self,
bytes: &[u8],
item_count: usize,
max_size: usize
) -> bool
Appends raw (pre-serialised) RLP data. Checks for size oveflow.
pub fn estimate_size<'a>(&'a self, add: usize) -> usize
[src]
Calculate total RLP size for appended payload.
pub fn len<'a>(&'a self) -> usize
[src]
Returns current RLP size in bytes for the data pushed into the list.
pub fn clear(&mut self)
[src]
Clear the output stream so far.
extern crate srlp; use srlp::*; fn main () { 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
[src]
Returns true if stream doesnt expect any more items.
extern crate srlp; use srlp::*; fn main () { 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 as_raw(&self) -> &[u8]
[src]
Get raw encoded bytes
pub fn out(self) -> Vec<u8>
[src]
Streams out encoded bytes.
panic! if stream is not finished.
pub fn encoder(&mut self) -> BasicEncoder
[src]
pub fn complete_unbounded_list(&mut self)
[src]
Finalize current ubnbound list. Panics if no unbounded list has been opened.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,