Skip to content
docsv0.1.0

StateTransferCodecInterface

Serializes {@see StateSnapshot} and {@see InteractionRequest} to and from wire strings the client round-trips (e.g. embedded in a `<milpa-state>` element in the SSR'd page, then echoed back verbatim on the next interaction). Because the client is untrusted, {@see \Milpa\Live\Http\LiveEndpoint} relies on a signed decorator of this interface (pairing an inner codec with a {@see \Milpa\Live\Contracts\Security\StateSignerInterface}) so a decoded snapshot is provably the one the server last issued — plain encode/decode here carries no authenticity guarantee by itself.

StateTransferCodecInterface::encodeState()

abstract public function encodeState(Milpa\Live\ValueObjects\StateSnapshot $snapshot): string

Serializes a state snapshot to a wire string.

Parameters

Parameters of encodeState()
NameTypeDescription
$snapshotMilpa\Live\ValueObjects\StateSnapshot

StateTransferCodecInterface::decodeState()

abstract public function decodeState(string $encoded): Milpa\Live\ValueObjects\StateSnapshot

Parses a wire string back into a {@see StateSnapshot}.

Parameters

Parameters of decodeState()
NameTypeDescription
$encodedstring

Throws

\RuntimeException If `$encoded` is not well-formed, or (for signed implementations) fails signature verification.

StateTransferCodecInterface::encodeInteraction()

abstract public function encodeInteraction(Milpa\Live\ValueObjects\InteractionRequest $request): string

Serializes an interaction request to a wire string.

Parameters

Parameters of encodeInteraction()
NameTypeDescription
$requestMilpa\Live\ValueObjects\InteractionRequest

StateTransferCodecInterface::decodeInteraction()

abstract public function decodeInteraction(string $encoded): Milpa\Live\ValueObjects\InteractionRequest

Parses a wire string back into an {@see InteractionRequest}.

Parameters

Parameters of decodeInteraction()
NameTypeDescription
$encodedstring

Throws

\RuntimeException If `$encoded` is not well-formed, or (for signed implementations) fails signature verification.