Struct ssz::SszDecoder
source · pub struct SszDecoder<'a> { /* private fields */ }
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§
source§impl<'a> SszDecoder<'a>
impl<'a> SszDecoder<'a>
sourcepub fn decode_next<T: Decode>(&mut self) -> Result<T, DecodeError>
pub fn decode_next<T: Decode>(&mut self) -> Result<T, DecodeError>
sourcepub fn decode_next_with<T, F>(&mut self, f: F) -> Result<T, DecodeError>
pub fn decode_next_with<T, F>(&mut self, f: F) -> Result<T, DecodeError>
Decodes the next item using the provided function.
Auto Trait Implementations§
impl<'a> Freeze for SszDecoder<'a>
impl<'a> RefUnwindSafe for SszDecoder<'a>
impl<'a> Send for SszDecoder<'a>
impl<'a> Sync for SszDecoder<'a>
impl<'a> Unpin for SszDecoder<'a>
impl<'a> UnwindSafe for SszDecoder<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more