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§

pub use crate::SimpleSerialize;
pub use crate::Sized;

Modules§

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

Structs§

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

Enums§

DeserializeError
Deserialization errors.
InstanceError
An invalid value.
MerkleizationError
An error encountered during merkleization.
SerializeError
Serialization errors.
SimpleSerializeError
Top-level error to wrap all other errors in this crate
TypeError
An invalid type.

Traits§

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

Functions§

deserialize
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
is_valid_merkle_branch verifies the Merkle proof against the root given the other metadata.
serialize
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.