Skip to content

CassetteCodec

Encodes/decodes a Cassette to/from its .qcast container: canonical JSON, gzipped by default so bodies and ledgers compress well, with a raw (plain JSON) path for inspection.

_schema_version is checked: this codec understands exactly one version. A newer version is refused outright, naming the version it needs — no silent best-effort parsing. There is no older version yet, so the “load an * old version through a documented forward-reader” branch has nothing to implement; when a version 2 exists, that branch is added here rather than assumed in advance.

final class CassetteCodec

SourceCassette/CassetteCodec.php
ConstantValueDescription
CURRENT_SCHEMA_VERSION1
DEFAULT_MAX_DECODED_BYTES33554432Ceiling on the inflated size of a .qcast payload, well above what replay.max_bytes’ own 2 MiB default plus a bounded effect ledger can produce, and far below what an unbounded inflate can cost.

public function __construct(positive-int $maxDecodedBytes = self::DEFAULT_MAX_DECODED_BYTES): mixed

Inflated-size ceiling for CassetteCodec::decode().

ParameterTypeDescription
$maxDecodedBytespositive-intInflated-size ceiling for CassetteCodec::decode().

Returns mixed

MethodDescription
decode(string $payload): CassetteDecodes a gzip-wrapped .qcast payload.
decodeRaw(string $json): CassetteDecodes a plain-JSON (--raw) payload.
encode(Cassette $cassette): stringGzip-wrapped JSON — the on-disk .qcast format.
encodeRaw(Cassette $cassette): stringPlain JSON, uncompressed — the --raw inspection format.

public function decode(string $payload): Cassette

Decodes a gzip-wrapped .qcast payload.

Inflated incrementally against $maxDecodedBytes rather than through gzdecode(), because a cassette is untrusted input and gzip’s compression ratio is unbounded: a few hundred kilobytes of highly repetitive .qcast inflates to hundreds of megabytes, and exhausting memory_limit is a fatal error rather than a catchable one — so a single oversized cassette in a store would take down cassette:list/cassette:prune for every cassette, past any catch (Throwable) a caller wrapped it in. Checking the budget as the output grows refuses that payload with a normal exception instead, and does so before the allocation rather than after it.

ParameterTypeDescription
$payloadstring

Returns Cassette

public function decodeRaw(string $json): Cassette

Decodes a plain-JSON (--raw) payload.

ParameterTypeDescription
$jsonstring

Returns Cassette

public function encode(Cassette $cassette): string

Gzip-wrapped JSON — the on-disk .qcast format.

ParameterTypeDescription
$cassetteCassette

Returns string

public function encodeRaw(Cassette $cassette): string

Plain JSON, uncompressed — the --raw inspection format.

ParameterTypeDescription
$cassetteCassette

Returns string