\Drupal\strata\Delta DeltaFrame

One encoded value, either self-contained or expressed against its previous version.

A value object rather than an array so a typo in a key is a type error instead of a silently absent field, and so the two modes cannot be confused: an anchor has no parent and depth zero, a delta has both, and the constructor refuses any other combination. That invariant is what lets DeltaCodec::decode() trust the frame it is handed.

Summary

Methods
Properties
Constants
__construct
isAnchor
length
ratio
jsonSerialize
fromArray
mode
codec
bytes
parent
depth
plainLength
MODE_ANCHOR
MODE_DELTA
No protected methods found
No protected properties found
No protected constants found
No private methods found
No private properties found
No private constants found

Constant

MODE_ANCHOR

MODE_ANCHOR = 'anchor'

A frame that decodes with nothing else.

MODE_DELTA

MODE_DELTA = 'delta'

A frame that decodes only against its parent.

Properties

$mode

$mode : string

Type

string

$codec

$codec : string

Type

string

$bytes

$bytes : string

Type

string

$parent

$parent : ?string

Type

string|null

$depth

$depth : int

Type

int

$plainLength

$plainLength : int

Type

int

Methods

__construct()

__construct(string  $mode, string  $codec, string  $bytes, string|null  $parent = null, int  $depth = 0, int  $plainLength = 0) : mixed

Constructs a frame.

Parameters

string $mode

DeltaFrame::MODE_ANCHOR or DeltaFrame::MODE_DELTA.

string $codec

The codec id the bytes were produced by, as recorded for the store.

string $bytes

The encoded bytes.

string|null $parent

Digest of the value this frame was encoded against, or NULL for an anchor.

int $depth

Links between this frame and its anchor; zero for an anchor.

int $plainLength

Length of the decoded value, so a caller can size a buffer and a verifier can catch a truncated decode without decoding twice.

Throws

\InvalidArgumentException

When the mode, parent and depth do not describe a coherent frame.

Returns

mixed —

isAnchor()

isAnchor() : bool

Whether this frame decodes without any other.

Returns

bool —

TRUE for an anchor.

length()

length() : int

Encoded size in bytes.

Returns

int —

Length of the encoded bytes.

ratio()

ratio() : float

How much smaller the encoding is than the value it encodes.

Returns

float —

Plain length divided by encoded length; 1.0 when either is zero.

jsonSerialize()

jsonSerialize() : array<string,mixed>

{@inheritdoc}

Returns

array

Keys mode, codec, parent, depth and plainLength verbatim, plus bytes base64-encoded so the frame survives JSON.

fromArray()

fromArray(array  $data) : self

Rebuilds a frame from its serialized form.

Parameters

array $data

The array produced by DeltaFrame::jsonSerialize().

Throws

\InvalidArgumentException

When a required key is missing, or the bytes are not valid base64.

Returns

self —

The frame.