# `Spectre.GAM.Canonical.Value`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/gam/canonical/value.ex#L1)

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.

# `reason`

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

# `decode`

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

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

# `digest`

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

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

# `digest!`

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

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

# `digest_algorithm`

```elixir
@spec digest_algorithm() :: :sha256
```

Returns the digest algorithm used by `digest/2`.

# `encode`

```elixir
@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!`

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

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

# `validate`

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

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

# `version`

```elixir
@spec version() :: pos_integer()
```

Returns the canonicalization format version.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
