#serialization #wasm-module #merkle-tree #ffi #canon #data-structures #database

nightly no-std canonical

A serialization library built for no_std environments where you want to deal with recursive datastructures

20 releases

0.7.1 Apr 29, 2022
0.7.0 Feb 23, 2022
0.6.7 Feb 23, 2022
0.6.5 Jun 8, 2021
0.4.2 Nov 12, 2020

#730 in Encoding

Download history 9/week @ 2023-11-27 2/week @ 2023-12-04 2/week @ 2023-12-11 11/week @ 2023-12-18 10/week @ 2023-12-25 9/week @ 2024-01-08 8/week @ 2024-01-15 10/week @ 2024-01-22 8/week @ 2024-02-05 12/week @ 2024-02-12 42/week @ 2024-02-19 55/week @ 2024-02-26 29/week @ 2024-03-04 17/week @ 2024-03-11

145 downloads per month
Used in 18 crates (17 directly)

MPL-2.0 license

28KB
668 lines

Canonical

Build Status Repository Documentation

Canonical is a specialized serialization library built for merkle trees and suitable for wasm environments.

Its main component is the Canon trait, which specifies how the type is encoded to/read from bytes.

This allows you, for example, to easily pass complex sets containing millions of elements between different wasm modules.

identifiers

Each value of a type implementing the Canon trait has a 1:1 relation to an Id.

let a = 42;

let id = Id::new(&a);

assert_eq!(id.reify().expect("read back"), a);

The Repr<T> is a smart-pointer type that either owns the value, contains a cryptographic hash of the value, or both. This allows you to construct recursive data types, that can also effeciently be stored and accessed as merkle trees.

canonical_derive

In order not to have to write all this byte-counting code by hand, canonical includes a derive-macro to implement them for you.

#[derive(Canon, PartialEq, Debug)]
struct A2 {
    a: u8,
    b: u8,
}

canonical_fuzz

A simple fuzzer built on top of the arbitrary crate. Allows you to fuzz the canon encoding for types, helpful if you choose to implement custom encodings.

The fuzzer also checks that the reported length of the value is correct with what is being written.

Dependencies

~0.4–6.5MB
~10K SLoC