pub trait Encode {
// Required methods
fn is_ssz_fixed_len() -> bool;
fn ssz_append(&self, buf: &mut Vec<u8>);
fn ssz_bytes_len(&self) -> usize;
// Provided methods
fn ssz_fixed_len() -> usize { ... }
fn as_ssz_bytes(&self) -> Vec<u8> { ... }
}
Expand description
Provides SSZ encoding (serialization) via the as_ssz_bytes(&self)
method.
See examples/
for manual implementations or the crate root for implementations using
#[derive(Encode)]
.
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 ssz_append(&self, buf: &mut Vec<u8>)
fn ssz_append(&self, buf: &mut Vec<u8>)
Append the encoding self
to buf
.
Note, variable length objects need only to append their “variable length” portion, they do not need to provide their offset.
sourcefn ssz_bytes_len(&self) -> usize
fn ssz_bytes_len(&self) -> usize
Returns the size (in bytes) when self
is serialized.
Returns the same value as self.as_ssz_bytes().len()
but this method is significantly more
efficient.
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.
sourcefn as_ssz_bytes(&self) -> Vec<u8>
fn as_ssz_bytes(&self) -> Vec<u8>
Returns the full-form encoding of this object.
The default implementation of this method should suffice for most cases.