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

Decodes the next item.

Panics

Panics when attempting to decode more items than actually exist.

Decodes the next item using the provided function.

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

Performs the conversion.

Performs the conversion.

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.