Struct ssz::SszDecoder [−][src]
pub struct SszDecoder<'a> { /* fields omitted */ }Expand description
Decodes some slices of SSZ into object instances. Should be instantiated using
SszDecoderBuilder.
Example
use ssz_derive::{Encode, Decode};
use ssz::{Decode, Encode, SszDecoder, SszDecoderBuilder};
#[derive(PartialEq, Debug, Encode, Decode)]
struct Foo {
a: u64,
b: Vec<u16>,
}
fn ssz_decoding_example() {
let foo = Foo {
a: 42,
b: vec![1, 3, 3, 7]
};
let bytes = foo.as_ssz_bytes();
let mut builder = SszDecoderBuilder::new(&bytes);
builder.register_type::<u64>().unwrap();
builder.register_type::<Vec<u16>>().unwrap();
let mut decoder = builder.build().unwrap();
let decoded_foo = Foo {
a: decoder.decode_next().unwrap(),
b: decoder.decode_next().unwrap(),
};
assert_eq!(foo, decoded_foo);
}
Implementations
pub fn decode_next_with<T, F>(&mut self, f: F) -> Result<T, DecodeError> where
F: FnOnce(&'a [u8]) -> Result<T, DecodeError>,
pub fn decode_next_with<T, F>(&mut self, f: F) -> Result<T, DecodeError> where
F: FnOnce(&'a [u8]) -> Result<T, DecodeError>,
Decodes the next item using the provided function.