Noun.Jam (Anoma v0.29.0)

I am the implementation of Nock de/serialization functions, cue and jam.

Jam is optimized for small output size; cue is optimized for speed. (At least in theory; this implementation is not claiming perfection.)

Any improvements made here should neither make jam outputs larger nor make cue slower. Additionally, cue compatibility across all existing implementations is a hard requirement.

This implementation, unlike others, only emits references in jam if they would not make the output larger; existing implementations have a bug in calculating this. However, all existing implementations of cue are compatible with both encoders' output. Correctly calculating this makes outputs significantly smaller on large nouns.

Because we're going "backwards" in the Erlang runtime system sense, there's going to be some excessive copying. Cueing shouldn't need too much, except for alignment reasons, I think.

Public API

I have the following public functionality:

Summary

Types

I am the type of the cue cache, that is, I store the already decoded nouns as values to their encodings in a map for optimization.

I am the jam cache type. I store the reference alongside with its size.

Functions

I am the cue function.

I am the cue! function.

I am the jam function.

Types

@type cue_cache() :: %{required(non_neg_integer()) => Noun.t()}

I am the type of the cue cache, that is, I store the already decoded nouns as values to their encodings in a map for optimization.

@type jam_cache() :: %{required(Noun.t()) => {bitstring(), non_neg_integer()}}

I am the jam cache type. I store the reference alongside with its size.

Functions

@spec cue(binary()) :: {:ok, Noun.t()} | {:error, term()}

I am the cue function.

I execute cue! in a try environment and return the result wrapped in {:ok, result} upon success. Return :error otherwise.

See cue!/1 for more information.

@spec cue!(binary()) :: Noun.t()

I am the cue! function.

Given jammed input, I first change the endianness of the input, unpad the extra 0es inserted and proceed via the usual deserialization of Nock terms.

My inverse is jam/1

@spec jam(Noun.t()) :: binary()

I am the jam function.

I serialize any Nock noun into binary format. My inverse is cue!/1