pub trait Decode: Sized {
// Required methods
fn is_ssz_fixed_len() -> bool;
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>;
// Provided method
fn ssz_fixed_len() -> usize { ... }
}
Expand description
Provides SSZ decoding (de-serialization) via the from_ssz_bytes(&bytes)
method.
See examples/
for manual implementations or the crate root for implementations using
#[derive(Decode)]
.
Required Methods§
sourcefn is_ssz_fixed_len() -> bool
fn is_ssz_fixed_len() -> bool
Returns true
if this object has a fixed-length.
I.e., there are no variable length items in this object or any of it’s contained objects.
sourcefn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, DecodeError>
Attempts to decode Self
from bytes
, returning a DecodeError
on failure.
The supplied bytes must be the exact length required to decode Self
, excess bytes will
result in an error.
Provided Methods§
sourcefn ssz_fixed_len() -> usize
fn ssz_fixed_len() -> usize
The number of bytes this object occupies in the fixed-length portion of the SSZ bytes.
By default, this is set to BYTES_PER_LENGTH_OFFSET
which is suitable for variable length
objects, but not fixed-length objects. Fixed-length objects must return a value which
represents their length.