Crate ssz_rs

source ·
Expand description

An implementation of the SSZ serialization scheme.

Examples

De/serialize a simple value:

let mut buf = Vec::new();
42u64.serialize(&mut buf);
assert_eq!(u64::deserialize(&buf).unwrap(), 42);

De/serialize a custom type using the derive macro:

#[derive(Debug, Default, PartialEq, Eq, SimpleSerialize)]
struct Data {
  flag: bool,
  value: u64
}

let mut buf = Vec::new();
Data { flag: true, value: 42 }.serialize(&mut buf);
assert_eq!(
  Data::deserialize(&buf).unwrap(),
  Data { flag: true, value: 42 }
);

Re-exports

Modules

  • The prelude contains common traits and types a user of this library would want to have handy with a simple (single) import.

Structs

  • A homogenous collection of a variable number of boolean values.
  • A homogenous collection of a fixed number of boolean values.
  • A homogenous collection of a variable number of values.
  • A node in a merkle tree.
  • An unsigned integer represented by 256 bits
  • A homogenous collection of a fixed number of values. NOTE: a Vector of length 0 is illegal.

Enums

Traits

  • A data structure that can be deserialized using SSZ.
  • A Merkleized type provides a “hash tree root” following the SSZ spec.
  • A data structure that can be serialized using SSZ.
  • SimpleSerialize is a trait for types conforming to the SSZ spec.
  • Sized is a trait for types that can provide sizing information relevant for the SSZ spec.

Functions

  • deserialize is a convenience function for taking an encoding for some value that implements SimpleSerialize in a &[u8] and attempting to deserialize that value from the byte representation.
  • is_valid_merkle_branch verifies the Merkle proof against the root given the other metadata.
  • serialize is a convenience function for taking a value that implements SimpleSerialize and attempting to encode it to a Vec<u8> according to the SSZ spec.