Spectre.State.Codec (Spectre v0.3.0)

Copy Markdown View Source

Strict, versioned serialization for durable Spectre state.

The codec accepts JSON text or database-style maps with string keys. It validates state, effect, and awaitable lifecycle enums and rejects unknown fields instead of silently dropping them. Arbitrary nested terms are encoded through explicit tagged JSON values; decoding never creates atoms.

Summary

Functions

Decodes JSON text or a string/atom-keyed persistence map into validated state.

Decodes state or raises for trusted boot-time configuration paths.

Encodes state into a JSON-safe map whose public schema uses string keys.

Encodes state as JSON.

Functions

decode(json)

@spec decode(String.t() | map()) :: {:ok, Spectre.State.t()} | {:error, term()}

Decodes JSON text or a string/atom-keyed persistence map into validated state.

decode!(payload)

@spec decode!(String.t() | map()) :: Spectre.State.t()

Decodes state or raises for trusted boot-time configuration paths.

encode(state)

@spec encode(Spectre.State.t()) :: {:ok, map()} | {:error, term()}

Encodes state into a JSON-safe map whose public schema uses string keys.

encode_json(state)

@spec encode_json(Spectre.State.t()) :: {:ok, String.t()} | {:error, term()}

Encodes state as JSON.