Trait rlp::rlptraits::Stream
[−]
[src]
pub trait Stream: Sized {
fn new() -> Self;
fn new_list(len: usize) -> Self;
fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: RlpEncodable;
fn begin_list(&mut self, len: usize) -> &mut Self;
fn append_empty_data(&mut self) -> &mut Self;
fn append_raw<'a>(&'a mut self, bytes: &[u8], item_count: usize) -> &'a mut Self;
fn clear(&mut self);
fn is_finished(&self) -> bool;
fn as_raw(&self) -> &[u8];
fn out(self) -> Vec<u8>;
}
RLP encoding stream
Required Methods
fn new() -> Self
Initializes instance of empty Stream
.
fn new_list(len: usize) -> Self
Initializes the Stream
as a list.
fn append<'a, E>(&'a mut self, value: &E) -> &'a mut Self where E: RlpEncodable
Apends value to the end of stream, chainable.
extern crate rlp; use rlp::*; 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']); }
fn begin_list(&mut self, len: usize) -> &mut Self
Declare appending the list of given size, chainable.
extern crate rlp; use rlp::*; 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]); }
fn append_empty_data(&mut self) -> &mut Self
Apends null to the end of stream, chainable.
extern crate rlp; use rlp::*; 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]); }
fn append_raw<'a>(&'a mut self, bytes: &[u8], item_count: usize) -> &'a mut Self
Appends raw (pre-serialised) RLP data. Use with caution. Chainable.
fn clear(&mut self)
Clear the output stream so far.
extern crate rlp; use rlp::*; 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']); }
fn is_finished(&self) -> bool
Returns true if stream doesnt expect any more items.
extern crate rlp; use rlp::*; 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']); }
fn as_raw(&self) -> &[u8]
Get raw encoded bytes
fn out(self) -> Vec<u8>
Streams out encoded bytes.
panic! if stream is not finished.
Implementors
impl Stream for RlpStream