ArrayLikeCodecSentinelSize

type ArrayLikeCodecSentinelSize = object;

A size strategy for array-like codecs where the collection ends when the bytes at the next item position match a constant sentinel, compared at item boundaries only.

Unlike addCodecSentinel, the sentinel is never searched for within an item's bytes, so its bytes may occur inside an item without terminating the collection. This mirrors Codama's sentinelCountNode.

Remarks

Because the sentinel is only compared at the start of the next item slot, two invariants must hold for the collection to round-trip correctly. The codec does not enforce them — like Codama's sentinelCountNode, it is the caller's (or IDL author's) responsibility to guarantee them:

  1. No item may begin with the sentinel's bytes. A valid item that starts with the sentinel is indistinguishable from the terminator, so decoding would stop early at that item. The sentinel may still appear inside an item, just never at its start. For instance, a single 0xff byte is a poor sentinel for a list of public keys: roughly one key in 256 starts with 0xff, so such a key would prematurely terminate the list. A sentinel as wide as an item — for instance the all-zero (default) public key — avoids this, since only that exact key can ever match the terminator.
  2. Under "optional" and "omitted", the sentinel must be no wider than the smallest possible item. Otherwise a trailing region shorter than the sentinel but large enough to hold a valid item would be skipped: decoding stops as soon as fewer bytes than the sentinel remain, so that final item would never be read. This cannot arise under "required" because a terminator is always written.

See

SentinelCountStrategy

Properties

__kind

readonly __kind: "sentinel";

Internal discriminator identifying this object as a sentinel size strategy.


sentinel

readonly sentinel: ReadonlyUint8Array;

The fixed-size constant compared against the bytes at each item position.

No valid item may begin with these bytes, and under the "optional" / "omitted" strategies this must be no wider than the smallest possible item. See the remarks above.


strategy?

readonly optional strategy?: SentinelCountStrategy;

Whether the sentinel is written when encoding and required when decoding.

Default Value

"required"

On this page