Spectre.Run.Codec (Spectre v0.3.0)

Copy Markdown View Source

Serializes a Spectre.Run to and from its portable checkpoint binary.

Encoding projects the run down to its logical, transport-safe form (raw input, PIDs, refs, and functions are dropped) and wraps it in a versioned envelope. Decoding validates the envelope, the run shape, and the lifecycle invariants of the checkpointed boundary before returning the run.

Summary

Functions

Decodes a checkpoint binary produced by encode/2 back into a Spectre.Run.

Encodes a run into a deterministic, versioned checkpoint binary.

Functions

decode(binary, opts)

@spec decode(
  binary(),
  keyword()
) :: {:ok, Spectre.Run.t()} | {:error, term()}

Decodes a checkpoint binary produced by encode/2 back into a Spectre.Run.

Enforces the size limit, rejects compressed or unknown envelopes, and revalidates the run's shape and lifecycle invariants, so an untrusted checkpoint can never yield an inconsistent run.

encode(run, opts)

@spec encode(
  Spectre.Run.t(),
  keyword()
) :: {:ok, binary()} | {:error, term()}

Encodes a run into a deterministic, versioned checkpoint binary.

The run is validated before encoding and the resulting binary is rejected with {:error, {:run_checkpoint_too_large, size, max}} when it exceeds :max_bytes (default 2000000).