pub struct RlpStream { /* private fields */ }
Expand description

Appendable rlp encoder.

Implementations

Initializes instance of empty Stream.

Initializes the Stream as a list.

Initializes instance of empty Stream.

Initializes the Stream as a list.

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']);

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']);

Appends list of values to the end of stream, chainable.

Appends value to the end of stream, but do not count it as an appended item. It’s useful for wrapper types

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]);

Declare appending the list of unknown size, chainable.

Appends raw (pre-serialised) RLP data. Checks for size overflow.

Calculate total RLP size for appended payload.

Returns current RLP size in bytes for the data pushed into the list.

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']);

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

Streams out encoded bytes.

panic! if stream is not finished.

Finalize current unbounded list. Panics if no unbounded list has been opened.

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.