Spectre.GAM.Canonical.Value (Spectre v0.4.0)

Copy Markdown View Source

Portable deterministic SPCV v1 values for GAM, using the shared Spectre codec.

Maps use canonical key order and decoding never creates atoms. Structs require :allowed_structs; processes, references, functions and improper lists are rejected. The GAM encoder checks its byte budget incrementally, before allocating the final binary. validate/2 checks the same budget without constructing that binary.

Summary

Functions

Decodes canonical bytes, rejecting trailing data, aliases and disallowed structs.

Returns the lowercase SHA-256 digest of a canonical value.

Returns the digest or raises ArgumentError for a non-canonical value.

Returns the digest algorithm used by digest/2.

Encodes a value into the versioned canonical binary format.

Encodes a value or raises ArgumentError with the stable failure reason.

Checks whether a value can be represented within this codec's limits.

Returns the canonicalization format version.

Types

reason()

@type reason() :: Spectre.Canonical.Value.reason()

Functions

decode(encoded, opts \\ [])

@spec decode(
  binary(),
  keyword()
) :: {:ok, term()} | {:error, reason()}

Decodes canonical bytes, rejecting trailing data, aliases and disallowed structs.

digest(value, opts \\ [])

@spec digest(
  term(),
  keyword()
) :: {:ok, String.t()} | {:error, reason()}

Returns the lowercase SHA-256 digest of a canonical value.

digest!(value, opts \\ [])

@spec digest!(
  term(),
  keyword()
) :: String.t()

Returns the digest or raises ArgumentError for a non-canonical value.

digest_algorithm()

@spec digest_algorithm() :: :sha256

Returns the digest algorithm used by digest/2.

encode(value, opts \\ [])

@spec encode(
  term(),
  keyword()
) :: {:ok, binary()} | {:error, reason()}

Encodes a value into the versioned canonical binary format.

Options: :allowed_structs, :max_bytes (including the header), :max_depth and :max_collection_size. See Spectre.Canonical.Value.encode/2.

encode!(value, opts \\ [])

@spec encode!(
  term(),
  keyword()
) :: binary()

Encodes a value or raises ArgumentError with the stable failure reason.

validate(value, opts \\ [])

@spec validate(
  term(),
  keyword()
) :: :ok | {:error, reason()}

Checks whether a value can be represented within this codec's limits.

version()

@spec version() :: pos_integer()

Returns the canonicalization format version.