Skip to main content

Encode

Trait Encode 

Source
pub trait Encode {
    // Required methods
    fn is_ssz_fixed_len() -> bool;
    fn ssz_bytes_len(&self) -> usize;
    fn ssz_append(&self, buf: &mut Vec<u8>);

    // Provided methods
    fn ssz_fixed_len() -> usize { ... }
    fn is_basic_type() -> bool { ... }
    fn as_ssz_bytes(&self) -> Vec<u8>  { ... }
}
Expand description

SSZ encoding trait.

ssz_append is the primary primitive: every other method delegates to it.

Required Methods§

Source

fn is_ssz_fixed_len() -> bool

true iff this type is fixed-length (no variable-length fields).

Source

fn ssz_bytes_len(&self) -> usize

Total size of self when serialized.

Source

fn ssz_append(&self, buf: &mut Vec<u8>)

Append the encoding of self to buf.

Provided Methods§

Source

fn ssz_fixed_len() -> usize

Number of bytes this type occupies in the fixed-length portion of a container encoding. For variable-length types this returns BYTES_PER_LENGTH_OFFSET (i.e. the size of the offset slot).

Source

fn is_basic_type() -> bool

true for “basic” SSZ types (uintN, bool), which pack adjacent elements into shared 32-byte chunks for merkleization. Composite types (containers, lists, structs) return false (the default).

Source

fn as_ssz_bytes(&self) -> Vec<u8>

Serialize into a fresh Vec<u8> allocated through the global allocator.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Encode for bool

Source§

impl Encode for u8

Source§

impl Encode for u16

Source§

impl Encode for u32

Source§

impl Encode for u64

Source§

impl Encode for u128

Source§

impl Encode for NonZeroU32

Source§

impl<A: Encode, B: Encode> Encode for (A, B)

Source§

impl<K: Encode + Ord, V: Encode> Encode for BTreeMap<K, V>

Source§

impl<T: Encode> Encode for Option<T>

Source§

impl<T: Encode> Encode for Vec<T>

Source§

impl<const N: usize> Encode for [u8; N]

Source§

impl<const N: usize> Encode for [u64; N]

Implementors§

Source§

impl Encode for U256

Source§

impl<T: Encode> Encode for MissingOr<T>

Source§

impl<T: Encode, const N: u64> Encode for List<T, N>

Source§

impl<T: Encode, const N: u64> Encode for SparseList<T, N>

Source§

impl<T: Encode, const N: usize> Encode for FixedVector<T, N>

Source§

impl<const N: u64> Encode for Bitlist<N>

Source§

impl<const N: usize> Encode for Bitvector<N>