@sofa-buffers/corelib 0.8.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +267 -1
- package/README.md +764 -109
- package/dist/index.cjs +2799 -1171
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1780 -407
- package/dist/index.d.ts +1780 -407
- package/dist/index.global.js +2799 -1171
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +2788 -1168
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/public.ts","../src/constants.ts","../src/errors.ts","../src/long.ts","../src/varint/leb128.ts","../src/varint/num64.ts","../src/varint/zigzag.ts","../src/backend/js.ts","../src/backend/kernel.ts","../src/encode/fixlen.ts","../src/encode/ostream.ts","../src/decode/fast.ts","../src/decode/state.ts","../src/decode/istream.ts","../src/decode/cursor.ts","../src/backend/native.ts","../src/backend/wasm.ts"],"names":["SIGNED_FAST_MAX","TWO32","require"],"mappings":";;;;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,WAAA,EAAA,MAAA,WAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,aAAA,EAAA,MAAA,aAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,IAAA,EAAA,MAAA,IAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA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AAA,GAA+B,EAAC,EACd;AAClB,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI,MAAA,YAAkB,YAAY,MAAA,EAAQ;AACxC,IAAA,QAAA,GAAW,MAAM,WAAA,CAAY,WAAA,CAAY,MAAA,EAAQ,OAAO,CAAA;AAAA,EAC1D,CAAA,MAAA,IACE,OAAO,QAAA,KAAa,WAAA,KACnB,kBAAkB,QAAA,IAAY,UAAA,CAAW,MAAM,CAAA,CAAA,EAChD;AACA,IAAA,MAAM,MAAA,GAAS,MAAM,WAAA,CAAY,oBAAA;AAAA,MAC/B,MAAA;AAAA,MACA;AAAA,KACF;AACA,IAAA,QAAA,GAAW,MAAA,CAAO,QAAA;AAAA,EACpB,CAAA,MAAO;AACL,IAAA,MAAM,MAAA,GAAS,MAAM,WAAA,CAAY,WAAA,CAAY,QAAwB,OAAO,CAAA;AAC5E,IAAA,QAAA,GAAW,MAAA,CAAO,QAAA;AAAA,EACpB;AACA,EAAA,SAAA,CAAU,OAAA,CAAQ,QAAA,CAAS,OAAO,CAAC,CAAA;AACnC,EAAA,OAAO,IAAA;AACT;AAEA,SAAS,WAAW,CAAA,EAAuC;AACzD,EAAA,OACE,OAAO,CAAA,KAAM,QAAA,IACb,MAAM,IAAA,IACN,OAAQ,EAAyB,IAAA,KAAS,UAAA;AAE9C","file":"index.cjs","sourcesContent":["/**\n * The complete public surface of the library, re-exported by {@link \"./index\"}\n * both as flat named exports and, aggregated, under the `sofab` namespace.\n */\n\nexport {\n API_VERSION,\n ArrayKind,\n DecodeStatus,\n FixlenSubtype,\n WireType,\n ID_MAX,\n FIXLEN_MAX,\n ARRAY_MAX,\n MAX_DEPTH,\n U64_MAX,\n I64_MIN,\n I64_MAX,\n} from \"./constants.js\";\n\nexport { SofabError, SofabErrorCode } from \"./errors.js\";\n\nexport { Long } from \"./long.js\";\nexport { OStream } from \"./encode/ostream.js\";\nexport type { FlushSink } from \"./encode/sink.js\";\n\nexport { IStream, decode } from \"./decode/istream.js\";\nexport type { Visitor } from \"./decode/istream.js\";\nexport type { DecodeLimits } from \"./decode/limits.js\";\nexport { Cursor } from \"./decode/cursor.js\";\n\nexport { getKernel, setKernel } from \"./backend/kernel.js\";\nexport type { Kernel } from \"./backend/kernel.js\";\nexport { jsKernel } from \"./backend/js.js\";\nexport { loadNativeKernel } from \"./backend/native.js\";\nexport { loadWasmKernel } from \"./backend/wasm.js\";\nexport type { WasmKernelFactory } from \"./backend/wasm.js\";\n","/**\n * Wire-format constants for SofaBuffers.\n *\n * The format is specified, language-neutrally, in the\n * {@link https://github.com/sofa-buffers/documentation | SofaBuffers documentation}.\n * Every field on the wire begins with a varint header `(id << 3) | wireType`,\n * so the wire type lives in the low three bits and the field id in the rest.\n */\n\n/**\n * The SofaBuffers API version this library implements. The generator and other\n * tooling read it to verify compatibility. Bumped only on a breaking API change.\n */\nexport const API_VERSION = 1;\n\n/** The three low bits of a field header: what kind of field follows. */\nexport const WireType = {\n /** Unsigned varint scalar. */\n Unsigned: 0,\n /** Signed varint scalar (zig-zag encoded). */\n Signed: 1,\n /** Fixed-length value: fp32, fp64, string or blob (see {@link FixlenSubtype}). */\n Fixlen: 2,\n /** Array of unsigned varints. */\n ArrayUnsigned: 3,\n /** Array of signed (zig-zag) varints. */\n ArraySigned: 4,\n /** Array of fixed-length values (fp32 / fp64 only). */\n ArrayFixlen: 5,\n /** Opens a nested sequence (new id scope). */\n SequenceStart: 6,\n /** Closes the current sequence. Encoded as the single byte `0x07`. */\n SequenceEnd: 7,\n} as const;\n/** A field's wire type: one of the {@link WireType} values. */\nexport type WireType = (typeof WireType)[keyof typeof WireType];\n\n/** The three low bits of a fixlen length header: which fixed-length type. */\nexport const FixlenSubtype = {\n /** IEEE-754 32-bit float, little-endian. */\n Fp32: 0,\n /** IEEE-754 64-bit double, little-endian. */\n Fp64: 1,\n /** UTF-8 string (no null terminator). */\n String: 2,\n /** Arbitrary binary data. */\n Blob: 3,\n} as const;\n/** A fixed-length value's type: one of the {@link FixlenSubtype} values. */\nexport type FixlenSubtype = (typeof FixlenSubtype)[keyof typeof FixlenSubtype];\n\n/** Which element kind an array field carries (reported to {@link Visitor.arrayBegin}). */\nexport const ArrayKind = {\n /** Unsigned-integer elements. */\n Unsigned: 0,\n /** Signed-integer (zig-zag) elements. */\n Signed: 1,\n /** IEEE-754 32-bit float elements. */\n Fp32: 2,\n /** IEEE-754 64-bit double elements. */\n Fp64: 3,\n} as const;\n/** An array field's element kind: one of the {@link ArrayKind} values. */\nexport type ArrayKind = (typeof ArrayKind)[keyof typeof ArrayKind];\n\n/** Largest permitted field id and fixlen length / array count: `INT32_MAX`. */\nexport const ID_MAX = 0x7fff_ffff;\n/** Largest permitted fixlen byte length: `INT32_MAX`. */\nexport const FIXLEN_MAX = 0x7fff_ffff;\n/** Largest permitted array element count: `INT32_MAX`. */\nexport const ARRAY_MAX = 0x7fff_ffff;\n\n/** Largest unsigned 64-bit value (`2^64 - 1`). */\nexport const U64_MAX = 0xffff_ffff_ffff_ffffn;\n/** Smallest signed 64-bit value (`-2^63`). */\nexport const I64_MIN = -0x8000_0000_0000_0000n;\n/** Largest signed 64-bit value (`2^63 - 1`). */\nexport const I64_MAX = 0x7fff_ffff_ffff_ffffn;\n\n/** A varint encodes at most this many bytes for a 64-bit value. */\nexport const VARINT_MAX_BYTES = 10;\n\n/**\n * Maximum nested-sequence depth (§4.9 / §6.2). An encoder must not open more\n * than this many nested sequences, and a decoder must reject a message that\n * nests deeper with an `InvalidMessage` error rather than risk unbounded\n * recursion / stack growth.\n */\nexport const MAX_DEPTH = 255;\n\n/**\n * The terminal outcome of a decode (MESSAGE_SPEC §7), reported identically for\n * one-shot and streaming decode with **no** finish / finalize / end promotion\n * step:\n *\n * - `Complete` — the bytes ended exactly at a field boundary: a valid message.\n * - `Incomplete` — the bytes ended *inside* a field (an unterminated varint, a\n * payload shorter than its declared length, an array that runs off the end, or\n * a nested sequence never closed). **Not an error** — more bytes could\n * complete it, and the caller owns end-of-input.\n * - `Invalid` — the bytes are malformed regardless of what follows.\n *\n * {@link IStream.end} returns `Complete` or `Incomplete` (an `Invalid` message\n * has already thrown from {@link IStream.feed}); the one-shot {@link decode} /\n * {@link Cursor} path signals `Incomplete` and `Invalid` by throwing a\n * {@link SofabError} whose `code` is {@link SofabErrorCode.Incomplete} or\n * {@link SofabErrorCode.InvalidMsg}, and `Complete` by returning normally.\n */\nexport const DecodeStatus = {\n /** The bytes ended exactly at a field boundary — a valid message. */\n Complete: \"COMPLETE\",\n /** The bytes ended inside a field; more bytes could complete it (not an error). */\n Incomplete: \"INCOMPLETE\",\n /** The bytes are malformed regardless of what follows. */\n Invalid: \"INVALID\",\n} as const;\n/** A decode's terminal outcome: one of the {@link DecodeStatus} values. */\nexport type DecodeStatus = (typeof DecodeStatus)[keyof typeof DecodeStatus];\n","/**\n * Error handling for SofaBuffers.\n *\n * Both encoder and decoder report problems through a single {@link SofabError}\n * carrying a {@link SofabErrorCode}, mirroring the C reference's `sofab_ret_t`\n * return codes so the failure modes line up across the language family.\n *\n * The decoder distinguishes two *kinds* of decode failure (MESSAGE_SPEC §7):\n * {@link SofabErrorCode.InvalidMsg} for input that is malformed regardless of\n * what follows (`INVALID`), and {@link SofabErrorCode.Incomplete} for input that\n * merely ends inside a field (`INCOMPLETE`) — a truncation that more bytes could\n * complete, and so is *not* the same as a malformed message. A third code,\n * {@link SofabErrorCode.LimitExceeded}, is orthogonal to both: it reports a\n * receiver-configured decode limit being hit — *policy*, not a property of the\n * bytes — so it is kept distinct from `InvalidMsg`.\n */\n\n/**\n * The cause of a {@link SofabError}. `Argument`, `Usage`, `BufferFull` and\n * `InvalidMsg` match the C reference's `sofab_ret_t` codes; `Incomplete` is the\n * finish-less INCOMPLETE decode outcome (MESSAGE_SPEC §7), a distinct,\n * more-bytes-could-complete-it signal split out from `InvalidMsg`.\n */\nexport const SofabErrorCode = {\n /** A caller argument was invalid (e.g. id out of range, empty array). */\n Argument: \"ARGUMENT\",\n /** The API was used incorrectly (e.g. unbalanced sequence end). */\n Usage: \"USAGE\",\n /** The output buffer is full and no flush sink was provided. */\n BufferFull: \"BUFFER_FULL\",\n /** The input being decoded is malformed regardless of what follows (`INVALID`). */\n InvalidMsg: \"INVALID_MSG\",\n /**\n * The input being decoded ends inside a field (`INCOMPLETE`, MESSAGE_SPEC §7):\n * an unterminated varint, a payload shorter than its declared length, an array\n * that runs off the end, or a nested sequence never closed. Not a malformed\n * message — more bytes could complete it, and the caller owns end-of-input.\n */\n Incomplete: \"INCOMPLETE\",\n /**\n * A receiver-configured decode limit was exceeded — a dynamic array, string or\n * blob on the wire claims more elements / bytes than the caller's\n * {@link DecodeLimits} (`maxArrayCount` / `maxStringLen` / `maxBlobLen`)\n * allows. Deliberately distinct from {@link SofabErrorCode.InvalidMsg}:\n * exceeding a limit is *policy*, not wire malformation — the identical bytes\n * decode fine under a looser limit — so differential fuzzing must not read it\n * as a conformance divergence. The decoder never clamps or truncates; it\n * rejects, before the offending field is materialized.\n */\n LimitExceeded: \"LIMIT_EXCEEDED\",\n} as const;\n/** A {@link SofabError}'s cause: one of the {@link SofabErrorCode} values. */\nexport type SofabErrorCode =\n (typeof SofabErrorCode)[keyof typeof SofabErrorCode];\n\n/** The single error type thrown by the encoder and decoder. */\nexport class SofabError extends Error {\n /** The machine-readable cause. */\n readonly code: SofabErrorCode;\n\n constructor(code: SofabErrorCode, message: string) {\n super(message);\n this.name = \"SofabError\";\n this.code = code;\n // Restore the prototype chain for transpiled-to-ES5 consumers.\n Object.setPrototypeOf(this, SofabError.prototype);\n }\n}\n\n/** @internal A caller passed an invalid argument. */\nexport function argumentError(message: string): SofabError {\n return new SofabError(SofabErrorCode.Argument, message);\n}\n\n/** @internal The API was driven into an invalid state. */\nexport function usageError(message: string): SofabError {\n return new SofabError(SofabErrorCode.Usage, message);\n}\n\n/** @internal The output buffer filled with no flush sink to drain it. */\nexport function bufferFullError(message: string): SofabError {\n return new SofabError(SofabErrorCode.BufferFull, message);\n}\n\n/** @internal The input being decoded is malformed regardless of what follows. */\nexport function invalidMsgError(message: string): SofabError {\n return new SofabError(SofabErrorCode.InvalidMsg, message);\n}\n\n/**\n * @internal The input being decoded ended inside a field (truncation). A\n * distinct, non-malformed outcome (MESSAGE_SPEC §7): more bytes could complete\n * it, so it carries {@link SofabErrorCode.Incomplete}, never `InvalidMsg`.\n */\nexport function incompleteError(message: string): SofabError {\n return new SofabError(SofabErrorCode.Incomplete, message);\n}\n\n/**\n * @internal A receiver-configured decode limit ({@link DecodeLimits}) was\n * exceeded. Carries {@link SofabErrorCode.LimitExceeded}, never `InvalidMsg`:\n * it is a policy rejection, not a statement that the bytes are malformed.\n */\nexport function limitExceededError(message: string): SofabError {\n return new SofabError(SofabErrorCode.LimitExceeded, message);\n}\n","/**\n * A 64-bit integer value carried as two unsigned 32-bit halves.\n *\n * SofaBuffers accepts `bigint` at every 64-bit surface for ergonomics, but a\n * `bigint` in the encode/decode hot path is expensive — especially on\n * JavaScriptCore (Bun), where profiling showed the `bigint` split/materialise\n * and zig-zag operations dominating the 64-bit array codecs. `Long` lets a\n * caller (and the generated code) stay entirely on `number` arithmetic: the\n * codec reads `.low`/`.high` directly, and any `bigint`↔`Long` conversion\n * happens once at the API boundary rather than once per encode.\n *\n * Values are stored as raw two's-complement bits; the same `Long` serves an\n * unsigned or signed field — {@link Long.toBigInt} takes the signedness.\n */\nexport class Long {\n /** Low 32 bits (unsigned). */\n readonly low: number;\n /** High 32 bits (unsigned). */\n readonly high: number;\n\n constructor(low: number, high: number) {\n this.low = low >>> 0;\n this.high = high >>> 0;\n }\n\n /**\n * The 64-bit zero. `Long` is immutable (readonly halves), so this single shared\n * instance is safe to reuse anywhere a zero default is needed — generated code\n * uses it for fixed-count array defaults and pad-fill instead of\n * `Long.fromValue(0)`, which would run `bigint` arithmetic per call on the hot\n * decode/encode path.\n */\n static readonly ZERO: Long = new Long(0, 0);\n\n /** Construct from raw 32-bit halves. */\n static fromBits(low: number, high: number): Long {\n return new Long(low, high);\n }\n\n /** Split a `bigint` into its low/high 32-bit halves (two's complement). */\n static fromBigInt(value: bigint): Long {\n return new Long(Number(value & 0xffff_ffffn) >>> 0, Number((value >> 32n) & 0xffff_ffffn) >>> 0);\n }\n\n /** From an integer `number` (`|n| < 2^53`); sign handled via `bigint` once. */\n static fromNumber(n: number): Long {\n return Long.fromBigInt(BigInt(Math.trunc(n)));\n }\n\n /** Accept a `Long` as-is, or convert a `bigint` / `number` once. */\n static fromValue(v: Long | bigint | number): Long {\n if (v instanceof Long) return v;\n return typeof v === \"bigint\" ? Long.fromBigInt(v) : Long.fromNumber(v);\n }\n\n /** Materialise as a `bigint`. `signed` reads the high bit as two's complement. */\n toBigInt(signed = false): bigint {\n let r = (BigInt(this.high >>> 0) << 32n) | BigInt(this.low >>> 0);\n if (signed && (this.high & 0x8000_0000) !== 0) r -= 0x1_0000_0000_0000_0000n;\n return r;\n }\n\n /** Decimal string (`signed` interprets the high bit as two's complement). */\n toString(signed = false): string {\n return this.toBigInt(signed).toString();\n }\n}\n","/**\n * LEB128 variable-length integer coding.\n *\n * Each byte carries seven payload bits with the high bit as a continuation\n * flag; bytes are little-endian (least-significant group first). Values are\n * `bigint` so the full 64-bit range works. The streaming decoder in\n * `decode/state.ts` has its own resumable byte-at-a-time reader; the helpers\n * here are for whole-buffer paths (array elements, tests, the JS kernel).\n */\n\nimport { VARINT_MAX_BYTES } from \"../constants.js\";\nimport { incompleteError, invalidMsgError } from \"../errors.js\";\n\n/** Number of bytes {@link encodeVarint} will write for `value` (unsigned). */\nexport function varintSize(value: bigint): number {\n let lo = Number(value & 0xffff_ffffn) >>> 0;\n let hi = Number((value >> 32n) & 0xffff_ffffn) >>> 0;\n let n = 0;\n while (hi !== 0) {\n n++;\n const next = ((lo >>> 7) | (hi << 25)) >>> 0;\n hi >>>= 7;\n lo = next;\n }\n while (lo > 0x7f) {\n n++;\n lo >>>= 7;\n }\n return n + 1;\n}\n\n/**\n * Write `value` (an unsigned `bigint`) as a varint into `out` at `pos`.\n * The caller must guarantee `out` has at least {@link VARINT_MAX_BYTES} bytes\n * of room from `pos`. Returns the position just past the last byte written.\n *\n * The 64-bit value is split into two 32-bit *number* halves once (the only two\n * `bigint` operations), then the LEB128 groups are produced with number-only\n * arithmetic — `lo`'s top bits are fed from `hi` as it drains. This avoids the\n * ~20 short-lived `bigint` allocations a per-byte `v & 0x7fn; v >>= 7n` loop\n * would make, which V8 profiling showed to be the encoder's dominant cost.\n */\nexport function encodeVarint(value: bigint, out: Uint8Array, pos: number): number {\n let lo = Number(value & 0xffff_ffffn) >>> 0;\n let hi = Number((value >> 32n) & 0xffff_ffffn) >>> 0;\n // While high bits remain, every emitted byte is a full 7-bit group + continuation.\n while (hi !== 0) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo = ((lo >>> 7) | (hi << 25)) >>> 0; // shift the 64-bit value right by 7\n hi >>>= 7;\n }\n while (lo > 0x7f) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo >>>= 7;\n }\n out[pos++] = lo;\n return pos;\n}\n\n/**\n * Write a 64-bit value already split into two unsigned 32-bit halves as a\n * varint — the `bigint`-free sibling of {@link encodeVarint}. Callers holding a\n * `bigint` split it once (or hold a {@link Long}) and then stay on the number\n * path here, avoiding the per-value `bigint` churn that dominates the 64-bit\n * array encoders (and which JavaScriptCore optimizes far worse than V8).\n * `lo`/`hi` are coerced to uint32.\n */\nexport function encodeVarintLoHi(lo: number, hi: number, out: Uint8Array, pos: number): number {\n lo >>>= 0;\n hi >>>= 0;\n while (hi !== 0) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo = ((lo >>> 7) | (hi << 25)) >>> 0;\n hi >>>= 7;\n }\n while (lo > 0x7f) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo >>>= 7;\n }\n out[pos++] = lo;\n return pos;\n}\n\n/** Number of bytes {@link encodeVarintNum} will write for `value`. */\nexport function varintSizeNum(value: number): number {\n let n = 1;\n while (value > 0x7f) {\n n++;\n value = Math.floor(value / 128);\n }\n return n;\n}\n\n/**\n * Write `value` (a non-negative integer `number`, `≤ 2^53`) as a varint into\n * `out` at `pos`. The number-only sibling of {@link encodeVarint}: it avoids\n * `bigint` entirely, which is the encoder's hot path for ids, lengths, counts\n * and the very common small scalar. The caller guarantees {@link VARINT_MAX_BYTES}\n * bytes of room. Returns the position past the last byte written.\n */\nexport function encodeVarintNum(value: number, out: Uint8Array, pos: number): number {\n // Fast path: below 2^32 every 7-bit group survives bitwise extraction (ToUint32\n // is exact there, and `>>>` keeps it unsigned), so we stay on cheap integer ops.\n // This covers ids, lengths, counts, u8..u32 and their zig-zags — the vast\n // majority of calls. It matters because JavaScriptCore does not inline this\n // helper and its `% 128` / `Math.floor(/128)` float path is a top-3 hotspot\n // there; V8 optimizes both away, so the change is JSC-facing but harmless on V8.\n if (value < 0x1_0000_0000) {\n let v = value;\n while (v > 0x7f) {\n out[pos++] = (v & 0x7f) | 0x80;\n v >>>= 7;\n }\n out[pos++] = v;\n return pos;\n }\n // Slow path: 2^32 .. 2^53, where bitwise ops would truncate to 32 bits.\n while (value > 0x7f) {\n out[pos++] = (value % 128) | 0x80;\n value = Math.floor(value / 128);\n }\n out[pos++] = value;\n return pos;\n}\n\n/** The result of {@link decodeVarint}: the value and the position after it. */\nexport interface VarintResult {\n value: bigint;\n pos: number;\n}\n\n/**\n * Read a varint from `buf` starting at `pos`. Reports the same two decode\n * failures the streaming path does (MESSAGE_SPEC §7): throws a\n * {@link SofabError} with code `INVALID_MSG` on overflow past 64 bits (malformed\n * regardless of what follows), and `INCOMPLETE` if the buffer ends mid-varint\n * (an unterminated varint that more bytes could complete).\n */\nexport function decodeVarint(buf: Uint8Array, pos: number): VarintResult {\n let value = 0n;\n let shift = 0n;\n let bytes = 0;\n for (;;) {\n if (pos >= buf.length) throw incompleteError(\"truncated varint\");\n if (bytes >= VARINT_MAX_BYTES) throw invalidMsgError(\"varint overflow\");\n const byte = buf[pos++]!;\n // 10th byte carries only bit 63 below 64; any higher payload bit would\n // spill past bit 63 and is a >64-bit overflow (silently accepted before).\n if (bytes === VARINT_MAX_BYTES - 1 && (byte & 0x7f) > 1) {\n throw invalidMsgError(\"varint overflow\");\n }\n value |= BigInt(byte & 0x7f) << shift;\n bytes++;\n if ((byte & 0x80) === 0) return { value, pos };\n shift += 7n;\n }\n}\n","/**\n * 64-bit and IEEE-754 helpers.\n *\n * `bigint` masking utilities plus little-endian float pack/unpack built on a\n * single shared {@link DataView}. The format always stores `fp32` / `fp64`\n * little-endian regardless of host byte order, which a `DataView` gives us for\n * free (the `littleEndian` argument is passed explicitly everywhere).\n */\n\nimport { I64_MAX, I64_MIN, U64_MAX } from \"../constants.js\";\n\nconst SCRATCH = new DataView(new ArrayBuffer(8));\n\n/** Coerce a `number | bigint` to a `bigint`, rejecting non-integers. */\nexport function toBigInt(value: number | bigint): bigint {\n if (typeof value === \"bigint\") return value;\n if (!Number.isInteger(value)) {\n throw new RangeError(`expected an integer, got ${value}`);\n }\n return BigInt(value);\n}\n\n/** True when `value` fits in an unsigned 64-bit integer. */\nexport function inU64(value: bigint): boolean {\n return value >= 0n && value <= U64_MAX;\n}\n\n/** True when `value` fits in a signed 64-bit integer. */\nexport function inI64(value: bigint): boolean {\n return value >= I64_MIN && value <= I64_MAX;\n}\n\n/** Write `value` as a little-endian fp32 into `out` at `pos`; returns `pos + 4`. */\nexport function packFp32(out: Uint8Array, pos: number, value: number): number {\n SCRATCH.setFloat32(0, value, true);\n out[pos] = SCRATCH.getUint8(0);\n out[pos + 1] = SCRATCH.getUint8(1);\n out[pos + 2] = SCRATCH.getUint8(2);\n out[pos + 3] = SCRATCH.getUint8(3);\n return pos + 4;\n}\n\n/** Write `value` as a little-endian fp64 into `out` at `pos`; returns `pos + 8`. */\nexport function packFp64(out: Uint8Array, pos: number, value: number): number {\n SCRATCH.setFloat64(0, value, true);\n for (let i = 0; i < 8; i++) out[pos + i] = SCRATCH.getUint8(i);\n return pos + 8;\n}\n\n/** Read a little-endian fp32 from `buf` at `pos`. */\nexport function unpackFp32(buf: Uint8Array, pos: number): number {\n SCRATCH.setUint8(0, buf[pos]!);\n SCRATCH.setUint8(1, buf[pos + 1]!);\n SCRATCH.setUint8(2, buf[pos + 2]!);\n SCRATCH.setUint8(3, buf[pos + 3]!);\n return SCRATCH.getFloat32(0, true);\n}\n\n/** Read a little-endian fp64 from `buf` at `pos`. */\nexport function unpackFp64(buf: Uint8Array, pos: number): number {\n for (let i = 0; i < 8; i++) SCRATCH.setUint8(i, buf[pos + i]!);\n return SCRATCH.getFloat64(0, true);\n}\n","/**\n * Zig-zag mapping for signed integers.\n *\n * Signed values are zig-zag encoded before being written as an unsigned varint,\n * so small magnitudes of either sign stay short. The transform is the standard\n * `(n << 1) ^ (n >> 63)` over 64 bits, computed here in `bigint` so the full\n * `int64` range round-trips exactly.\n */\n\nimport { U64_MAX } from \"../constants.js\";\n\n/** Map a signed 64-bit value to its unsigned zig-zag representation. */\nexport function zigzagEncode(value: bigint): bigint {\n return ((value << 1n) ^ (value >> 63n)) & U64_MAX;\n}\n\n/** Recover a signed 64-bit value from its unsigned zig-zag representation. */\nexport function zigzagDecode(value: bigint): bigint {\n return (value >> 1n) ^ -(value & 1n);\n}\n","/**\n * The default, pure-TypeScript {@link Kernel}.\n *\n * Always available — no native dependency, no WebAssembly — so SofaBuffers runs\n * unchanged in Node.js, browsers, Electron and bundled builds. Importing this\n * module registers it as the default kernel (idempotently); a native or WASM\n * kernel can later override it via {@link setKernel}.\n */\n\nimport { encodeVarint, encodeVarintNum } from \"../varint/leb128.js\";\nimport { packFp32, packFp64, toBigInt } from \"../varint/num64.js\";\nimport { zigzagEncode } from \"../varint/zigzag.js\";\nimport type { Kernel } from \"./kernel.js\";\n\n// Largest signed magnitude whose zig-zag (|v|*2) stays an exact integer.\nconst SIGNED_FAST_MAX = 0x10_0000_0000_0000; // 2^52\n\n/**\n * The default, pure-TypeScript {@link Kernel} — active until {@link setKernel}\n * installs another. It implements the bulk encoder transforms with no native or\n * WebAssembly dependency, so it works in every environment.\n */\nexport const jsKernel: Kernel = {\n name: \"js\",\n\n encodeUnsignedVarints(values, out, pos) {\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n // Number elements (u8..u32 and any small u64) skip bigint entirely.\n if (typeof v === \"number\" && v >= 0 && v <= Number.MAX_SAFE_INTEGER && Number.isInteger(v)) {\n pos = encodeVarintNum(v, out, pos);\n } else {\n pos = encodeVarint(toBigInt(v), out, pos);\n }\n }\n return pos;\n },\n\n encodeSignedVarints(values, out, pos) {\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n if (typeof v === \"number\" && v >= -SIGNED_FAST_MAX && v <= SIGNED_FAST_MAX && Number.isInteger(v)) {\n pos = encodeVarintNum(v >= 0 ? v * 2 : -v * 2 - 1, out, pos);\n } else {\n pos = encodeVarint(zigzagEncode(toBigInt(v)), out, pos);\n }\n }\n return pos;\n },\n\n packFp32Array(values, out, pos) {\n for (let i = 0; i < values.length; i++) {\n pos = packFp32(out, pos, values[i]!);\n }\n return pos;\n },\n\n packFp64Array(values, out, pos) {\n for (let i = 0; i < values.length; i++) {\n pos = packFp64(out, pos, values[i]!);\n }\n return pos;\n },\n};\n","/**\n * The acceleration seam.\n *\n * The encoder's bulk array paths run through a {@link Kernel} — a small set of\n * self-contained, buffer-oriented transforms over a region the caller has\n * already sized. The default {@link \"./js\"} kernel is pure TypeScript and works\n * everywhere; a C++ (N-API) or WebAssembly build can implement the same\n * interface and be swapped in with {@link setKernel} for a speed-up, with **no\n * change to the public API**. The boundary is deliberately *bulk* (a whole\n * array per call, into guaranteed capacity) so the cost of crossing into native\n * code is amortised — never one call per element.\n */\n\nimport { jsKernel } from \"./js.js\";\n\n/**\n * Bulk, capacity-guaranteed transforms used on the encoder's fast path.\n *\n * Every method writes into `out` starting at `pos`, assuming the caller has\n * already ensured enough room, and returns the position just past the last byte\n * written. Headers, counts, flushing and validation stay in the stream classes;\n * a kernel only moves bytes.\n */\nexport interface Kernel {\n /** A short identifier, surfaced in diagnostics and the parity tests. */\n readonly name: string;\n\n /** Encode each element as an unsigned varint. */\n encodeUnsignedVarints(\n values: ArrayLike<number | bigint>,\n out: Uint8Array,\n pos: number,\n ): number;\n\n /** Zig-zag then varint-encode each element. */\n encodeSignedVarints(\n values: ArrayLike<number | bigint>,\n out: Uint8Array,\n pos: number,\n ): number;\n\n /** Pack each element as a little-endian fp32 (4 bytes). */\n packFp32Array(values: ArrayLike<number>, out: Uint8Array, pos: number): number;\n\n /** Pack each element as a little-endian fp64 (8 bytes). */\n packFp64Array(values: ArrayLike<number>, out: Uint8Array, pos: number): number;\n}\n\n// Initialised directly (not via an import side effect) so that bundlers honouring\n// the package's `\"sideEffects\": false` can never tree-shake the default away.\nlet active: Kernel = jsKernel;\n\n/** Install `kernel` as the active acceleration backend. */\nexport function setKernel(kernel: Kernel): void {\n validateKernel(kernel);\n active = kernel;\n}\n\n/** The currently active kernel (the JS kernel until something replaces it). */\nexport function getKernel(): Kernel {\n return active;\n}\n\n/** Throws if `kernel` is missing a required method — used by {@link setKernel}. */\nexport function validateKernel(kernel: Kernel): void {\n const required: (keyof Kernel)[] = [\n \"encodeUnsignedVarints\",\n \"encodeSignedVarints\",\n \"packFp32Array\",\n \"packFp64Array\",\n ];\n for (const m of required) {\n if (typeof kernel[m] !== \"function\") {\n throw new TypeError(`kernel \"${kernel?.name}\" is missing ${String(m)}()`);\n }\n }\n}\n","/**\n * Encode-side text helper.\n *\n * Two paths turn strings into UTF-8:\n *\n * - {@link utf8Length} / {@link utf8Write} — an allocation-free, two-pass writer\n * used by the encoder's in-memory fast path. `writeString` needs the byte\n * length *before* the payload (it goes into the fixlen length word), so the\n * length is scanned first and the bytes are then written straight into the\n * output buffer. This avoids `TextEncoder.encode`'s per-call WHATWG setup cost\n * plus the throwaway `Uint8Array` it allocates and the second copy into the\n * buffer — which V8 profiling showed to be the encoder's dominant cost (a\n * short string cost ~700 ns almost entirely in `TextEncoder`).\n * - {@link encodeUtf8} — a validated wrapper over the shared {@link TextEncoder},\n * still used by the streaming path where the payload is drained in chunks\n * through a small buffer.\n *\n * **Strict UTF-8 (MESSAGE_SPEC §8, CORELIB_PLAN §6.4).** A `string` is UTF-8\n * text; the encode side is always strict for this Unicode-string target. The\n * platform encoders are lossy — `TextEncoder`, and the hand-rolled fast path it\n * once mirrored, both replace an **unpaired surrogate** with `U+FFFD` — which is\n * the silent data mutation §8 forbids in every mode and direction. Both paths\n * here instead **reject** an unpaired surrogate with an `InvalidArgument`\n * {@link SofabError} (the encode-side image of the decode `INVALID` outcome), so\n * a producer can never emit bytes a strict decoder would refuse. Every *valid*\n * string — ASCII, multibyte BMP, correctly paired astral code points, embedded\n * `U+0000` — still encodes byte-for-byte as before.\n */\n\nimport { argumentError, type SofabError } from \"../errors.js\";\n\nconst UTF8 = new TextEncoder();\n\n/** An unpaired surrogate at `index` cannot be encoded as valid UTF-8 (§8/§6.4). */\nfunction unpairedSurrogate(index: number): SofabError {\n return argumentError(\n `unpaired surrogate at index ${index}: string value is not valid UTF-8`,\n );\n}\n\n/**\n * Encode `text` to UTF-8 bytes (no null terminator). Throws\n * {@link SofabError} (`ARGUMENT`) on an unpaired surrogate — `TextEncoder` alone\n * would silently substitute `U+FFFD`, the lossy mutation §8 forbids, so the\n * string is validated first and only well-formed input reaches the encoder.\n */\nexport function encodeUtf8(text: string): Uint8Array {\n // utf8Length is a full unpaired-surrogate scan that throws on the first one;\n // reuse it as the validator so both encode paths share one rule, then hand the\n // now-known-well-formed string to TextEncoder (byte-identical for valid input).\n utf8Length(text);\n return UTF8.encode(text);\n}\n\n/**\n * Number of UTF-8 bytes {@link utf8Write} will emit for `text`. For a\n * well-formed string this matches {@link TextEncoder} byte-for-byte (a paired\n * surrogate is 4 bytes). An **unpaired surrogate** is not encodable as UTF-8, so\n * it is **rejected** with {@link SofabError} (`ARGUMENT`), never counted as a\n * `U+FFFD` (3-byte) replacement (MESSAGE_SPEC §8).\n */\nexport function utf8Length(text: string): number {\n let len = 0;\n for (let i = 0; i < text.length; i++) {\n const c = text.charCodeAt(i);\n if (c < 0x80) {\n len += 1;\n } else if (c < 0x800) {\n len += 2;\n } else if (c >= 0xd800 && c <= 0xdbff) {\n // High surrogate: a following low surrogate makes a 4-byte code point;\n // otherwise it is an unpaired surrogate — reject, never collapse to U+FFFD.\n const c2 = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c2 >= 0xdc00 && c2 <= 0xdfff) {\n i++;\n len += 4;\n } else {\n throw unpairedSurrogate(i);\n }\n } else if (c >= 0xdc00 && c <= 0xdfff) {\n // Lone low surrogate (a paired one was consumed with its high half above).\n throw unpairedSurrogate(i);\n } else {\n // BMP ≥ 0x800.\n len += 3;\n }\n }\n return len;\n}\n\n/**\n * Write `text` as UTF-8 into `out` at `pos`; returns the position past the last\n * byte. The caller must have ensured {@link utf8Length}(text) bytes of room.\n * Byte-for-byte identical to {@link TextEncoder} for well-formed input; an\n * **unpaired surrogate** is rejected with {@link SofabError} (`ARGUMENT`) rather\n * than written as `U+FFFD` (MESSAGE_SPEC §8). `writeString` runs\n * {@link utf8Length} first, so the fast path rejects before any byte is emitted.\n */\nexport function utf8Write(text: string, out: Uint8Array, pos: number): number {\n for (let i = 0; i < text.length; i++) {\n let c = text.charCodeAt(i);\n if (c < 0x80) {\n out[pos++] = c;\n } else if (c < 0x800) {\n out[pos++] = 0xc0 | (c >> 6);\n out[pos++] = 0x80 | (c & 0x3f);\n } else if (c >= 0xd800 && c <= 0xdbff) {\n const c2 = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c2 >= 0xdc00 && c2 <= 0xdfff) {\n i++;\n c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);\n out[pos++] = 0xf0 | (c >> 18);\n out[pos++] = 0x80 | ((c >> 12) & 0x3f);\n out[pos++] = 0x80 | ((c >> 6) & 0x3f);\n out[pos++] = 0x80 | (c & 0x3f);\n } else {\n // Unpaired high surrogate — reject, never write U+FFFD.\n throw unpairedSurrogate(i);\n }\n } else if (c >= 0xdc00 && c <= 0xdfff) {\n // Unpaired low surrogate — reject, never write U+FFFD.\n throw unpairedSurrogate(i);\n } else {\n out[pos++] = 0xe0 | (c >> 12);\n out[pos++] = 0x80 | ((c >> 6) & 0x3f);\n out[pos++] = 0x80 | (c & 0x3f);\n }\n }\n return pos;\n}\n","/**\n * The SofaBuffers encoder.\n *\n * `OStream` writes fields into a byte buffer. Two modes:\n *\n * - **In-memory** (`new OStream()`): an auto-growing buffer; call\n * {@link OStream.bytes} for the finished message.\n * - **Streaming** (`new OStream(buffer, offset?, flush?)`): writes into a\n * caller-provided buffer and, when it fills, hands the produced bytes to the\n * `flush` sink and continues — so the buffer can be much smaller than the\n * message. `offset` reserves room at the front for a lower-layer header.\n *\n * Generated code typically writes one field per message field; the methods map\n * one-to-one onto the wire types. Problems throw {@link SofabError}.\n */\n\nimport {\n ARRAY_MAX,\n FIXLEN_MAX,\n FixlenSubtype,\n ID_MAX,\n MAX_DEPTH,\n VARINT_MAX_BYTES,\n WireType,\n} from \"../constants.js\";\nimport {\n argumentError,\n bufferFullError,\n usageError,\n} from \"../errors.js\";\nimport {\n getKernel,\n type Kernel,\n} from \"../backend/kernel.js\";\nimport { Long } from \"../long.js\";\nimport { encodeVarint, encodeVarintLoHi, encodeVarintNum, varintSize, varintSizeNum } from \"../varint/leb128.js\";\nimport { inI64, inU64, packFp32, packFp64, toBigInt } from \"../varint/num64.js\";\nimport { zigzagEncode } from \"../varint/zigzag.js\";\nimport { encodeUtf8, utf8Length, utf8Write } from \"./fixlen.js\";\nimport type { FlushSink } from \"./sink.js\";\n\nconst DEFAULT_CAPACITY = 256;\n\n/**\n * Largest magnitude a signed scalar takes on the number fast path: its zig-zag\n * image (`|v| * 2`) must stay an exact integer, i.e. `≤ 2^53`.\n */\nconst SIGNED_FAST_MAX = 0x10_0000_0000_0000; // 2^52\n\n/**\n * Encoder for the SofaBuffers wire format. Each `write*` method appends one\n * field and maps one-to-one onto a wire type. Construct it in-memory (an\n * auto-growing buffer, read back with {@link OStream.bytes}) or in streaming\n * mode over a caller-provided buffer that drains to a {@link FlushSink} as it\n * fills, so the message can outgrow the buffer. Invalid arguments and a full\n * buffer with no sink throw {@link SofabError}.\n */\nexport class OStream {\n private buf: Uint8Array;\n private pos: number;\n private start: number;\n private readonly flushSink: FlushSink | undefined;\n private readonly canGrow: boolean;\n private depth = 0;\n private kernel: Kernel;\n\n /** In-memory encoder backed by an auto-growing buffer. */\n constructor();\n /** Streaming encoder over a caller buffer, optionally draining to `flush`. */\n constructor(buffer: Uint8Array, offset?: number, flush?: FlushSink);\n constructor(buffer?: Uint8Array, offset = 0, flush?: FlushSink) {\n this.kernel = getKernel();\n if (buffer === undefined) {\n this.buf = new Uint8Array(DEFAULT_CAPACITY);\n this.start = 0;\n this.pos = 0;\n this.flushSink = undefined;\n this.canGrow = true;\n } else {\n if (offset < 0 || offset > buffer.length) {\n throw argumentError(`offset ${offset} out of range`);\n }\n this.buf = buffer;\n this.start = offset;\n this.pos = offset;\n this.flushSink = flush;\n this.canGrow = false;\n }\n }\n\n /** Bytes currently held in the buffer (since construction or the last flush). */\n get bytesUsed(): number {\n return this.pos - this.start;\n }\n\n /**\n * The encoded message so far, as a view into the working buffer.\n * Meaningful for the in-memory mode; in streaming mode it is only the\n * not-yet-flushed tail. The view is valid until the next write.\n */\n bytes(): Uint8Array {\n return this.buf.subarray(this.start, this.pos);\n }\n\n /** Drain buffered bytes to the flush sink (no-op without one). */\n flush(): void {\n if (this.flushSink && this.pos > this.start) {\n this.flushSink(this.buf.subarray(this.start, this.pos));\n this.pos = this.start;\n }\n }\n\n /**\n * Install a fresh output buffer to write into, mid-stream. Intended for the\n * streaming (flush-sink) mode: call it from inside your flush callback to hand\n * the encoder a new buffer for the next batch of bytes, so encoding continues\n * without interruption. `offset` reserves space at the front of the new\n * buffer. Any not-yet-flushed bytes in the old buffer are dropped, so\n * {@link flush} first (the flush callback fires before you swap).\n */\n setBuffer(buffer: Uint8Array, offset = 0): void {\n if (offset < 0 || offset > buffer.length) {\n throw argumentError(`offset ${offset} out of range`);\n }\n this.buf = buffer;\n this.start = offset;\n this.pos = offset;\n }\n\n /**\n * Rewind the encoder to empty, reusing the existing buffer. Lets a caller pool\n * one OStream across many messages instead of allocating a fresh buffer per\n * encode. Any view previously returned by {@link bytes} is invalidated.\n */\n reset(): void {\n this.pos = this.start;\n this.depth = 0;\n }\n\n // --- scalars ------------------------------------------------------------\n\n /** Write an unsigned integer field. */\n writeUnsigned(id: number, value: number | bigint): void {\n // Fast path: a small non-negative integer never touches bigint.\n if (typeof value === \"number\" && value >= 0 && value <= Number.MAX_SAFE_INTEGER && Number.isInteger(value)) {\n this.header(id, WireType.Unsigned);\n this.putVarintNum(value);\n return;\n }\n const v = toBigInt(value);\n if (!inU64(v)) throw argumentError(`unsigned value ${v} out of 64-bit range`);\n this.header(id, WireType.Unsigned);\n this.putVarint(v);\n }\n\n /** Write a signed integer field (zig-zag encoded). */\n writeSigned(id: number, value: number | bigint): void {\n // Fast path: a small-magnitude integer zig-zags within number precision.\n if (typeof value === \"number\" && value >= -SIGNED_FAST_MAX && value <= SIGNED_FAST_MAX && Number.isInteger(value)) {\n this.header(id, WireType.Signed);\n this.putVarintNum(value >= 0 ? value * 2 : -value * 2 - 1);\n return;\n }\n const v = toBigInt(value);\n if (!inI64(v)) throw argumentError(`signed value ${v} out of 64-bit range`);\n this.header(id, WireType.Signed);\n this.putVarint(zigzagEncode(v));\n }\n\n /** Write a boolean field (encoded as the unsigned value 0 or 1). */\n writeBoolean(id: number, value: boolean): void {\n this.header(id, WireType.Unsigned);\n this.putVarintNum(value ? 1 : 0);\n }\n\n /** Write an IEEE-754 32-bit float field. */\n writeFp32(id: number, value: number): void {\n this.fixlenHead(id, 4, FixlenSubtype.Fp32);\n this.ensure(4);\n this.pos = packFp32(this.buf, this.pos, value);\n }\n\n /** Write an IEEE-754 64-bit double field. */\n writeFp64(id: number, value: number): void {\n this.fixlenHead(id, 8, FixlenSubtype.Fp64);\n this.ensure(8);\n this.pos = packFp64(this.buf, this.pos, value);\n }\n\n /** Write a UTF-8 string field. */\n writeString(id: number, text: string): void {\n // Fast path (in-memory, growable buffer): scan the UTF-8 byte length, write\n // the fixlen header, then encode the characters straight into the output\n // buffer. This skips `TextEncoder.encode`'s per-call setup + throwaway array\n // + second copy — the encoder's dominant cost on string-heavy messages.\n if (this.canGrow) {\n const byteLen = utf8Length(text);\n if (byteLen > FIXLEN_MAX) {\n throw argumentError(`fixlen length ${byteLen} exceeds ${FIXLEN_MAX}`);\n }\n this.fixlenHead(id, byteLen, FixlenSubtype.String);\n this.ensure(byteLen);\n this.pos = utf8Write(text, this.buf, this.pos);\n return;\n }\n // Streaming path: the payload may outgrow a fixed caller buffer, so keep the\n // chunk-draining `writeRaw` route (needs the bytes materialised up front).\n this.writeFixlen(id, encodeUtf8(text), FixlenSubtype.String);\n }\n\n /** Write a blob (arbitrary bytes) field. */\n writeBlob(id: number, data: Uint8Array): void {\n this.writeFixlen(id, data, FixlenSubtype.Blob);\n }\n\n /** Write a fixed-length field of the given subtype from raw bytes. */\n writeFixlen(id: number, data: Uint8Array, subtype: FixlenSubtype): void {\n if (data.length > FIXLEN_MAX) {\n throw argumentError(`fixlen length ${data.length} exceeds ${FIXLEN_MAX}`);\n }\n this.fixlenHead(id, data.length, subtype);\n this.writeRaw(data);\n }\n\n // --- arrays -------------------------------------------------------------\n\n /** Write an array of unsigned integers (each a varint). */\n writeUnsignedArray(id: number, values: ArrayLike<number | bigint>): void {\n this.arrayHead(id, WireType.ArrayUnsigned, values.length);\n if (this.canGrow) {\n this.ensure(values.length * VARINT_MAX_BYTES);\n this.pos = this.kernel.encodeUnsignedVarints(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) {\n const v = toBigInt(values[i]!);\n if (!inU64(v)) throw argumentError(`unsigned value ${v} out of range`);\n this.ensure(VARINT_MAX_BYTES);\n this.pos = encodeVarint(v, this.buf, this.pos);\n }\n }\n }\n\n /** Write an array of signed integers (each zig-zag + varint). */\n writeSignedArray(id: number, values: ArrayLike<number | bigint>): void {\n this.arrayHead(id, WireType.ArraySigned, values.length);\n if (this.canGrow) {\n this.ensure(values.length * VARINT_MAX_BYTES);\n this.pos = this.kernel.encodeSignedVarints(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) {\n const v = toBigInt(values[i]!);\n if (!inI64(v)) throw argumentError(`signed value ${v} out of range`);\n this.ensure(VARINT_MAX_BYTES);\n this.pos = encodeVarint(zigzagEncode(v), this.buf, this.pos);\n }\n }\n }\n\n /**\n * Write an unsigned 64-bit array from {@link Long}[] — the `bigint`-free path.\n * Produces the identical wire to {@link writeUnsignedArray}; reads each Long's\n * 32-bit halves directly, so no `bigint` is created per element.\n */\n writeUnsignedArrayLong(id: number, values: readonly Long[]): void {\n this.arrayHead(id, WireType.ArrayUnsigned, values.length);\n this.ensure(values.length * VARINT_MAX_BYTES);\n let pos = this.pos;\n const buf = this.buf;\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n pos = encodeVarintLoHi(v.low, v.high, buf, pos);\n }\n this.pos = pos;\n }\n\n /**\n * Write a signed 64-bit array (zig-zag) from {@link Long}[] — the `bigint`-free\n * path. Zig-zag `(n << 1) ^ (n >> 63)` is computed on the lo/hi pair.\n */\n writeSignedArrayLong(id: number, values: readonly Long[]): void {\n this.arrayHead(id, WireType.ArraySigned, values.length);\n this.ensure(values.length * VARINT_MAX_BYTES);\n let pos = this.pos;\n const buf = this.buf;\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n const lo = v.low;\n const hi = v.high;\n const sgn = (-(hi >>> 31)) >>> 0; // all ones when negative, else zero\n const zLo = (((lo << 1) >>> 0) ^ sgn) >>> 0;\n const zHi = ((((hi << 1) | (lo >>> 31)) >>> 0) ^ sgn) >>> 0;\n pos = encodeVarintLoHi(zLo, zHi, buf, pos);\n }\n this.pos = pos;\n }\n\n /** Write an array of IEEE-754 32-bit floats. */\n writeFp32Array(id: number, values: ArrayLike<number>): void {\n this.arrayHead(id, WireType.ArrayFixlen, values.length);\n // A fixlen array always carries its fixlen_word — even when empty (§4.8) —\n // so an empty fp32 array stays distinct from an empty fp64 one. The payload\n // loop below simply runs zero times: the field is [ header ][ count = 0 ]\n // [ fixlen_word ] with no elements.\n this.putVarintNum(4 * 8 + FixlenSubtype.Fp32);\n if (this.canGrow) {\n this.ensure(values.length * 4);\n this.pos = this.kernel.packFp32Array(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) {\n this.ensure(4);\n this.pos = packFp32(this.buf, this.pos, values[i]!);\n }\n }\n }\n\n /** Write an array of IEEE-754 64-bit doubles. */\n writeFp64Array(id: number, values: ArrayLike<number>): void {\n this.arrayHead(id, WireType.ArrayFixlen, values.length);\n // A fixlen array always carries its fixlen_word — even when empty (§4.8) —\n // so an empty fp64 array stays distinct from an empty fp32 one. The payload\n // loop below simply runs zero times: the field is [ header ][ count = 0 ]\n // [ fixlen_word ] with no elements.\n this.putVarintNum(8 * 8 + FixlenSubtype.Fp64);\n if (this.canGrow) {\n this.ensure(values.length * 8);\n this.pos = this.kernel.packFp64Array(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) {\n this.ensure(8);\n this.pos = packFp64(this.buf, this.pos, values[i]!);\n }\n }\n }\n\n // --- sequences ----------------------------------------------------------\n\n /** Open a nested sequence (a fresh id scope). */\n writeSequenceBegin(id: number): void {\n // §4.9/§6.2: refuse to open more than MAX_DEPTH nested sequences.\n if (this.depth >= MAX_DEPTH) {\n throw usageError(`nesting exceeds MAX_DEPTH (${MAX_DEPTH})`);\n }\n this.header(id, WireType.SequenceStart);\n this.depth++;\n }\n\n /** Close the current sequence. */\n writeSequenceEnd(): void {\n if (this.depth <= 0) throw usageError(\"sequence end without matching begin\");\n this.ensure(1);\n this.buf[this.pos++] = WireType.SequenceEnd; // id 0, type 7 -> byte 0x07\n this.depth--;\n }\n\n // --- internals ----------------------------------------------------------\n\n /** Ensure exactly `value`'s varint size, then write it (bigint path). */\n private putVarint(value: bigint): void {\n this.ensure(varintSize(value));\n this.pos = encodeVarint(value, this.buf, this.pos);\n }\n\n /** Ensure exactly `value`'s varint size, then write it (number fast path). */\n private putVarintNum(value: number): void {\n this.ensure(varintSizeNum(value));\n this.pos = encodeVarintNum(value, this.buf, this.pos);\n }\n\n private header(id: number, type: WireType): void {\n if (id < 0 || id > ID_MAX || !Number.isInteger(id)) {\n throw argumentError(`field id ${id} out of range 0..${ID_MAX}`);\n }\n // (id << 3) | type as a number: id ≤ 2^31-1, so the word stays ≤ 2^34.\n this.putVarintNum(id * 8 + type);\n }\n\n private fixlenHead(id: number, length: number, subtype: FixlenSubtype): void {\n this.header(id, WireType.Fixlen);\n this.putVarintNum(length * 8 + subtype);\n }\n\n private arrayHead(id: number, type: WireType, count: number): void {\n // §4.7/§4.8: element_count range is 0..ARRAY_MAX; a zero-count array is a\n // valid, fully-specified empty array on the wire.\n if (count < 0 || count > ARRAY_MAX) {\n throw argumentError(`array count ${count} out of range 0..${ARRAY_MAX}`);\n }\n this.header(id, type);\n this.putVarintNum(count);\n }\n\n /** Copy `data` out, flushing/growing as needed (large payloads stay chunked). */\n private writeRaw(data: Uint8Array): void {\n let off = 0;\n while (off < data.length) {\n const room = this.ensureSome(data.length - off);\n this.buf.set(data.subarray(off, off + room), this.pos);\n this.pos += room;\n off += room;\n }\n }\n\n /** Ensure `n` contiguous bytes are free at `pos`; returns `pos` for chaining. */\n private ensure(n: number): number {\n if (this.buf.length - this.pos >= n) return this.pos;\n this.flush();\n if (this.buf.length - this.pos >= n) return this.pos;\n if (this.canGrow) {\n this.growTo(this.pos + n);\n return this.pos;\n }\n throw bufferFullError(\n `output buffer full: need ${n} more bytes, have ${this.buf.length - this.pos}`,\n );\n }\n\n /** Ensure *some* room (up to `want`); returns how many bytes are available. */\n private ensureSome(want: number): number {\n let room = this.buf.length - this.pos;\n if (room === 0) {\n this.flush();\n room = this.buf.length - this.pos;\n if (room === 0) {\n if (this.canGrow) {\n this.growTo(this.pos + want);\n room = this.buf.length - this.pos;\n } else {\n throw bufferFullError(\"output buffer full\");\n }\n }\n }\n return Math.min(room, want);\n }\n\n private growTo(needed: number): void {\n let cap = this.buf.length * 2;\n if (cap < needed) cap = needed;\n const next = new Uint8Array(cap);\n next.set(this.buf.subarray(0, this.pos));\n this.buf = next;\n }\n}\n","/**\n * The contiguous-buffer fast path: \"advance a pointer over a whole message\".\n *\n * When the entire message is already in one {@link Uint8Array} (the common\n * non-streaming case) there is no need for the resumable, byte-at-a-time state\n * machine in {@link \"./state\"}. This decoder keeps a single read cursor and\n * walks it straight to the end, decoding each field inline — the technique\n * Protocol Buffers uses for its fast path.\n *\n * Two things make it much faster than the streaming decoder:\n *\n * - **No `bigint` in the varint hot loop.** Each varint is accumulated into two\n * 32-bit JavaScript *numbers* (`lo` / `hi`); a `bigint` is materialised only\n * once per 64-bit *value* (and never at all for ids, lengths and counts,\n * which stay numbers). The streaming reader, by contrast, does a `bigint`\n * shift-and-or for every single byte.\n * - **No per-byte state reload.** The field type is dispatched once and the\n * whole field is consumed in place, instead of re-entering a `switch` on a\n * saved state enum for each byte.\n *\n * String / blob payloads are handed to the visitor as a single zero-copy\n * `subarray` view (one call, offset 0) rather than streamed in pieces. The\n * decoder validates exactly what the streaming path does and reports the same\n * three-valued outcome (MESSAGE_SPEC §7): it throws a {@link SofabError} with\n * code `INVALID_MSG` on malformed input, and `INCOMPLETE` when the buffer ends\n * inside a field — a truncated varint / payload / array, or an unclosed\n * sequence detected at the end of the buffer.\n */\n\nimport {\n ARRAY_MAX,\n ArrayKind,\n FIXLEN_MAX,\n FixlenSubtype,\n ID_MAX,\n MAX_DEPTH,\n WireType,\n} from \"../constants.js\";\nimport {\n incompleteError,\n invalidMsgError,\n limitExceededError,\n} from \"../errors.js\";\nimport { zigzagDecode } from \"../varint/zigzag.js\";\nimport type { DecodeLimits } from \"./limits.js\";\nimport type { Visitor } from \"./istream.js\";\n\nconst TWO32 = 0x1_0000_0000; // 2^32, for combining the 32-bit halves\n\n/** Decode a complete message held in one contiguous buffer. */\nexport function decodeContiguous(\n buf: Uint8Array,\n root: Visitor,\n limits?: DecodeLimits,\n): void {\n new FastDecoder(buf, limits).run(root);\n}\n\nclass FastDecoder {\n private readonly buf: Uint8Array;\n private readonly view: DataView;\n private readonly n: number;\n private p = 0;\n\n // Last varint, as two unsigned 32-bit halves (see readVarint).\n private lo = 0;\n private hi = 0;\n\n // Opt-in decode limits (corelib-ts#38); an unset limit is Infinity (no cap).\n private readonly maxArrayCount: number;\n private readonly maxStringLen: number;\n private readonly maxBlobLen: number;\n\n constructor(buf: Uint8Array, limits?: DecodeLimits) {\n this.buf = buf;\n this.n = buf.length;\n this.view = new DataView(buf.buffer, buf.byteOffset, buf.length);\n this.maxArrayCount = limits?.maxArrayCount ?? Infinity;\n this.maxStringLen = limits?.maxStringLen ?? Infinity;\n this.maxBlobLen = limits?.maxBlobLen ?? Infinity;\n }\n\n run(root: Visitor): void {\n const stack: Visitor[] = [root];\n let top = root;\n\n while (this.p < this.n) {\n this.readVarint();\n const type = this.lo & 7;\n\n if (type === WireType.SequenceEnd) {\n if (stack.length <= 1) throw invalidMsgError(\"unbalanced sequence end\");\n top.sequenceEnd?.();\n stack.pop();\n top = stack[stack.length - 1]!;\n continue;\n }\n\n const id = this.upper();\n if (id > ID_MAX) throw invalidMsgError(`field id ${id} out of range`);\n\n switch (type) {\n case WireType.Unsigned: {\n this.readVarint();\n top.unsigned?.(id, this.unsignedValue());\n break;\n }\n\n case WireType.Signed: {\n this.readVarint();\n top.signed?.(id, this.signedValue());\n break;\n }\n\n case WireType.Fixlen: {\n this.readVarint();\n const sub = this.lo & 7;\n const len = this.upper();\n if (sub > FixlenSubtype.Blob) throw invalidMsgError(`invalid fixlen subtype ${sub}`);\n if (len > FIXLEN_MAX) throw invalidMsgError(\"fixlen length out of range\");\n if (sub === FixlenSubtype.String && len > this.maxStringLen) {\n throw limitExceededError(`string length ${len} exceeds maxStringLen ${this.maxStringLen}`);\n }\n if (sub === FixlenSubtype.Blob && len > this.maxBlobLen) {\n throw limitExceededError(`blob length ${len} exceeds maxBlobLen ${this.maxBlobLen}`);\n }\n if (sub === FixlenSubtype.Fp32 || sub === FixlenSubtype.Fp64) {\n const want = sub === FixlenSubtype.Fp32 ? 4 : 8;\n if (len !== want) throw invalidMsgError(\"fixlen float length mismatch\");\n const value =\n sub === FixlenSubtype.Fp32 ? this.readFp32() : this.readFp64();\n if (sub === FixlenSubtype.Fp32) top.fp32?.(id, value);\n else top.fp64?.(id, value);\n } else {\n const chunk = this.take(len);\n if (sub === FixlenSubtype.String) top.string?.(id, len, 0, chunk);\n else top.blob?.(id, len, 0, chunk);\n }\n break;\n }\n\n case WireType.ArrayUnsigned: {\n const count = this.arrayCount();\n top.arrayBegin?.(id, ArrayKind.Unsigned, count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n top.arrayUnsigned?.(id, i, this.unsignedValue());\n }\n top.arrayEnd?.(id);\n break;\n }\n\n case WireType.ArraySigned: {\n const count = this.arrayCount();\n top.arrayBegin?.(id, ArrayKind.Signed, count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n top.arraySigned?.(id, i, this.signedValue());\n }\n top.arrayEnd?.(id);\n break;\n }\n\n case WireType.ArrayFixlen: {\n const count = this.arrayCount();\n // §4.8: a fixlen array always carries its element-length word — even\n // when empty — so the true element kind (fp32 vs fp64) stays known.\n // When count == 0 the payload loops below simply run zero times.\n this.readVarint();\n const sub = this.lo & 7;\n const size = this.upper();\n let kind: ArrayKind;\n if (sub === FixlenSubtype.Fp32 && size === 4) kind = ArrayKind.Fp32;\n else if (sub === FixlenSubtype.Fp64 && size === 8) kind = ArrayKind.Fp64;\n else throw invalidMsgError(\"invalid fixlen array element type\");\n top.arrayBegin?.(id, kind, count);\n // Read each element into a local *before* the optional call: with an\n // absent handler, `v?.m(read())` would short-circuit and never advance.\n if (kind === ArrayKind.Fp32) {\n for (let i = 0; i < count; i++) {\n const value = this.readFp32();\n top.arrayFp32?.(id, i, value);\n }\n } else {\n for (let i = 0; i < count; i++) {\n const value = this.readFp64();\n top.arrayFp64?.(id, i, value);\n }\n }\n top.arrayEnd?.(id);\n break;\n }\n\n case WireType.SequenceStart: {\n // §4.9/§6.2: reject nesting deeper than MAX_DEPTH. The stack holds the\n // root plus one entry per open sequence, so depth is stack.length - 1.\n if (stack.length - 1 >= MAX_DEPTH) {\n throw invalidMsgError(`nesting exceeds MAX_DEPTH (${MAX_DEPTH})`);\n }\n const child = top.sequenceBegin?.(id);\n top = child ?? top;\n stack.push(top);\n break;\n }\n\n default:\n throw invalidMsgError(`invalid wire type ${type}`);\n }\n }\n\n if (stack.length > 1) throw incompleteError(\"truncated message: unbalanced sequence\");\n }\n\n // --- field helpers ------------------------------------------------------\n\n /** Read and validate an array count word (0..ARRAY_MAX; §4.7/§4.8). */\n private arrayCount(): number {\n this.readVarint();\n const count = this.num();\n if (count > ARRAY_MAX) throw invalidMsgError(\"array count out of range\");\n if (count > this.maxArrayCount) {\n throw limitExceededError(`array count ${count} exceeds maxArrayCount ${this.maxArrayCount}`);\n }\n return count;\n }\n\n /** Hand back a zero-copy view of the next `len` bytes, advancing the cursor. */\n private take(len: number): Uint8Array {\n const start = this.p;\n const end = start + len;\n if (end > this.n) throw incompleteError(\"truncated fixlen payload\");\n this.p = end;\n return this.buf.subarray(start, end);\n }\n\n private readFp32(): number {\n const p = this.p;\n if (p + 4 > this.n) throw incompleteError(\"truncated fp32\");\n this.p = p + 4;\n return this.view.getFloat32(p, true);\n }\n\n private readFp64(): number {\n const p = this.p;\n if (p + 8 > this.n) throw incompleteError(\"truncated fp64\");\n this.p = p + 8;\n return this.view.getFloat64(p, true);\n }\n\n // --- varint reading -----------------------------------------------------\n\n /** The last varint's full value as a `bigint` (64-bit fidelity). */\n private big(): bigint {\n return this.hi === 0\n ? BigInt(this.lo >>> 0)\n : (BigInt(this.hi >>> 0) << 32n) | BigInt(this.lo >>> 0);\n }\n\n /**\n * The last varint as an unsigned value, number-first: a `number` when it fits\n * exactly (`≤ 2^53-1` — all ids, u8..u32 and small u64s), a `bigint` only\n * beyond that. Skips the per-value bigint allocation on the common path.\n */\n private unsignedValue(): number | bigint {\n const hi = this.hi >>> 0; // unsigned: hi's bit 31 must not read as negative\n return hi <= 0x1fffff ? hi * TWO32 + (this.lo >>> 0) : this.big();\n }\n\n /** The last zig-zag varint as a signed value, number-first (see {@link unsignedValue}). */\n private signedValue(): number | bigint {\n const hi = this.hi >>> 0;\n if (hi <= 0x1fffff) {\n const r = hi * TWO32 + (this.lo >>> 0); // raw zig-zag, ≤ 2^53-1\n return r % 2 === 0 ? r / 2 : -(r + 1) / 2;\n }\n return zigzagDecode(this.big());\n }\n\n /** The last varint's value as a JS number — exact for ids/lengths/counts. */\n private num(): number {\n return this.hi * TWO32 + (this.lo >>> 0);\n }\n\n /** The last varint with its low 3 tag bits stripped (`value >> 3`). */\n private upper(): number {\n // value >> 3 without losing the high bits: drop 3 bits, carry hi's low 3.\n return (this.hi >>> 0) * (TWO32 / 8) + (this.lo >>> 3);\n }\n\n /**\n * Decode one LEB128 varint at the cursor into {@link lo} / {@link hi} (each an\n * unsigned 32-bit half), advancing {@link p}. Throws on truncation or a value\n * spilling past 64 bits (>10 bytes). Unrolled, number-only — no `bigint`.\n */\n private readVarint(): void {\n const buf = this.buf;\n const n = this.n;\n let p = this.p;\n let b: number;\n let lo: number;\n let hi = 0;\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo = b & 0x7f;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 7;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 14;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 21;\n if (b < 0x80) return this.set(lo, 0, p);\n\n // 5th byte straddles the 32-bit boundary: 4 bits to lo, 3 bits to hi.\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x0f) << 28;\n hi = (b >> 4) & 0x07;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 3;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 10;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 17;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 24;\n if (b < 0x80) return this.set(lo, hi, p);\n\n // 10th byte: only bit 63 (1 payload bit) remains below 64; any higher\n // payload bit, or a continuation into an 11th byte, is a >64-bit overflow.\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n if (((b & 0x7f) >> 1) !== 0) throw invalidMsgError(\"varint overflow\");\n hi |= (b & 0x7f) << 31;\n if (b < 0x80) return this.set(lo, hi, p);\n\n throw invalidMsgError(\"varint overflow\");\n }\n\n private set(lo: number, hi: number, p: number): void {\n this.lo = lo;\n this.hi = hi;\n this.p = p;\n }\n}\n","/**\n * The resumable decode state machine.\n *\n * `DecoderState` consumes input one byte at a time and never needs to buffer\n * more than a single varint (≤10 bytes) or one fixlen element (≤8 bytes), so it\n * can be fed arbitrarily small chunks: every multi-byte construct saves its\n * progress in instance fields and continues on the next {@link push}. Large\n * string / blob payloads are streamed straight to the visitor in pieces, and\n * array elements are emitted as they arrive — nothing is materialised whole.\n */\n\nimport {\n ARRAY_MAX,\n ArrayKind,\n DecodeStatus,\n FIXLEN_MAX,\n FixlenSubtype,\n ID_MAX,\n MAX_DEPTH,\n VARINT_MAX_BYTES,\n WireType,\n} from \"../constants.js\";\nimport { invalidMsgError, limitExceededError } from \"../errors.js\";\nimport { unpackFp32, unpackFp64 } from \"../varint/num64.js\";\nimport { zigzagDecode } from \"../varint/zigzag.js\";\nimport type { DecodeLimits } from \"./limits.js\";\nimport type { Visitor } from \"./istream.js\";\n\nconst enum S {\n Header,\n ScalarU,\n ScalarS,\n FixlenLen,\n FixlenFp,\n FixlenBytes,\n ArrayCount,\n ArrayUElem,\n ArraySElem,\n ArrayElemLen,\n ArrayFp,\n}\n\nconst TWO32 = 0x1_0000_0000; // 2^32, for combining the 32-bit halves\n\nexport class DecoderState {\n private state = S.Header;\n private stack: Visitor[] = [];\n\n // current field\n private id = 0;\n\n // Resumable varint accumulator, as two unsigned 32-bit halves (vLo / vHi)\n // plus the byte count so far. Number-only: a `bigint` is built once, at the\n // end, and only for full 64-bit *values* (not ids, lengths or counts).\n private vLo = 0;\n private vHi = 0;\n private vBytes = 0;\n private vComplete = false;\n\n // fixlen / fp scratch\n private scratch = new Uint8Array(8);\n private need = 0;\n private have = 0;\n\n // fixlen string/blob streaming\n private fixSub: FixlenSubtype = FixlenSubtype.String;\n private fixLen = 0;\n private fixOff = 0;\n\n // array\n private arrKind: ArrayKind = ArrayKind.Unsigned;\n private arrIsFixlen = false;\n private arrCount = 0;\n private arrIndex = 0;\n\n // Opt-in decode limits (corelib-ts#38); an unset limit is Infinity (no cap).\n // Enforced at the count / length header, before any payload is streamed to\n // the visitor, so an over-limit string/blob is never fed chunk-by-chunk.\n private readonly maxArrayCount: number;\n private readonly maxStringLen: number;\n private readonly maxBlobLen: number;\n\n constructor(limits?: DecodeLimits) {\n this.maxArrayCount = limits?.maxArrayCount ?? Infinity;\n this.maxStringLen = limits?.maxStringLen ?? Infinity;\n this.maxBlobLen = limits?.maxBlobLen ?? Infinity;\n }\n\n /** Feed `input` to the machine, dispatching to `root` and its sub-visitors. */\n push(input: Uint8Array, root: Visitor): void {\n if (this.stack.length === 0) this.stack.push(root);\n let i = 0;\n const n = input.length;\n\n while (i < n) {\n switch (this.state) {\n case S.Header: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const type = this.vTag();\n if (type === WireType.SequenceEnd) {\n this.resetVarint();\n this.endSequence();\n break;\n }\n const id = this.vUpper();\n this.resetVarint();\n if (id > ID_MAX) throw invalidMsgError(`field id ${id} out of range`);\n this.id = id;\n this.dispatch(type);\n break;\n }\n\n case S.ScalarU: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const value = this.vUnsigned();\n this.resetVarint();\n this.top().unsigned?.(this.id, value);\n this.state = S.Header;\n break;\n }\n\n case S.ScalarS: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const value = this.vSigned();\n this.resetVarint();\n this.top().signed?.(this.id, value);\n this.state = S.Header;\n break;\n }\n\n case S.FixlenLen: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const sub = this.vTag();\n const len = this.vUpper();\n this.resetVarint();\n if (sub > FixlenSubtype.Blob) throw invalidMsgError(`invalid fixlen subtype ${sub}`);\n if (len > FIXLEN_MAX) throw invalidMsgError(\"fixlen length out of range\");\n if (sub === FixlenSubtype.String && len > this.maxStringLen) {\n throw limitExceededError(`string length ${len} exceeds maxStringLen ${this.maxStringLen}`);\n }\n if (sub === FixlenSubtype.Blob && len > this.maxBlobLen) {\n throw limitExceededError(`blob length ${len} exceeds maxBlobLen ${this.maxBlobLen}`);\n }\n this.fixSub = sub as FixlenSubtype;\n this.fixLen = len;\n this.fixOff = 0;\n if (sub === FixlenSubtype.Fp32 || sub === FixlenSubtype.Fp64) {\n const want = sub === FixlenSubtype.Fp32 ? 4 : 8;\n if (this.fixLen !== want) throw invalidMsgError(\"fixlen float length mismatch\");\n this.need = want;\n this.have = 0;\n this.state = S.FixlenFp;\n } else {\n // string / blob: emit empties immediately, otherwise stream below\n if (this.fixLen === 0) {\n this.emitBytes(input.subarray(0, 0));\n this.state = S.Header;\n } else {\n this.state = S.FixlenBytes;\n }\n }\n break;\n }\n\n case S.FixlenFp: {\n i = this.fpStep(input, i);\n if (this.have < this.need) return;\n const value =\n this.fixSub === FixlenSubtype.Fp32\n ? unpackFp32(this.scratch, 0)\n : unpackFp64(this.scratch, 0);\n if (this.fixSub === FixlenSubtype.Fp32) this.top().fp32?.(this.id, value);\n else this.top().fp64?.(this.id, value);\n this.state = S.Header;\n break;\n }\n\n case S.FixlenBytes: {\n const take = Math.min(n - i, this.fixLen - this.fixOff);\n this.emitBytes(input.subarray(i, i + take));\n i += take;\n this.fixOff += take;\n if (this.fixOff === this.fixLen) this.state = S.Header;\n break;\n }\n\n case S.ArrayCount: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const count = this.vNum();\n this.resetVarint();\n if (count > ARRAY_MAX) throw invalidMsgError(\"array count out of range\");\n if (count > this.maxArrayCount) {\n throw limitExceededError(`array count ${count} exceeds maxArrayCount ${this.maxArrayCount}`);\n }\n this.arrCount = count;\n this.arrIndex = 0;\n if (this.arrIsFixlen) {\n // §4.8: a fixlen array always carries its element-length word — even\n // when empty — so the true element kind (fp32 vs fp64) stays known.\n // The element kind is only knowable once that word arrives, so defer\n // arrayBegin until then; a zero-count array reads the word then ends\n // with no payload (handled in S.ArrayElemLen).\n this.state = S.ArrayElemLen;\n } else if (count === 0) {\n // §4.7: a zero-count integer array is empty — no payload follows and\n // no element-length word exists (element width is API-only).\n this.top().arrayBegin?.(this.id, this.arrKind, 0);\n this.top().arrayEnd?.(this.id);\n this.state = S.Header;\n } else {\n this.top().arrayBegin?.(this.id, this.arrKind, this.arrCount);\n this.state = this.arrKind === ArrayKind.Unsigned ? S.ArrayUElem : S.ArraySElem;\n }\n break;\n }\n\n case S.ArrayUElem: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const value = this.vUnsigned();\n this.resetVarint();\n this.top().arrayUnsigned?.(this.id, this.arrIndex, value);\n this.advanceArray();\n break;\n }\n\n case S.ArraySElem: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const value = this.vSigned();\n this.resetVarint();\n this.top().arraySigned?.(this.id, this.arrIndex, value);\n this.advanceArray();\n break;\n }\n\n case S.ArrayElemLen: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const sub = this.vTag();\n const size = this.vUpper();\n this.resetVarint();\n if (sub === FixlenSubtype.Fp32 && size === 4) {\n this.arrKind = ArrayKind.Fp32;\n this.need = 4;\n } else if (sub === FixlenSubtype.Fp64 && size === 8) {\n this.arrKind = ArrayKind.Fp64;\n this.need = 8;\n } else {\n throw invalidMsgError(\"invalid fixlen array element type\");\n }\n this.top().arrayBegin?.(this.id, this.arrKind, this.arrCount);\n if (this.arrCount === 0) {\n // §4.8: an empty fixlen array is [ header ][ count = 0 ][ fixlen_word ]\n // with no payload — the word above yielded the true element kind.\n this.top().arrayEnd?.(this.id);\n this.state = S.Header;\n } else {\n this.have = 0;\n this.state = S.ArrayFp;\n }\n break;\n }\n\n case S.ArrayFp: {\n i = this.fpStep(input, i);\n if (this.have < this.need) return;\n const value =\n this.arrKind === ArrayKind.Fp32\n ? unpackFp32(this.scratch, 0)\n : unpackFp64(this.scratch, 0);\n if (this.arrKind === ArrayKind.Fp32) this.top().arrayFp32?.(this.id, this.arrIndex, value);\n else this.top().arrayFp64?.(this.id, this.arrIndex, value);\n this.have = 0;\n this.advanceArray();\n break;\n }\n }\n }\n }\n\n /**\n * Report the terminal decode outcome (MESSAGE_SPEC §7) *without* promoting it\n * to an error. Returns {@link DecodeStatus.Complete} when the stream ended\n * exactly at a field boundary, or {@link DecodeStatus.Incomplete} when it\n * ended inside a field (a partial varint, an unfinished payload / array, or a\n * still-open nested sequence). This is a pure accessor — the finish-less spec\n * has no finalize step, and a trailing `Incomplete` is a truncation the caller\n * decides how to treat, not an error this machine raises. A genuinely\n * malformed message has already thrown from {@link push}.\n */\n finish(): DecodeStatus {\n const atBoundary =\n this.state === S.Header && this.vBytes === 0 && this.stack.length <= 1;\n return atBoundary ? DecodeStatus.Complete : DecodeStatus.Incomplete;\n }\n\n // --- helpers ------------------------------------------------------------\n\n private dispatch(type: number): void {\n switch (type) {\n case WireType.Unsigned:\n this.state = S.ScalarU;\n break;\n case WireType.Signed:\n this.state = S.ScalarS;\n break;\n case WireType.Fixlen:\n this.state = S.FixlenLen;\n break;\n case WireType.ArrayUnsigned:\n this.arrKind = ArrayKind.Unsigned;\n this.arrIsFixlen = false;\n this.state = S.ArrayCount;\n break;\n case WireType.ArraySigned:\n this.arrKind = ArrayKind.Signed;\n this.arrIsFixlen = false;\n this.state = S.ArrayCount;\n break;\n case WireType.ArrayFixlen:\n this.arrIsFixlen = true; // element kind resolved at the element-length word\n this.state = S.ArrayCount;\n break;\n case WireType.SequenceStart: {\n // §4.9/§6.2: reject nesting deeper than MAX_DEPTH. The stack always\n // holds the root visitor plus one entry per open sequence, so the\n // current depth is stack.length - 1.\n if (this.stack.length - 1 >= MAX_DEPTH) {\n throw invalidMsgError(`nesting exceeds MAX_DEPTH (${MAX_DEPTH})`);\n }\n const child = this.top().sequenceBegin?.(this.id);\n this.stack.push(child ?? this.top());\n this.state = S.Header;\n break;\n }\n default:\n throw invalidMsgError(`invalid wire type ${type}`);\n }\n }\n\n private endSequence(): void {\n if (this.stack.length <= 1) throw invalidMsgError(\"unbalanced sequence end\");\n this.top().sequenceEnd?.();\n this.stack.pop();\n this.state = S.Header;\n }\n\n private advanceArray(): void {\n this.arrIndex++;\n if (this.arrIndex === this.arrCount) {\n this.top().arrayEnd?.(this.id);\n this.state = S.Header;\n }\n }\n\n private emitBytes(chunk: Uint8Array): void {\n const v = this.top();\n if (this.fixSub === FixlenSubtype.String) v.string?.(this.id, this.fixLen, this.fixOff, chunk);\n else v.blob?.(this.id, this.fixLen, this.fixOff, chunk);\n }\n\n private top(): Visitor {\n return this.stack[this.stack.length - 1]!;\n }\n\n /**\n * Consume varint bytes from `input` at `i` into the {@link vLo} / {@link vHi}\n * accumulator, resuming across chunk boundaries; sets {@link vComplete} when a\n * terminator byte arrives. Number-only — no per-byte `bigint`.\n */\n private varintStep(input: Uint8Array, i: number): number {\n let lo = this.vLo;\n let hi = this.vHi;\n let k = this.vBytes;\n const n = input.length;\n while (i < n) {\n if (k >= VARINT_MAX_BYTES) throw invalidMsgError(\"varint overflow\");\n const b = input[i++]!;\n if (k < 4) lo |= (b & 0x7f) << (7 * k);\n else if (k === 4) {\n lo |= (b & 0x0f) << 28;\n hi |= (b >> 4) & 0x07;\n } else {\n // 10th byte (k === 9) has only bit 63 below 64; any higher payload\n // bit would spill past bit 63 and is a >64-bit overflow.\n if (k === 9 && ((b & 0x7f) >> 1) !== 0) throw invalidMsgError(\"varint overflow\");\n hi |= (b & 0x7f) << (7 * k - 32);\n }\n k++;\n if ((b & 0x80) === 0) {\n this.vLo = lo;\n this.vHi = hi;\n this.vBytes = k;\n this.vComplete = true;\n return i;\n }\n }\n this.vLo = lo;\n this.vHi = hi;\n this.vBytes = k;\n this.vComplete = false;\n return i;\n }\n\n private resetVarint(): void {\n this.vLo = 0;\n this.vHi = 0;\n this.vBytes = 0;\n this.vComplete = false;\n }\n\n /** The accumulated varint as a `bigint` (full 64-bit fidelity). */\n private vBig(): bigint {\n return this.vHi === 0\n ? BigInt(this.vLo >>> 0)\n : (BigInt(this.vHi >>> 0) << 32n) | BigInt(this.vLo >>> 0);\n }\n\n /**\n * The accumulated varint as an unsigned value, number-first: a `number` when\n * it fits exactly (`≤ 2^53-1`, which covers all ids, u8..u32 and small u64s),\n * a `bigint` only beyond that. Avoids a bigint allocation on the common path.\n */\n private vUnsigned(): number | bigint {\n // Unsigned: vHi's bit 31 must not read as negative. vHi ≤ 0x1fffff (2^21-1)\n // ⇔ vHi*2^32 + lo ≤ 2^53-1.\n const hi = this.vHi >>> 0;\n return hi <= 0x1fffff ? hi * TWO32 + (this.vLo >>> 0) : this.vBig();\n }\n\n /** The accumulated zig-zag varint as a signed value, number-first (see {@link vUnsigned}). */\n private vSigned(): number | bigint {\n const hi = this.vHi >>> 0;\n if (hi <= 0x1fffff) {\n const r = hi * TWO32 + (this.vLo >>> 0); // raw zig-zag, ≤ 2^53-1\n return r % 2 === 0 ? r / 2 : -(r + 1) / 2;\n }\n return zigzagDecode(this.vBig());\n }\n\n /** The accumulated varint as a JS number — exact for ids/lengths/counts. */\n private vNum(): number {\n return this.vHi * TWO32 + (this.vLo >>> 0);\n }\n\n /** The accumulated varint's low 3 tag bits (the wire type / fixlen subtype). */\n private vTag(): number {\n return this.vLo & 7;\n }\n\n /** The accumulated varint with its low 3 tag bits stripped (`value >> 3`). */\n private vUpper(): number {\n return (this.vHi >>> 0) * (TWO32 / 8) + (this.vLo >>> 3);\n }\n\n /** Accumulate `need` raw bytes into {@link scratch}. */\n private fpStep(input: Uint8Array, i: number): number {\n while (this.have < this.need && i < input.length) {\n this.scratch[this.have++] = input[i++]!;\n }\n return i;\n }\n}\n","/**\n * The SofaBuffers decoder.\n *\n * `IStream` is a push parser: feed it bytes with {@link IStream.feed} and it\n * drives a {@link Visitor}, calling one method per decoded field. It is a\n * resumable state machine, so the chunks you feed can be any size — a whole\n * message, a network packet, or a single byte — and a field that straddles a\n * chunk boundary is picked up seamlessly on the next call.\n *\n * Nesting is hierarchical: {@link Visitor.sequenceBegin} may return a child\n * visitor, and the decoder routes the nested fields to it until the matching\n * end. Generated message classes use this directly — a class implements\n * `Visitor`, and a nested-message field returns the child instance.\n *\n * There is no finish / finalize step (MESSAGE_SPEC §7): {@link IStream.feed}\n * throws only for a *malformed* message ({@link SofabErrorCode.InvalidMsg}); a\n * message that merely ends inside a field is reported — never thrown — by\n * {@link IStream.end}, which returns {@link DecodeStatus.Incomplete} rather than\n * {@link DecodeStatus.Complete}. The caller owns end-of-input and decides\n * whether a trailing `Incomplete` is a truncation error.\n */\n\nimport type { ArrayKind, DecodeStatus } from \"../constants.js\";\nimport { decodeContiguous } from \"./fast.js\";\nimport type { DecodeLimits } from \"./limits.js\";\nimport { DecoderState } from \"./state.js\";\n\n/**\n * Receives decoded fields from an {@link IStream}. Every method is optional and\n * defaults to a no-op, so a visitor implements only the fields it cares about\n * and silently skips the rest.\n *\n * String and blob payloads arrive as one or more `chunk`s, each tagged with the\n * field's `total` length and the `offset` of the chunk within the field, so a\n * large payload never has to be held in one piece. Array elements arrive one at\n * a time between {@link Visitor.arrayBegin} and {@link Visitor.arrayEnd}.\n */\nexport interface Visitor {\n /**\n * An unsigned integer field. Number-first: `value` is a `number` when it fits\n * exactly (`≤ 2^53-1`, covering ids, u8..u32 and small u64s) and a `bigint`\n * only beyond that, so the common case avoids a per-value bigint allocation.\n */\n unsigned?(id: number, value: number | bigint): void;\n /** A signed integer field. Number-first like {@link unsigned} (`|value| ≤ 2^53-1` ⇒ `number`). */\n signed?(id: number, value: number | bigint): void;\n /** An IEEE-754 32-bit float field. */\n fp32?(id: number, value: number): void;\n /** An IEEE-754 64-bit double field. */\n fp64?(id: number, value: number): void;\n /** A chunk of a UTF-8 string field. */\n string?(id: number, total: number, offset: number, chunk: Uint8Array): void;\n /** A chunk of a blob field. */\n blob?(id: number, total: number, offset: number, chunk: Uint8Array): void;\n /** Start of an array; `count` elements of `kind` follow. */\n arrayBegin?(id: number, kind: ArrayKind, count: number): void;\n /** One unsigned array element. Number-first like {@link unsigned}. */\n arrayUnsigned?(id: number, index: number, value: number | bigint): void;\n /** One signed array element. Number-first like {@link signed}. */\n arraySigned?(id: number, index: number, value: number | bigint): void;\n /** One fp32 array element. */\n arrayFp32?(id: number, index: number, value: number): void;\n /** One fp64 array element. */\n arrayFp64?(id: number, index: number, value: number): void;\n /** End of an array. */\n arrayEnd?(id: number): void;\n /**\n * Start of a nested sequence. Return a {@link Visitor} to route the nested\n * fields to it (its {@link Visitor.sequenceEnd} fires at the matching end);\n * return nothing to keep using the current visitor.\n */\n sequenceBegin?(id: number): Visitor | void;\n /** End of the nested sequence this visitor was handling. */\n sequenceEnd?(): void;\n}\n\n/**\n * Push parser for the SofaBuffers wire format. Feed it bytes in chunks of any\n * size with {@link IStream.feed} and it drives a {@link Visitor}, one call per\n * decoded field, resuming cleanly across chunk boundaries. Call\n * {@link IStream.end} after the final chunk to read whether the message finished\n * on a field boundary. When the whole message is already in one buffer, prefer\n * the faster {@link decode}.\n */\nexport class IStream {\n private readonly state: DecoderState;\n\n /**\n * @param limits Optional opt-in decode caps ({@link DecodeLimits}). An\n * over-limit array count or string / blob length throws {@link SofabError}\n * (`LIMIT_EXCEEDED`) from {@link feed}, at the offending field's header and\n * before any of its payload is streamed to the visitor. Omit for no caps.\n */\n constructor(limits?: DecodeLimits) {\n this.state = new DecoderState(limits);\n }\n\n /**\n * Feed a chunk of bytes, dispatching decoded fields to `visitor`. Throws\n * {@link SofabError} (`INVALID_MSG`) only if the bytes are *malformed*;\n * running out of bytes mid-field is not an error — it simply suspends until\n * the next chunk (see {@link end}).\n */\n feed(chunk: Uint8Array, visitor: Visitor): void {\n this.state.push(chunk, visitor);\n }\n\n /**\n * Report whether the stream ended exactly at a field boundary. Call after the\n * final {@link feed}: returns {@link DecodeStatus.Complete} at a clean field\n * boundary, or {@link DecodeStatus.Incomplete} if the last chunk ended inside\n * a field (a partial varint, an unfinished payload / array, or a still-open\n * nested sequence).\n *\n * Per the finish-less spec (MESSAGE_SPEC §7) this is a pure accessor: it never\n * throws and never promotes an incomplete decode to an error — the caller owns\n * end-of-input and decides whether a trailing `Incomplete` is a truncation\n * error. (A *malformed* message has already thrown from {@link feed}.)\n */\n end(): DecodeStatus {\n return this.state.finish();\n }\n}\n\n/**\n * Decode a complete message held in one contiguous buffer, in a single call.\n *\n * This is the non-streaming convenience — and the fast path: with the whole\n * message in hand it advances one cursor over the buffer instead of running the\n * resumable per-byte state machine, so it is markedly faster than feeding the\n * same bytes through\n * {@link IStream}. Use {@link IStream} when the message arrives in chunks; use\n * this when you already have it whole.\n *\n * The whole buffer *is* the end of input, so the two failure outcomes both\n * throw a {@link SofabError} the caller tells apart by `code` (MESSAGE_SPEC §7):\n * malformed input throws `INVALID_MSG`, while input that ends inside a field —\n * truncation or an unclosed sequence — throws `INCOMPLETE`. A complete message\n * returns normally.\n *\n * Pass `limits` ({@link DecodeLimits}) to cap array counts and string / blob\n * lengths; an over-limit field throws `LIMIT_EXCEEDED` at its header, before it\n * is materialized. Omit for no caps (the default).\n */\nexport function decode(\n bytes: Uint8Array,\n visitor: Visitor,\n limits?: DecodeLimits,\n): void {\n decodeContiguous(bytes, visitor, limits);\n}\n","/**\n * The pull / cursor decoder: a monomorphic companion to {@link \"./fast\"}.\n *\n * {@link \"./fast\"}'s {@link decodeContiguous} is a *push* decoder — it drives the\n * buffer and calls a {@link Visitor} method per field. That is the right shape\n * for streaming and skip-subtree callers, but the visitor call sites go\n * megamorphic once a single decode routes through several differently-shaped\n * visitor objects (one per nested message type), which a JIT cannot inline.\n *\n * {@link Cursor} inverts control: it keeps one read cursor over the contiguous\n * {@link Uint8Array} and exposes *pull* primitives — {@link Cursor.readHeader}\n * plus a typed `read*` per wire type — so **generated code drives the loop** with\n * a single `switch (cursor.id)` that reads straight into its own fields. Every\n * call site is then monomorphic (the generated per-type decoder is the only\n * caller), which is what lets V8 inline the whole decode into a flat loop — the\n * same technique protobuf's generated `decode(reader)` uses.\n *\n * It shares {@link \"./fast\"}'s number-first varint core verbatim: each varint is\n * accumulated into two 32-bit JS *numbers* (`lo`/`hi`) and a `bigint` is\n * materialised only for a 64-bit *value* that does not fit in `2^53-1` (never for\n * ids, lengths or counts). String / blob payloads are returned as a single\n * zero-copy `subarray` view. It reports the same three-valued outcome as the\n * push path (MESSAGE_SPEC §7): malformed input throws a {@link SofabError} with\n * code `INVALID_MSG`, and a read that runs off the end of the buffer mid-field\n * throws `INCOMPLETE`.\n */\n\nimport {\n ARRAY_MAX,\n FIXLEN_MAX,\n FixlenSubtype,\n ID_MAX,\n WireType,\n} from \"../constants.js\";\nimport {\n incompleteError,\n invalidMsgError,\n limitExceededError,\n} from \"../errors.js\";\nimport { Long } from \"../long.js\";\nimport { zigzagDecode } from \"../varint/zigzag.js\";\nimport type { DecodeLimits } from \"./limits.js\";\n\nconst TWO32 = 0x1_0000_0000; // 2^32, for combining the 32-bit halves\n// Strict UTF-8 (MESSAGE_SPEC §8, CORELIB_PLAN §6.4): JavaScript strings are a\n// Unicode string type, so this target is always strict — the decoder builds the\n// string with the fatal TextDecoder, which throws on any invalid-UTF-8 payload\n// (overlong forms, surrogate code points, out-of-range, truncated or stray\n// bytes) rather than silently substituting U+FFFD. readString maps that throw to\n// the INVALID decode outcome. A lossy decoder is never used.\nconst _utf8 = new TextDecoder(\"utf-8\", { fatal: true });\n\n/**\n * A pull decoder over a complete message held in one contiguous buffer.\n *\n * Usage from generated code: loop on {@link readHeader}; for each field switch on\n * {@link id} and call the matching `read*` (which consumes that field's value and\n * advances the cursor); recurse into a child type's decoder on a nested sequence;\n * fall through to {@link skip} for an unknown id. See {@link readHeader}.\n *\n * Pass {@link DecodeLimits} to cap array counts and string / blob lengths; an\n * over-limit field throws {@link SofabError} (`LIMIT_EXCEEDED`) at its header,\n * before it is materialized. Omit for no caps (the default).\n */\nexport class Cursor {\n /** Field id of the header last accepted by {@link readHeader}. */\n id = 0;\n /** Wire type of the header last accepted by {@link readHeader}. */\n wire = 0;\n /**\n * Fixlen subtype of the header last accepted by {@link readHeader} — one of\n * {@link FixlenSubtype} — when its {@link wire} is {@link WireType.Fixlen} or\n * {@link WireType.ArrayFixlen}; `-1` otherwise (a non-fixlen field, or a\n * fixlen field whose subtype word is truncated away).\n *\n * The four fixlen subtypes (`fp32`, `fp64`, `string`, `blob`) all share one\n * {@link wire} type, so {@link wire} alone cannot separate them. This is the\n * companion accessor that can: a generated guard reads it right after\n * {@link readHeader} to skip a field whose delivered subtype contradicts the\n * schema (MESSAGE_SPEC §7.3), exactly as it already does on {@link wire} for\n * the other kinds:\n *\n * ```ts\n * case 9: if (c.wire !== WireType.Fixlen || c.fixSub !== FixlenSubtype.Fp64) {\n * c.skip(c.wire); break;\n * } o.somefp64 = c.readFp64(); break;\n * ```\n *\n * It is *peeked* — the subtype word is not consumed — so the matching typed\n * reader (or {@link skip}) still reads and validates it, and a malformed or\n * truncated word surfaces `INVALID` / `INCOMPLETE` there as before.\n */\n fixSub = -1;\n\n private readonly buf: Uint8Array;\n private readonly view: DataView;\n private readonly n: number;\n private p = 0;\n\n // Opt-in decode limits (corelib-ts#38). An unset limit is Infinity — no cap,\n // today's behavior. Enforced at the count / length header, before allocation.\n private readonly maxArrayCount: number;\n private readonly maxStringLen: number;\n private readonly maxBlobLen: number;\n\n // Last varint, as two unsigned 32-bit halves (see readVarint).\n private lo = 0;\n private hi = 0;\n\n // Number of nested sequences currently open (0 = root). Incremented when\n // readHeader accepts a SequenceStart, decremented when it consumes the matching\n // SequenceEnd (or when skip() discards a whole nested sequence). Lets the pull\n // parser tell a root-level dangling sequence-end (INVALID) and an unclosed\n // sequence at end-of-buffer (INCOMPLETE) apart from a clean boundary.\n private depth = 0;\n\n constructor(buf: Uint8Array, limits?: DecodeLimits) {\n this.buf = buf;\n this.n = buf.length;\n this.view = new DataView(buf.buffer, buf.byteOffset, buf.length);\n this.maxArrayCount = limits?.maxArrayCount ?? Infinity;\n this.maxStringLen = limits?.maxStringLen ?? Infinity;\n this.maxBlobLen = limits?.maxBlobLen ?? Infinity;\n }\n\n /**\n * Advance to the next field header. Returns `true` and sets {@link id} /\n * {@link wire} when a field follows; returns `false` — consuming the marker —\n * at the end of the buffer *or* at the sequence-end that closes the sequence\n * this decoder is reading. So a generated per-type decoder loops uniformly:\n *\n * ```ts\n * while (c.readHeader()) {\n * switch (c.id) {\n * case 4: this.u32 = Number(c.readUnsigned()); break;\n * case 10: this.child = Child.decodeFrom(c); break; // nested sequence\n * default: c.skip(c.wire); break; // unknown field\n * }\n * }\n * ```\n *\n * At the root the loop ends at end-of-buffer; inside a nested sequence it ends\n * at the matching {@link WireType.SequenceEnd} (which is consumed). A field\n * whose id is out of range throws {@link SofabError} (`INVALID_MSG`).\n */\n readHeader(): boolean {\n if (this.p >= this.n) {\n // End of buffer. At the root (depth 0) this is a clean, complete boundary;\n // inside an open sequence it is a truncated, unclosed sequence → INCOMPLETE\n // (§7), matching the fast path (fast.ts) which throws on `stack.length > 1`.\n if (this.depth > 0) {\n throw incompleteError(\"truncated message: unbalanced sequence\");\n }\n return false;\n }\n this.readVarint();\n const wire = this.lo & 7;\n if (wire === WireType.SequenceEnd) {\n // A sequence-end closes the current nested scope. At the root (depth 0)\n // there is no open sequence to close, so it is a dangling marker → INVALID\n // (mirrors fast.ts `stack.length <= 1` → \"unbalanced sequence end\").\n if (this.depth === 0) {\n throw invalidMsgError(\"unbalanced sequence end\");\n }\n this.depth--;\n return false;\n }\n const id = this.upper();\n if (id > ID_MAX) throw invalidMsgError(`field id ${id} out of range`);\n if (wire === WireType.SequenceStart) this.depth++;\n this.id = id;\n this.wire = wire;\n this.fixSub = this.peekFixSub(wire);\n return true;\n }\n\n /** Read an unsigned scalar (wire {@link WireType.Unsigned}), number-first. */\n readUnsigned(): number | bigint {\n this.readVarint();\n return this.unsignedValue();\n }\n\n /** Read a signed scalar (wire {@link WireType.Signed}), zig-zag, number-first. */\n readSigned(): number | bigint {\n this.readVarint();\n return this.signedValue();\n }\n\n /** Read a 32-bit float scalar (wire {@link WireType.Fixlen}, subtype fp32). */\n readFp32(): number {\n this.fixlenHeader(FixlenSubtype.Fp32, 4);\n return this.rawFp32();\n }\n\n /** Read a 64-bit float scalar (wire {@link WireType.Fixlen}, subtype fp64). */\n readFp64(): number {\n this.fixlenHeader(FixlenSubtype.Fp64, 8);\n return this.rawFp64();\n }\n\n /** Read a UTF-8 string scalar (wire {@link WireType.Fixlen}, subtype string). */\n readString(): string {\n const len = this.fixlenLen(FixlenSubtype.String);\n // take() (truncation → INCOMPLETE) runs before the decode, so a short\n // payload stays INCOMPLETE; only genuinely malformed UTF-8 bytes reach the\n // fatal decoder. Its TypeError becomes the INVALID outcome (§8/§6.4/§5.2).\n const bytes = this.take(len);\n try {\n return _utf8.decode(bytes);\n } catch {\n throw invalidMsgError(\"invalid UTF-8 in string\");\n }\n }\n\n /**\n * Read a blob scalar (wire {@link WireType.Fixlen}, subtype blob) as a\n * zero-copy {@link Uint8Array} view into the source buffer.\n */\n readBlob(): Uint8Array {\n const len = this.fixlenLen(FixlenSubtype.Blob);\n return this.take(len);\n }\n\n /** Read an unsigned array (wire {@link WireType.ArrayUnsigned}), number-first per element. */\n readUnsignedArray(): (number | bigint)[] {\n const count = this.arrayCount();\n const out: (number | bigint)[] = new Array(count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n out[i] = this.unsignedValue();\n }\n return out;\n }\n\n /** Read a signed array (wire {@link WireType.ArraySigned}), zig-zag, number-first per element. */\n readSignedArray(): (number | bigint)[] {\n const count = this.arrayCount();\n const out: (number | bigint)[] = new Array(count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n out[i] = this.signedValue();\n }\n return out;\n }\n\n /**\n * Read an unsigned 64-bit array into {@link Long}[] — the `bigint`-free path.\n * Each element keeps the raw lo/hi halves; call {@link Long.toBigInt} to\n * materialise only the values the caller actually needs.\n */\n readUnsignedArrayLong(): Long[] {\n const count = this.arrayCount();\n const out = new Array<Long>(count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n out[i] = new Long(this.lo, this.hi);\n }\n return out;\n }\n\n /** Read a signed 64-bit array (zig-zag) into {@link Long}[] — the `bigint`-free path. */\n readSignedArrayLong(): Long[] {\n const count = this.arrayCount();\n const out = new Array<Long>(count);\n for (let i = 0; i < count; i++) {\n this.readVarint();\n const lo = this.lo >>> 0;\n const hi = this.hi >>> 0;\n const mask = (-(lo & 1)) >>> 0; // all ones when the zig-zag lsb is set\n out[i] = new Long((((lo >>> 1) | (hi << 31)) >>> 0) ^ mask, ((hi >>> 1) >>> 0) ^ mask);\n }\n return out;\n }\n\n /** Read an fp32 array (wire {@link WireType.ArrayFixlen}, element subtype fp32). */\n readFp32Array(): number[] {\n const count = this.arrayFixlenHeader(FixlenSubtype.Fp32, 4);\n const out: number[] = new Array(count);\n for (let i = 0; i < count; i++) out[i] = this.rawFp32();\n return out;\n }\n\n /** Read an fp64 array (wire {@link WireType.ArrayFixlen}, element subtype fp64). */\n readFp64Array(): number[] {\n const count = this.arrayFixlenHeader(FixlenSubtype.Fp64, 8);\n const out: number[] = new Array(count);\n for (let i = 0; i < count; i++) out[i] = this.rawFp64();\n return out;\n }\n\n /**\n * Consume the value of the field whose header {@link readHeader} just accepted,\n * discarding it — for a `default:` branch that keeps the cursor in sync on an\n * unknown id. Pass {@link wire}. A {@link WireType.SequenceStart} skips the\n * whole nested sequence.\n */\n skip(wire: number): void {\n if (wire === WireType.SequenceStart) {\n // readHeader already counted this SequenceStart (depth++); skipSequence\n // consumes its whole balanced body incl. the matching end without going\n // through readHeader, so balance the count here.\n this.skipSequence();\n this.depth--;\n return;\n }\n this.skipValue(wire);\n }\n\n // --- value skipping -----------------------------------------------------\n\n private skipValue(wire: number): void {\n switch (wire) {\n case WireType.Unsigned:\n case WireType.Signed:\n this.readVarint();\n return;\n case WireType.Fixlen: {\n this.readVarint();\n const sub = this.lo & 7;\n const len = this.upper();\n // §4.6/§5.2: validate the fixlen word at the header, before the payload,\n // so a malformed word — a reserved subtype (0x4..0x7), or an fp32/fp64\n // whose declared length ≠ 4/8 — is INVALID even when the payload is also\n // truncated (INVALID takes precedence over INCOMPLETE). Mirrors the\n // known-field path ({@link fixlenHeader}) and fast.ts. A skip never\n // materializes the value, so string/blob keep only the len ≤ FIXLEN_MAX\n // bound — no opt-in length limit is enforced here (corelib-ts#49).\n if (sub > FixlenSubtype.Blob) throw invalidMsgError(`invalid fixlen subtype ${sub}`);\n if (sub === FixlenSubtype.Fp32 || sub === FixlenSubtype.Fp64) {\n if (len !== (sub === FixlenSubtype.Fp32 ? 4 : 8)) {\n throw invalidMsgError(\"fixlen float length mismatch\");\n }\n } else if (len > FIXLEN_MAX) {\n throw invalidMsgError(\"fixlen length out of range\");\n }\n this.take(len);\n return;\n }\n case WireType.ArrayUnsigned:\n case WireType.ArraySigned: {\n const count = this.arrayCount();\n for (let i = 0; i < count; i++) this.readVarint();\n return;\n }\n case WireType.ArrayFixlen: {\n // Read count and the element word, then validate the element type at the\n // header before taking the payload — a fixlen array carries only fp32\n // (size 4) or fp64 (size 8) elements (§4.8), so any other element word is\n // INVALID even when the payload is truncated (§5.2 precedence). This\n // deliberately does NOT use {@link arrayCount}'s count ≤ remaining-bytes\n // guard: that guard exists to bound allocation on the read paths, but the\n // skip path allocates nothing, and applying it here would report a\n // malformed-element array as INCOMPLETE instead of INVALID (corelib-ts#49).\n this.readVarint();\n const count = this.num();\n if (count > ARRAY_MAX) throw invalidMsgError(\"array count out of range\");\n if (count > this.maxArrayCount) {\n throw limitExceededError(\n `array count ${count} exceeds maxArrayCount ${this.maxArrayCount}`,\n );\n }\n this.readVarint();\n const sub = this.lo & 7;\n const size = this.upper();\n const ok =\n (sub === FixlenSubtype.Fp32 && size === 4) ||\n (sub === FixlenSubtype.Fp64 && size === 8);\n if (!ok) throw invalidMsgError(\"invalid fixlen array element type\");\n this.take(count * size);\n return;\n }\n default:\n throw invalidMsgError(`invalid wire type ${wire}`);\n }\n }\n\n private skipSequence(): void {\n let depth = 1;\n while (depth > 0) {\n if (this.p >= this.n) throw incompleteError(\"truncated message: unbalanced sequence\");\n this.readVarint();\n const wire = this.lo & 7;\n if (wire === WireType.SequenceEnd) {\n depth--;\n continue;\n }\n const id = this.upper();\n if (id > ID_MAX) throw invalidMsgError(`field id ${id} out of range`);\n if (wire === WireType.SequenceStart) depth++;\n else this.skipValue(wire);\n }\n }\n\n // --- field helpers ------------------------------------------------------\n\n /**\n * Peek the delivered fixlen subtype of the field {@link readHeader} just\n * accepted, **without advancing the cursor** — the readers / {@link skip}\n * still re-read and validate the word. Returns one of {@link FixlenSubtype}\n * (0..3), a reserved value (4..7), or `-1` when the wire is not a fixlen kind\n * or the subtype word is truncated away.\n *\n * The subtype is the low 3 bits of the fixlen sub-header word, and the low\n * bits of a LEB128 word live entirely in its **first** byte — so this only\n * reads one byte, it never decodes a varint.\n */\n private peekFixSub(wire: number): number {\n // Scalar fixlen: the sub-header is the byte right after the field header.\n if (wire === WireType.Fixlen) {\n return this.p < this.n ? this.buf[this.p]! & 7 : -1;\n }\n // Fixlen array: the element sub-header sits after the count varint (§4.8:\n // always present, even for count 0), so step over the count's bytes first —\n // a varint's last byte is the first one with the high bit clear.\n if (wire === WireType.ArrayFixlen) {\n let p = this.p;\n while (p < this.n && this.buf[p]! >= 0x80) p++;\n p++;\n return p < this.n ? this.buf[p]! & 7 : -1;\n }\n return -1; // not a fixlen field\n }\n\n /** Read and validate an array count word (0..ARRAY_MAX; §4.7/§4.8). */\n private arrayCount(): number {\n this.readVarint();\n const count = this.num();\n if (count > ARRAY_MAX) throw invalidMsgError(\"array count out of range\");\n if (count > this.maxArrayCount) {\n throw limitExceededError(\n `array count ${count} exceeds maxArrayCount ${this.maxArrayCount}`,\n );\n }\n // Part A hardening (corelib-ts#38): a dynamic array needs at least one wire\n // byte per element (a varint element, or an fp element ≥ its size), so a\n // count larger than the bytes left in the buffer cannot be real — reject it\n // as truncation *before* sizing `new Array(count)`, so a hostile count can\n // never drive an allocation larger than the input. A tighter fixlen bound\n // (count * elemSize) is applied once the element word is read, in\n // {@link arrayFixlenHeader}.\n if (count > this.n - this.p) throw incompleteError(\"truncated array\");\n return count;\n }\n\n /** Read a scalar fixlen sub-header, asserting subtype and exact byte length (floats). */\n private fixlenHeader(wantSub: number, wantLen: number): void {\n this.readVarint();\n const sub = this.lo & 7;\n const len = this.upper();\n if (sub !== wantSub) throw invalidMsgError(`invalid fixlen subtype ${sub}`);\n if (len !== wantLen) throw invalidMsgError(\"fixlen float length mismatch\");\n }\n\n /** Read a scalar fixlen sub-header for a string/blob, asserting subtype; returns byte length. */\n private fixlenLen(wantSub: number): number {\n this.readVarint();\n const sub = this.lo & 7;\n const len = this.upper();\n if (sub !== wantSub) throw invalidMsgError(`invalid fixlen subtype ${sub}`);\n if (len > FIXLEN_MAX) throw invalidMsgError(\"fixlen length out of range\");\n // Opt-in length cap (corelib-ts#38), enforced at the header before the\n // payload is taken. wantSub tells string from blob, so the right limit\n // applies to each.\n const limit =\n wantSub === FixlenSubtype.String ? this.maxStringLen : this.maxBlobLen;\n if (len > limit) {\n const what = wantSub === FixlenSubtype.String ? \"string\" : \"blob\";\n const name =\n wantSub === FixlenSubtype.String ? \"maxStringLen\" : \"maxBlobLen\";\n throw limitExceededError(\n `${what} length ${len} exceeds ${name} ${limit}`,\n );\n }\n return len;\n }\n\n /** Read an array fixlen element header (count + element type); returns the count. */\n private arrayFixlenHeader(wantSub: number, wantSize: number): number {\n // §4.8: a fixlen array always carries its element-length word — even when\n // empty — so the element kind stays known. count may then be 0.\n //\n // Read the count and validate the element word *before* the count ≤\n // remaining-bytes truncation guard, so a malformed element word on a\n // truncated array is INVALID, not INCOMPLETE (§5.2 precedence). This\n // deliberately inlines the count parse rather than calling {@link\n // arrayCount}, whose own `count > remaining` guard would otherwise fire\n // first — the same trap #49 sidestepped in skipValue's ArrayFixlen case\n // (corelib-ts#51, follow-up to #49).\n this.readVarint();\n const count = this.num();\n if (count > ARRAY_MAX) throw invalidMsgError(\"array count out of range\");\n if (count > this.maxArrayCount) {\n throw limitExceededError(\n `array count ${count} exceeds maxArrayCount ${this.maxArrayCount}`,\n );\n }\n this.readVarint();\n const sub = this.lo & 7;\n const size = this.upper();\n if (sub !== wantSub || size !== wantSize) {\n throw invalidMsgError(\"invalid fixlen array element type\");\n }\n // Part A hardening (corelib-ts#38): now the element size is known, a fixlen\n // array needs count * size payload bytes; a count claiming more than the\n // buffer holds is truncation — reject before sizing `new Array(count)`.\n // This tighter bound subsumes arrayCount's `count > remaining` guard.\n if (count > (this.n - this.p) / wantSize) {\n throw incompleteError(\"truncated fixlen array\");\n }\n return count;\n }\n\n /** Hand back a zero-copy view of the next `len` bytes, advancing the cursor. */\n private take(len: number): Uint8Array {\n const start = this.p;\n const end = start + len;\n if (end > this.n) throw incompleteError(\"truncated fixlen payload\");\n this.p = end;\n return this.buf.subarray(start, end);\n }\n\n private rawFp32(): number {\n const p = this.p;\n if (p + 4 > this.n) throw incompleteError(\"truncated fp32\");\n this.p = p + 4;\n return this.view.getFloat32(p, true);\n }\n\n private rawFp64(): number {\n const p = this.p;\n if (p + 8 > this.n) throw incompleteError(\"truncated fp64\");\n this.p = p + 8;\n return this.view.getFloat64(p, true);\n }\n\n // --- varint reading (shared verbatim with ./fast) -----------------------\n\n /**\n * The last varint's full value as a `bigint` (64-bit fidelity). Only ever\n * called from {@link unsignedValue} / {@link signedValue} on the `hi` overflow\n * path (`this.hi >>> 0 > 0x1fffff`), so `hi` is always non-zero here.\n */\n private big(): bigint {\n return (BigInt(this.hi >>> 0) << 32n) | BigInt(this.lo >>> 0);\n }\n\n /**\n * The last varint as an unsigned value, number-first: a `number` when it fits\n * exactly (`≤ 2^53-1`), a `bigint` only beyond that.\n */\n private unsignedValue(): number | bigint {\n const hi = this.hi >>> 0;\n return hi <= 0x1fffff ? hi * TWO32 + (this.lo >>> 0) : this.big();\n }\n\n /** The last zig-zag varint as a signed value, number-first. */\n private signedValue(): number | bigint {\n const hi = this.hi >>> 0;\n if (hi <= 0x1fffff) {\n const r = hi * TWO32 + (this.lo >>> 0); // raw zig-zag, ≤ 2^53-1\n return r % 2 === 0 ? r / 2 : -(r + 1) / 2;\n }\n return zigzagDecode(this.big());\n }\n\n /** The last varint's value as a JS number — exact for ids/lengths/counts. */\n private num(): number {\n return this.hi * TWO32 + (this.lo >>> 0);\n }\n\n /** The last varint with its low 3 tag bits stripped (`value >> 3`). */\n private upper(): number {\n return (this.hi >>> 0) * (TWO32 / 8) + (this.lo >>> 3);\n }\n\n /**\n * Decode one LEB128 varint at the cursor into {@link lo} / {@link hi} (each an\n * unsigned 32-bit half), advancing {@link p}. Throws on truncation or a value\n * spilling past 64 bits (>10 bytes). Unrolled, number-only — no `bigint`.\n */\n private readVarint(): void {\n const buf = this.buf;\n const n = this.n;\n let p = this.p;\n let b: number;\n let lo: number;\n let hi = 0;\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo = b & 0x7f;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 7;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 14;\n if (b < 0x80) return this.set(lo, 0, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x7f) << 21;\n if (b < 0x80) return this.set(lo, 0, p);\n\n // 5th byte straddles the 32-bit boundary: 4 bits to lo, 3 bits to hi.\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n lo |= (b & 0x0f) << 28;\n hi = (b >> 4) & 0x07;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 3;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 10;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 17;\n if (b < 0x80) return this.set(lo, hi, p);\n\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n hi |= (b & 0x7f) << 24;\n if (b < 0x80) return this.set(lo, hi, p);\n\n // 10th byte: only bit 63 (1 payload bit) remains below 64; any higher\n // payload bit, or a continuation into an 11th byte, is a >64-bit overflow.\n if (p >= n) throw incompleteError(\"truncated varint\");\n b = buf[p++]!;\n if (((b & 0x7f) >> 1) !== 0) throw invalidMsgError(\"varint overflow\");\n hi |= (b & 0x7f) << 31;\n if (b < 0x80) return this.set(lo, hi, p);\n\n throw invalidMsgError(\"varint overflow\");\n }\n\n private set(lo: number, hi: number, p: number): void {\n this.lo = lo;\n this.hi = hi;\n this.p = p;\n }\n}\n","/**\n * Optional native (N-API) acceleration loader.\n *\n * This module performs **no** work at import time and statically imports\n * nothing native, so pulling it into a browser or bundled build is harmless.\n * Call {@link loadNativeKernel} explicitly (only meaningful on Node.js /\n * Electron) to try to load the optional `@sofa-buffers/corelib-native` addon and\n * install it as the active {@link Kernel}. If the addon is absent or the host\n * is not Node, it returns `false` and the pure-JS kernel stays active.\n */\n\nimport { setKernel, type Kernel } from \"./kernel.js\";\n\n/** The package id of the optional native addon (an `optionalDependency`). */\nexport const NATIVE_PACKAGE = \"@sofa-buffers/corelib-native\";\n\nfunction isNode(): boolean {\n return (\n typeof process !== \"undefined\" &&\n !!(process as { versions?: { node?: string } }).versions?.node\n );\n}\n\n/**\n * Attempt to load and install the native kernel.\n *\n * @returns `true` if a valid native kernel was installed, `false` if it could\n * not be loaded (not on Node, addon not installed, or wrong shape). Never\n * throws for a missing addon — the JS kernel remains the fallback.\n */\nexport async function loadNativeKernel(): Promise<boolean> {\n if (!isNode()) return false;\n try {\n const { createRequire } = await import(\"node:module\");\n const require = createRequire(import.meta.url);\n const mod = require(NATIVE_PACKAGE) as { kernel?: Kernel } | Kernel;\n const kernel = (mod as { kernel?: Kernel }).kernel ?? (mod as Kernel);\n setKernel(kernel);\n return true;\n } catch {\n return false;\n }\n}\n","/**\n * Optional WebAssembly acceleration loader.\n *\n * Unlike the native addon, a WASM kernel runs in the browser too. This module\n * does nothing at import time; call {@link loadWasmKernel} with the compiled\n * module's bytes (or a streaming source) to instantiate it and install it as\n * the active {@link Kernel}. A real WASM build is shipped separately; this\n * loader is the stable entry point the rest of the library is wired through.\n */\n\nimport { setKernel, type Kernel } from \"./kernel.js\";\n\n/** A factory the WASM glue exposes: given the instance exports, build a Kernel. */\nexport type WasmKernelFactory = (\n exports: WebAssembly.Exports,\n) => Kernel;\n\n/**\n * Instantiate a WASM module and install the kernel it produces.\n *\n * @param source compiled-module bytes, a `Response`/stream, or a ready module.\n * @param factory wraps the instance exports into a {@link Kernel}.\n * @returns `true` once installed; throws only if instantiation itself fails.\n */\nexport async function loadWasmKernel(\n source: BufferSource | Response | PromiseLike<Response> | WebAssembly.Module,\n factory: WasmKernelFactory,\n imports: WebAssembly.Imports = {},\n): Promise<boolean> {\n let instance: WebAssembly.Instance;\n if (source instanceof WebAssembly.Module) {\n instance = await WebAssembly.instantiate(source, imports);\n } else if (\n typeof Response !== \"undefined\" &&\n (source instanceof Response || isThenable(source))\n ) {\n const result = await WebAssembly.instantiateStreaming(\n source as Response | PromiseLike<Response>,\n imports,\n );\n instance = result.instance;\n } else {\n const result = await WebAssembly.instantiate(source as BufferSource, imports);\n instance = result.instance;\n }\n setKernel(factory(instance.exports));\n return true;\n}\n\nfunction isThenable(x: unknown): x is PromiseLike<unknown> {\n return (\n typeof x === \"object\" &&\n x !== null &&\n typeof (x as { then?: unknown }).then === \"function\"\n );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/public.ts","../src/constants.ts","../src/errors.ts","../src/varint/bits64.ts","../src/long.ts","../src/varint/leb128.ts","../src/varint/num64.ts","../src/varint/zigzag.ts","../src/backend/js.ts","../src/backend/kernel.ts","../src/encode/fixlen.ts","../src/encode/ostream.ts","../src/encode/accumulate.ts","../src/decode/skip.ts","../src/decode/state.ts","../src/decode/istream.ts","../src/decode/text.ts","../src/decode/acc.ts","../src/decode/seq.ts","../src/encode/equal.ts"],"names":["SCRATCH","w","dv","SIGNED_FAST_MAX","named"],"mappings":";;;;;;;;;AAAA,IAAA,cAAA,GAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,WAAA,EAAA,MAAA,WAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA,SAAA,EAAA,MAAA,SAAA;AAAA,EAAA,OAAA,EAAA,MAAA,OAAA;AAAA,EAAA,YAAA,EAAA,MAAA,YAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,UAAA,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I,8BAA8B,KAAK,CAAA,0BAAA,EAC1C,KAAK,eAAe,CAAA;AAAA,OAC3B;AAAA,IACF;AAAA,EACF;AACF;AAGA,SAAS,kBACP,GAAA,EACA,KAAA,EACA,MAAA,EACA,GAAA,EACA,OACA,GAAA,EACe;AACf,EAAA,MAAM,UAAU,GAAA,CAAI,IAAA,CAAK,OAAO,MAAA,EAAQ,GAAA,EAAK,OAAO,GAAG,CAAA;AACvD,EAAA,OAAO,OAAA,KAAY,IAAA,GAAO,IAAA,GAAO,UAAA,CAAW,OAAO,CAAA;AACrD;;;AC9hBO,SAAS,aAAA,CAAc,GAAuB,CAAA,EAAgC;AACnF,EAAA,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,KAAA;AAClC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,CAAE,MAAA,EAAQ,CAAA,EAAA,EAAK,IAAI,CAAA,CAAE,CAAC,CAAA,KAAM,CAAA,CAAE,CAAC,GAAG,OAAO,KAAA;AAC7D,EAAA,OAAO,IAAA;AACT;AAmBO,SAAS,iBAAA,CAAkB,GAAoB,CAAA,EAA6B;AACjF,EAAA,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,KAAA;AAClC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,CAAE,QAAQ,CAAA,EAAA,EAAK;AACjC,IAAA,IAAI,EAAE,CAAC,CAAA,CAAG,GAAA,KAAQ,CAAA,CAAE,CAAC,CAAA,CAAG,GAAA,IAAO,CAAA,CAAE,CAAC,EAAG,IAAA,KAAS,CAAA,CAAE,CAAC,CAAA,CAAG,MAAM,OAAO,KAAA;AAAA,EACnE;AACA,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["/**\n * The complete public surface of the library, re-exported by {@link \"./index\"}\n * both as flat named exports and, aggregated, under the `sofab` namespace.\n */\n\nexport {\n API_VERSION,\n ArrayKind,\n DecodeStatus,\n FixlenSubtype,\n WireType,\n ID_MAX,\n FIXLEN_MAX,\n ARRAY_MAX,\n MAX_DEPTH,\n MIN_OUTPUT_BUFFER,\n U64_MAX,\n I64_MIN,\n I64_MAX,\n} from \"./constants.js\";\nexport type { FeedStatus } from \"./constants.js\";\n\nexport { SofabError, SofabErrorCode } from \"./errors.js\";\n\nexport { Long } from \"./long.js\";\nexport { OStream } from \"./encode/ostream.js\";\nexport { growingOStream } from \"./encode/accumulate.js\";\nexport type { FlushSink } from \"./encode/sink.js\";\n\n// The one decode surface (CORELIB_PLAN §5.3.1): a visitor, driven by IStream.\n// There is no pull parser, iterator or cursor to export beside it.\nexport { IStream, decode } from \"./decode/istream.js\";\nexport type {\n ArrayTarget,\n BoolArrayTarget,\n FloatArrayTarget,\n IntegerArrayTarget,\n Visitor,\n} from \"./decode/istream.js\";\n\n// The generated layer's support (ARCHITECTURE §8): schema-free helpers that a\n// generated message class would otherwise carry its own copy of. Nothing here\n// knows a schema — a capacity, a maxlen or a payload length is an argument.\nexport { decodeUtf8 } from \"./decode/text.js\";\nexport { PayloadAcc } from \"./decode/acc.js\";\nexport { BlobSeq, ElementSeq, FramedSeq, StringSeq, UNBOUNDED } from \"./decode/seq.js\";\nexport { elementsEqual, longElementsEqual } from \"./encode/equal.js\";\nexport { fp32RawBytes } from \"./varint/num64.js\";\n\nexport { getKernel, setKernel } from \"./backend/kernel.js\";\nexport type { Kernel } from \"./backend/kernel.js\";\nexport { jsKernel } from \"./backend/js.js\";\n","/**\n * Wire-format constants for SofaBuffers.\n *\n * The format is specified, language-neutrally, in the\n * {@link https://github.com/sofa-buffers/documentation | SofaBuffers documentation}.\n * Every field on the wire begins with a varint header `(id << 3) | wireType`,\n * so the wire type lives in the low three bits and the field id in the rest.\n */\n\n/**\n * The SofaBuffers API version this library implements. The generator and other\n * tooling read it to verify compatibility. Bumped only on a breaking API change.\n */\nexport const API_VERSION = 1;\n\n/** The three low bits of a field header: what kind of field follows. */\nexport const WireType = {\n /** Unsigned varint scalar. */\n Unsigned: 0,\n /** Signed varint scalar (zig-zag encoded). */\n Signed: 1,\n /** Fixed-length value: fp32, fp64, string or blob (see {@link FixlenSubtype}). */\n Fixlen: 2,\n /** Array of unsigned varints. */\n ArrayUnsigned: 3,\n /** Array of signed (zig-zag) varints. */\n ArraySigned: 4,\n /** Array of fixed-length values (fp32 / fp64 only). */\n ArrayFixlen: 5,\n /** Opens a nested sequence (new id scope). */\n SequenceStart: 6,\n /** Closes the current sequence. Encoded as the single byte `0x07`. */\n SequenceEnd: 7,\n} as const;\n/** A field's wire type: one of the {@link WireType} values. */\nexport type WireType = (typeof WireType)[keyof typeof WireType];\n\n/** The three low bits of a fixlen length header: which fixed-length type. */\nexport const FixlenSubtype = {\n /** IEEE-754 32-bit float, little-endian. */\n Fp32: 0,\n /** IEEE-754 64-bit double, little-endian. */\n Fp64: 1,\n /** UTF-8 string (no null terminator). */\n String: 2,\n /** Arbitrary binary data. */\n Blob: 3,\n} as const;\n/** A fixed-length value's type: one of the {@link FixlenSubtype} values. */\nexport type FixlenSubtype = (typeof FixlenSubtype)[keyof typeof FixlenSubtype];\n\n/** Which element kind an array field carries (reported to {@link Visitor.arrayBegin}). */\nexport const ArrayKind = {\n /** Unsigned-integer elements. */\n Unsigned: 0,\n /** Signed-integer (zig-zag) elements. */\n Signed: 1,\n /** IEEE-754 32-bit float elements. */\n Fp32: 2,\n /** IEEE-754 64-bit double elements. */\n Fp64: 3,\n} as const;\n/** An array field's element kind: one of the {@link ArrayKind} values. */\nexport type ArrayKind = (typeof ArrayKind)[keyof typeof ArrayKind];\n\n/** Largest permitted field id and fixlen length / array count: `INT32_MAX`. */\nexport const ID_MAX = 0x7fff_ffff;\n/** Largest permitted fixlen byte length: `INT32_MAX`. */\nexport const FIXLEN_MAX = 0x7fff_ffff;\n/** Largest permitted array element count: `INT32_MAX`. */\nexport const ARRAY_MAX = 0x7fff_ffff;\n\n/** Largest unsigned 64-bit value (`2^64 - 1`). */\nexport const U64_MAX = 0xffff_ffff_ffff_ffffn;\n/** Smallest signed 64-bit value (`-2^63`). */\nexport const I64_MIN = -0x8000_0000_0000_0000n;\n/** Largest signed 64-bit value (`2^63 - 1`). */\nexport const I64_MAX = 0x7fff_ffff_ffff_ffffn;\n\n/** A varint encodes at most this many bytes for a 64-bit value. */\nexport const VARINT_MAX_BYTES = 10;\n\n/**\n * The smallest output buffer this port accepts **for streaming** (CORELIB_PLAN\n * §5.1, normative): the number a caller sizes a streaming buffer from.\n *\n * `1`, because the encoder splits every *atomic unit* — a field header varint, a\n * fixlen word, an element count, a scalar or array element varint, an `fp32` /\n * `fp64` element — across a flush, so no write needs contiguous room and the\n * bytes produced are identical at any buffer size. (A port that required atomic\n * units to land contiguously would declare the largest run it reserves instead;\n * §5.1 caps any declaration at `20`.)\n *\n * It binds a buffer installed **with** a flush sink, at construction and at\n * every mid-stream `OStream.setBuffer`: such a buffer must satisfy\n * `buffer.length - offset >= MIN_OUTPUT_BUFFER` and is rejected right there\n * with `SofabErrorCode.Argument`, never partway through a message.\n *\n * A buffer installed **without** a sink is subject to no minimum: no flush can\n * occur, so nothing can be split, and the buffer either holds the whole message\n * or reports `SofabErrorCode.BufferFull`. That is the one-shot `MAX_SIZE` case\n * and it stays exact — a two-byte message encodes into a two-byte buffer.\n */\nexport const MIN_OUTPUT_BUFFER = 1;\n\n/**\n * Elements a bulk `fp32` run needs before a `DataView` handle over the buffer pays\n * for itself (CORELIB_PLAN §6.6.2 allows the handle; arithmetic decides when to take\n * it).\n *\n * On Node 24, building the handle costs ~129 ns and it saves ~1.9 ns per `fp32`\n * (4.11 → 2.23 ns writing, 3.27 → 1.46 ns reading including the raw bits §6.5\n * needs), so it breaks even around 68 elements. Below the threshold the shared\n * scratch word wins and no handle is built at all — which is why a message with one\n * float, or a two-element array, allocates nothing.\n *\n * End to end on a 1000-element array (Callgrind, `bench/run_callgrind.sh`, Ir/op):\n * encoding costs 195.3 → 28.0 instructions per `fp32` and 182.2 → 25.8 per `fp64`;\n * decoding 220.1 → 132.6 and 269.8 → 129.7. No workload in the shared benchmark\n * suite has a float run long enough to reach the threshold, so every row of it is\n * unchanged either way.\n *\n * @internal\n */\nexport const FP32_HANDLE_MIN = 64;\n\n/**\n * The `fp64` twin of {@link FP32_HANDLE_MIN}. A double saves far more per element —\n * ~7.3 ns writing (10.48 → 3.20) and ~8.0 ns reading (10.24 → 2.23) — so it breaks\n * even around 18.\n *\n * @internal\n */\nexport const FP64_HANDLE_MIN = 16;\n\n/**\n * Maximum nested-sequence depth (§4.9 / §6.2). An encoder must not open more\n * than this many nested sequences, and a decoder must reject a message that\n * nests deeper with an `InvalidMessage` error rather than risk unbounded\n * recursion / stack growth.\n */\nexport const MAX_DEPTH = 255;\n\n/**\n * The terminal outcome of a decode (MESSAGE_SPEC §7), reported identically for\n * one-shot and streaming decode with **no** finish / finalize / end promotion\n * step:\n *\n * - `Complete` — the bytes ended exactly at a field boundary: a valid message.\n * - `Incomplete` — the bytes ended *inside* a field (an unterminated varint, a\n * payload shorter than its declared length, an array that runs off the end, or\n * a nested sequence never closed). **Not an error** — more bytes could\n * complete it, and the caller owns end-of-input.\n * - `Invalid` — the bytes are malformed regardless of what follows. **Terminal**\n * (CORELIB_PLAN §5.2): no later bytes can undo it.\n *\n * **Each of the three leaves by exactly one channel.** {@link IStream.feed}\n * *returns* `Complete` or `Incomplete` — that is the {@link FeedStatus} pair, and\n * the caller needs no end step (CORELIB_PLAN §6). `Invalid` is never returned by\n * anything: it is the name of the outcome the throw carries, a {@link SofabError}\n * whose `code` is {@link SofabErrorCode.InvalidMsg}, and the verdict latches, so\n * every further `feed` re-throws without consuming input. There is no accessor\n * that re-reports any of the three, because a fact with two ways to learn it is a\n * fact that can be learned two different ways.\n *\n * The one-shot {@link decode} — the same stream, fed once — signals `Incomplete`\n * and `Invalid` by throwing a {@link SofabError} whose `code` is\n * {@link SofabErrorCode.Incomplete} or {@link SofabErrorCode.InvalidMsg}, and\n * `Complete` by returning normally.\n */\nexport const DecodeStatus = {\n /** The bytes ended exactly at a field boundary — a valid message. */\n Complete: \"COMPLETE\",\n /** The bytes ended inside a field; more bytes could complete it (not an error). */\n Incomplete: \"INCOMPLETE\",\n /** The bytes are malformed regardless of what follows. */\n Invalid: \"INVALID\",\n} as const;\n/** A decode's terminal outcome: one of the {@link DecodeStatus} values. */\nexport type DecodeStatus = (typeof DecodeStatus)[keyof typeof DecodeStatus];\n\n/**\n * The two outcomes {@link IStream.feed} can *return* — `Complete` and\n * `Incomplete`, the ones that leave a stream usable.\n *\n * `Invalid` is missing on purpose, and the type is the statement: this port puts\n * a refusal on the error channel (CORELIB_PLAN §6.3's second option), so a\n * malformed message throws rather than returning, and a caller switching on the\n * return value has no unreachable arm to write. The refusal is not lost by being\n * absent here — it arrives as a {@link SofabError} whose `code` says which\n * refusal it was, which is more than the outcome triple can express: a\n * `LimitExceeded` rejection has no value among the three at all.\n */\nexport type FeedStatus = typeof DecodeStatus.Complete | typeof DecodeStatus.Incomplete;\n","/**\n * Error handling for SofaBuffers.\n *\n * Both encoder and decoder report problems through a single {@link SofabError}\n * carrying a {@link SofabErrorCode}, mirroring the C reference's `sofab_ret_t`\n * return codes so the failure modes line up across the language family.\n *\n * The decoder distinguishes two *kinds* of decode failure (MESSAGE_SPEC §7):\n * {@link SofabErrorCode.InvalidMsg} for input that is malformed regardless of\n * what follows (`INVALID`), and {@link SofabErrorCode.Incomplete} for input that\n * merely ends inside a field (`INCOMPLETE`) — a truncation that more bytes could\n * complete, and so is *not* the same as a malformed message. A third code,\n * {@link SofabErrorCode.LimitExceeded}, is orthogonal to both: it reports a\n * receiver-configured decode limit being hit — *policy*, not a property of the\n * bytes — so it is kept distinct from `InvalidMsg`.\n */\n\n/**\n * The cause of a {@link SofabError}. `Argument`, `BufferFull` and `InvalidMsg`\n * match the C reference's `sofab_ret_t` codes; `Incomplete` is the\n * finish-less INCOMPLETE decode outcome (MESSAGE_SPEC §7), a distinct,\n * more-bytes-could-complete-it signal split out from `InvalidMsg`.\n */\nexport const SofabErrorCode = {\n /** A caller argument was invalid (e.g. id out of range, empty array). */\n Argument: \"ARGUMENT\",\n /** The output buffer is full and no flush sink was provided. */\n BufferFull: \"BUFFER_FULL\",\n /** The input being decoded is malformed regardless of what follows (`INVALID`). */\n InvalidMsg: \"INVALID_MSG\",\n /**\n * The input being decoded ends inside a field (`INCOMPLETE`, MESSAGE_SPEC §7):\n * an unterminated varint, a payload shorter than its declared length, an array\n * that runs off the end, or a nested sequence never closed. Not a malformed\n * message — more bytes could complete it, and the caller owns end-of-input.\n */\n Incomplete: \"INCOMPLETE\",\n /**\n * A receiver-configured decode limit was exceeded — a dynamic array, string or\n * blob on the wire claims more elements / bytes than the caller's\n * receiver cap (`max_dyn_array_count` / `max_dyn_string_len` /\n * `max_dyn_blob_len`, §6.2.1 — stated by generated code, never by this codec)\n * allows. Deliberately distinct from {@link SofabErrorCode.InvalidMsg}:\n * exceeding a limit is *policy*, not wire malformation — the identical bytes\n * decode fine under a looser limit — so differential fuzzing must not read it\n * as a conformance divergence. The decoder never clamps or truncates; it\n * rejects, before the offending field is materialized.\n */\n LimitExceeded: \"LIMIT_EXCEEDED\",\n} as const;\n/** A {@link SofabError}'s cause: one of the {@link SofabErrorCode} values. */\nexport type SofabErrorCode =\n (typeof SofabErrorCode)[keyof typeof SofabErrorCode];\n\n/** The single error type thrown by the encoder and decoder. */\nexport class SofabError extends Error {\n /** The machine-readable cause. */\n readonly code: SofabErrorCode;\n\n constructor(code: SofabErrorCode, message: string) {\n super(message);\n this.name = \"SofabError\";\n this.code = code;\n // Restore the prototype chain for transpiled-to-ES5 consumers.\n Object.setPrototypeOf(this, SofabError.prototype);\n }\n}\n\n/** @internal A caller passed an invalid argument. */\nexport function argumentError(message: string): SofabError {\n return new SofabError(SofabErrorCode.Argument, message);\n}\n\n/** @internal The output buffer filled with no flush sink to drain it. */\nexport function bufferFullError(message: string): SofabError {\n return new SofabError(SofabErrorCode.BufferFull, message);\n}\n\n/** @internal The input being decoded is malformed regardless of what follows. */\nexport function invalidMsgError(message: string): SofabError {\n return new SofabError(SofabErrorCode.InvalidMsg, message);\n}\n\n/**\n * @internal The input being decoded ended inside a field (truncation). A\n * distinct, non-malformed outcome (MESSAGE_SPEC §7): more bytes could complete\n * it, so it carries {@link SofabErrorCode.Incomplete}, never `InvalidMsg`.\n */\nexport function incompleteError(message: string): SofabError {\n return new SofabError(SofabErrorCode.Incomplete, message);\n}\n\n/**\n * @internal A receiver-configured decode limit (CORELIB_PLAN §6.2.1) was\n * exceeded. Carries {@link SofabErrorCode.LimitExceeded}, never `InvalidMsg`:\n * it is a policy rejection, not a statement that the bytes are malformed.\n */\nexport function limitExceededError(message: string): SofabError {\n return new SofabError(SofabErrorCode.LimitExceeded, message);\n}\n","/**\n * 64-bit ⇄ (lo, hi) bit punning through one shared 8-byte scratch buffer.\n *\n * Every hot path in the codec needs the same two conversions: a `bigint` split\n * into two unsigned 32-bit *number* halves (encode), and two halves joined back\n * into a `bigint` (decode). Doing that with `bigint` arithmetic —\n * `Number(v & 0xffff_ffffn)` / `(BigInt(hi) << 32n) | BigInt(lo)` — allocates a\n * fresh heap `bigint` per intermediate, and profiling under Callgrind showed\n * that split alone accounting for ~74% of the `u64 array` encode workload\n * (≈900 instructions per element).\n *\n * Aliasing one `ArrayBuffer` with a {@link BigUint64Array} and a\n * {@link Uint32Array} turns both conversions into raw loads and stores: the\n * engine converts a `bigint` to two machine words on the typed-array store and\n * back on the load, with **no intermediate allocation**. Measured on V8 the\n * split drops from ~900 to ~32 instructions per element (28×) and the join from\n * ~360 to ~81 (4.5×).\n *\n * **Truncation is identical to the masking it replaces.** Storing into a\n * `BigUint64Array` applies `ToBigUint64` — reduction modulo 2^64 — which is\n * exactly what `value & 0xffff_ffffn` plus `(value >> 32n) & 0xffff_ffffn`\n * computed, including for negative and over-wide inputs. `BigInt64Array`\n * applies `ToBigInt64`, the signed counterpart.\n *\n * **The scratch is shared, so read both halves immediately.** Every use must be\n * a straight-line store-then-load with no intervening call that could itself\n * reach this module — in particular no `ensure()` (which may invoke a\n * caller-supplied flush sink) between the split and the reads. Callers here\n * copy `lo`/`hi` into locals first, which is why that ordering is spelled out\n * at each call site.\n */\n\nconst SCRATCH = new ArrayBuffer(8);\n\n/** Unsigned 64-bit view of the scratch — the `ToBigUint64` conversion seam. */\nexport const S_U64 = new BigUint64Array(SCRATCH);\n/** Signed 64-bit view of the scratch — the `ToBigInt64` conversion seam. */\nexport const S_I64 = new BigInt64Array(SCRATCH);\n/** Two 32-bit halves of the scratch, in host byte order (see {@link LO}). */\nexport const S_U32 = new Uint32Array(SCRATCH);\n\n// Typed arrays use *host* byte order, so which Uint32Array slot holds the low\n// half depends on the platform. Probe it once: write 1 into slot 0 and see\n// whether the 64-bit view reads it as the value 1 (little-endian) or as\n// 2^32 (big-endian). Every real target is little-endian, so the branches below\n// fold away, but the format itself is little-endian on every host (§4) and this\n// keeps that true without a per-value byte swap.\nS_U64[0] = 0n;\nS_U32[0] = 1;\n/** Index of the low 32-bit half in {@link S_U32} on this host. */\nexport const LO = S_U64[0] === 1n ? 0 : 1;\n/** Index of the high 32-bit half in {@link S_U32} on this host. */\nexport const HI = LO ^ 1;\n\n/**\n * True when `value` fits an unsigned 64-bit integer — and, as a side effect,\n * leaves its two halves in {@link S_U32} for the caller to read.\n *\n * The round-trip *is* the range check: the store reduces modulo 2^64, so the\n * reloaded value differs from the original exactly when the original was\n * negative or ≥ 2^64. That fuses the `0n <= v <= U64_MAX` test (two `bigint`\n * comparisons) and the split (three `bigint` allocations) into one store, one\n * load and one compare.\n */\nexport function splitU64(value: bigint): boolean {\n S_U64[0] = value;\n return S_U64[0] === value;\n}\n\n/**\n * True when `value` fits a signed 64-bit integer, leaving its two's-complement\n * halves in {@link S_U32}. The signed twin of {@link splitU64}.\n */\nexport function splitI64(value: bigint): boolean {\n S_I64[0] = value;\n return S_I64[0] === value;\n}\n\n/** Join two unsigned 32-bit halves into an unsigned 64-bit `bigint`. */\nexport function joinU64(lo: number, hi: number): bigint {\n S_U32[LO] = lo;\n S_U32[HI] = hi;\n return S_U64[0]!;\n}\n\n/** Join two 32-bit halves into a *signed* 64-bit `bigint` (two's complement). */\nexport function joinI64(lo: number, hi: number): bigint {\n S_U32[LO] = lo;\n S_U32[HI] = hi;\n return S_I64[0]!;\n}\n","/**\n * A 64-bit integer value carried as two unsigned 32-bit halves.\n *\n * SofaBuffers accepts `bigint` at every 64-bit surface for ergonomics, but a\n * `bigint` in the encode/decode hot path is expensive — especially on\n * JavaScriptCore (Bun), where profiling showed the `bigint` split/materialise\n * and zig-zag operations dominating the 64-bit array codecs. `Long` lets a\n * caller (and the generated code) stay entirely on `number` arithmetic: the\n * codec reads `.low`/`.high` directly, and any `bigint`↔`Long` conversion\n * happens once at the API boundary rather than once per encode.\n *\n * Values are stored as raw two's-complement bits; the same `Long` serves an\n * unsigned or signed field — {@link Long.toBigInt} takes the signedness.\n *\n * The two `bigint` conversions below go through the shared bit-punning scratch\n * ({@link \"./varint/bits64\"}) that the codec's own hot paths use, rather than\n * through mask-and-shift `bigint` arithmetic: the split allocated four\n * intermediate `bigint`s per call and the join two, on the very boundary this\n * class exists to make cheap.\n */\n\nimport { HI, joinI64, joinU64, LO, S_I64, S_U32 } from \"./varint/bits64.js\";\n\nexport class Long {\n /** Low 32 bits (unsigned). */\n readonly low: number;\n /** High 32 bits (unsigned). */\n readonly high: number;\n\n constructor(low: number, high: number) {\n this.low = low >>> 0;\n this.high = high >>> 0;\n }\n\n /**\n * The 64-bit zero. `Long` is immutable (readonly halves), so this single shared\n * instance is safe to reuse anywhere a zero default is needed — generated code\n * uses it for fixed-count array defaults and pad-fill instead of\n * `Long.fromValue(0)`, which would run `bigint` arithmetic per call on the hot\n * decode/encode path.\n */\n static readonly ZERO: Long = new Long(0, 0);\n\n /** Construct from raw 32-bit halves. */\n static fromBits(low: number, high: number): Long {\n return new Long(low, high);\n }\n\n /**\n * Split a `bigint` into its low/high 32-bit halves (two's complement). The\n * `BigInt64Array` store *is* `ToBigInt64` — reduction modulo 2^64 — so an\n * out-of-range value keeps exactly the halves the masks kept (bits64).\n */\n static fromBigInt(value: bigint): Long {\n S_I64[0] = value;\n return new Long(S_U32[LO]!, S_U32[HI]!);\n }\n\n /** From an integer `number` (`|n| < 2^53`); sign handled via `bigint` once. */\n static fromNumber(n: number): Long {\n return Long.fromBigInt(BigInt(Math.trunc(n)));\n }\n\n /** Accept a `Long` as-is, or convert a `bigint` / `number` once. */\n static fromValue(v: Long | bigint | number): Long {\n if (v instanceof Long) return v;\n return typeof v === \"bigint\" ? Long.fromBigInt(v) : Long.fromNumber(v);\n }\n\n /** Materialise as a `bigint`. `signed` reads the high bit as two's complement. */\n toBigInt(signed = false): bigint {\n return signed ? joinI64(this.low, this.high) : joinU64(this.low, this.high);\n }\n\n /** Decimal string (`signed` interprets the high bit as two's complement). */\n toString(signed = false): string {\n return this.toBigInt(signed).toString();\n }\n}\n","/**\n * LEB128 variable-length integer coding — the **encode** half.\n *\n * Each byte carries seven payload bits with the high bit as a continuation flag;\n * bytes are little-endian (least-significant group first). Everything here is\n * `bigint`-free: a 64-bit value arrives already split into two 32-bit halves\n * (`…LoHi`, the shape {@link \"./bits64\"} produces), or as a `number` below 2^53\n * (`…Num`, the shape ids, lengths, counts and small scalars have).\n *\n * There is no varint *reader* in this module. Each decode surface reads varints\n * in the shape its own control flow needs — the resumable byte-at-a-time\n * accumulator in `decode/state.ts`, the unrolled whole-buffer ladder shared by\n * the decoder's own varint paths in `decode/state.ts` — and a general reader\n * with no production caller was only ever a fourth copy of the same overflow and\n * truncation rules to keep in lockstep (it had to be fixed alongside them in\n * corelib-ts#82, #88, #99/#100, #113, #131). The rules are pinned on the shipped\n * surfaces instead, in `test/varint.test.ts` and `test/varint-reader-shared.test.ts`.\n */\n\n/**\n * Number of bytes {@link encodeVarintLoHi} will write for the 64-bit value held\n * as two unsigned 32-bit halves, so a caller that has already split a value\n * sizes it without splitting again.\n */\nexport function varintSizeLoHi(lo: number, hi: number): number {\n // Below 2^32 the answer is a plain range ladder — no loop, no 64-bit shifting.\n if (hi === 0) {\n return lo < 0x80 ? 1 : lo < 0x4000 ? 2 : lo < 0x20_0000 ? 3 : lo < 0x1000_0000 ? 4 : 5;\n }\n // Above it, the first five bytes are always full: four 7-bit groups out of\n // `lo` plus a fifth straddling byte carrying lo's top 4 bits and hi's low 3.\n // What remains is `hi >>> 3`, a 29-bit quantity, sized by the same ladder.\n const h = hi >>> 3;\n return h === 0\n ? 5\n : 5 + (h < 0x80 ? 1 : h < 0x4000 ? 2 : h < 0x20_0000 ? 3 : h < 0x1000_0000 ? 4 : 5);\n}\n\n/**\n * Write a 64-bit value already split into two unsigned 32-bit halves as a\n * varint. Callers holding a `bigint` split it once through the shared\n * bit-punning scratch ({@link \"./bits64\"}, which allocates no `bigint` at all)\n * or hold a {@link Long}, and then stay on the number path here — avoiding both\n * the per-value `bigint` churn that dominates the 64-bit array encoders (which\n * JavaScriptCore optimizes far worse than V8) and the ~20 short-lived `bigint`s\n * a per-byte `v & 0x7fn; v >>= 7n` loop would make. The caller guarantees\n * `VARINT_MAX_BYTES` bytes of room from `pos`; `lo`/`hi` are coerced to uint32.\n */\nexport function encodeVarintLoHi(lo: number, hi: number, out: Uint8Array, pos: number): number {\n lo >>>= 0;\n hi >>>= 0;\n if (hi === 0) {\n // Wholly within 32 bits: a plain varint loop over `lo`, at most 5 bytes.\n while (lo > 0x7f) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo >>>= 7;\n }\n out[pos++] = lo;\n return pos;\n }\n // A real 64-bit value. The first four bytes are the four full 7-bit groups of\n // `lo`, taken straight off it — the loop this replaces re-derived a shifted\n // 64-bit value (`(lo >>> 7) | (hi << 25)`) for *every* byte, which is the\n // dominant per-byte cost when every element is a full-width u64.\n out[pos++] = (lo & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 7) & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 14) & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 21) & 0x7f) | 0x80;\n // Fifth byte straddles the halves: lo's top 4 bits, then hi's low 3.\n const b4 = (lo >>> 28) | ((hi & 0x07) << 4);\n let h = hi >>> 3;\n if (h === 0) {\n out[pos++] = b4;\n return pos;\n }\n out[pos++] = b4 | 0x80;\n // What is left is a 29-bit quantity — an ordinary 32-bit varint tail.\n while (h > 0x7f) {\n out[pos++] = (h & 0x7f) | 0x80;\n h >>>= 7;\n }\n out[pos++] = h;\n return pos;\n}\n\n/** Number of bytes {@link encodeVarintNum} will write for `value`. */\nexport function varintSizeNum(value: number): number {\n let n = 1;\n while (value > 0x7f) {\n n++;\n value = Math.floor(value / 128);\n }\n return n;\n}\n\n/**\n * Write `value` (a non-negative integer `number`, `≤ 2^53`) as a varint into\n * `out` at `pos`. The number-only sibling of {@link encodeVarintLoHi}: it avoids\n * `bigint` entirely, which is the encoder's hot path for ids, lengths, counts\n * and the very common small scalar. The caller guarantees `VARINT_MAX_BYTES`\n * bytes of room. Returns the position past the last byte written.\n */\nexport function encodeVarintNum(value: number, out: Uint8Array, pos: number): number {\n // Fast path: below 2^32 every 7-bit group survives bitwise extraction (ToUint32\n // is exact there, and `>>>` keeps it unsigned), so we stay on cheap integer ops.\n // This covers ids, lengths, counts, u8..u32 and their zig-zags — the vast\n // majority of calls. It matters because JavaScriptCore does not inline this\n // helper and its `% 128` / `Math.floor(/128)` float path is a top-3 hotspot\n // there; V8 optimizes both away, so the change is JSC-facing but harmless on V8.\n if (value < 0x1_0000_0000) {\n let v = value;\n while (v > 0x7f) {\n out[pos++] = (v & 0x7f) | 0x80;\n v >>>= 7;\n }\n out[pos++] = v;\n return pos;\n }\n // Slow path: 2^32 .. 2^53, where bitwise ops would truncate to 32 bits.\n while (value > 0x7f) {\n out[pos++] = (value % 128) | 0x80;\n value = Math.floor(value / 128);\n }\n out[pos++] = value;\n return pos;\n}\n","/**\n * 64-bit and IEEE-754 helpers.\n *\n * `bigint` coercion plus the float **bit** helpers: the conversions between an\n * IEEE-754 value and its little-endian wire bits, over one shared\n * {@link DataView}. The format stores `fp32` / `fp64` little-endian regardless of\n * host byte order, which a `DataView` gives us for free (the `littleEndian`\n * argument is passed explicitly everywhere).\n *\n * A single float goes through the shared scratch: one `DataView` construction costs\n * ~129 ns on Node 24, about sixteen `fp64` reads, so a handle over the caller's\n * buffer (CORELIB_PLAN §6.6.2) only pays for a *bulk* run — which is where the\n * kernel and the decoder's array drain take one, and nowhere else.\n */\n\nimport { argumentError } from \"../errors.js\";\nimport { HI, LO } from \"./bits64.js\";\n\n// One 8-byte scratch, viewed two ways: the `DataView` performs the IEEE-754\n// conversion with an explicit little-endian flag (so the wire stays\n// little-endian on any host, §4), and the `Uint8Array` alias moves the bytes.\n// Reading through the alias rather than `DataView.getUint8` turns each byte\n// into a plain typed-array load instead of a method call.\nconst SCRATCH_BUF = new ArrayBuffer(8);\nconst SCRATCH = new DataView(SCRATCH_BUF);\nconst SCRATCH_BYTES = new Uint8Array(SCRATCH_BUF);\nconst SCRATCH_U32 = new Uint32Array(SCRATCH_BUF);\nconst SCRATCH_F32 = new Float32Array(SCRATCH_BUF, 0, 1);\nconst SCRATCH_F64 = new Float64Array(SCRATCH_BUF);\n\n/**\n * Coerce a `number | bigint` to a `bigint`, rejecting non-integers.\n *\n * A fractional, `NaN` or infinite `number` at an integer surface is a caller\n * mistake in exactly the sense of CORELIB_PLAN §6.3's `InvalidArgument`, and so\n * is reported the way every other encoder rejection is: a {@link SofabError}\n * carrying {@link SofabErrorCode.Argument}. It used to escape as a bare\n * `RangeError`, which the documented `catch (e) { if (e instanceof SofabError) }`\n * pattern never sees (corelib-ts#111).\n */\nexport function toBigInt(value: number | bigint): bigint {\n if (typeof value === \"bigint\") return value;\n if (!Number.isInteger(value)) {\n throw argumentError(`expected an integer, got ${value}`);\n }\n return BigInt(value);\n}\n\n/** Write `value` as a little-endian fp32 into `out` at `pos`; returns `pos + 4`. */\nexport function packFp32(out: Uint8Array, pos: number, value: number): number {\n SCRATCH.setFloat32(0, value, true);\n out[pos] = SCRATCH_BYTES[0]!;\n out[pos + 1] = SCRATCH_BYTES[1]!;\n out[pos + 2] = SCRATCH_BYTES[2]!;\n out[pos + 3] = SCRATCH_BYTES[3]!;\n return pos + 4;\n}\n\n/** Write `value` as a little-endian fp64 into `out` at `pos`; returns `pos + 8`. */\nexport function packFp64(out: Uint8Array, pos: number, value: number): number {\n SCRATCH.setFloat64(0, value, true);\n out[pos] = SCRATCH_BYTES[0]!;\n out[pos + 1] = SCRATCH_BYTES[1]!;\n out[pos + 2] = SCRATCH_BYTES[2]!;\n out[pos + 3] = SCRATCH_BYTES[3]!;\n out[pos + 4] = SCRATCH_BYTES[4]!;\n out[pos + 5] = SCRATCH_BYTES[5]!;\n out[pos + 6] = SCRATCH_BYTES[6]!;\n out[pos + 7] = SCRATCH_BYTES[7]!;\n return pos + 8;\n}\n\n/**\n * The 4 little-endian wire bytes of `value` as one 32-bit word (byte `k` in bits\n * `8*k`) — the inverse of {@link fp32FromBits}, and the companion to an encoder\n * that must emit those bytes one at a time because its output buffer is smaller\n * than the value (CORELIB_PLAN §5.1). Returning a word rather than a byte view\n * keeps the bytes in the caller's registers, so a flush sink that re-enters the\n * encoder mid-value cannot overwrite them the way a shared scratch would.\n */\nexport function fp32Bits(value: number): number {\n SCRATCH.setFloat32(0, value, true);\n return SCRATCH.getUint32(0, true);\n}\n\n/** Bytes 0..3 of `value`'s little-endian fp64 image, as a 32-bit word. */\nexport function fp64BitsLo(value: number): number {\n SCRATCH.setFloat64(0, value, true);\n return SCRATCH.getUint32(0, true);\n}\n\n/** Bytes 4..7 of `value`'s little-endian fp64 image, as a 32-bit word. */\nexport function fp64BitsHi(value: number): number {\n SCRATCH.setFloat64(0, value, true);\n return SCRATCH.getUint32(4, true);\n}\n\n/**\n * Reinterpret the 4 little-endian wire bytes of an fp32, packed into one 32-bit\n * word (byte `k` in bits `8*k`), as a `number`. The companion to a resumable\n * decoder that accumulates float bytes into a machine word instead of a\n * per-instance byte array.\n */\nexport function fp32FromBits(bits: number): number {\n // Same-width aliases of one word: no byte order is involved, so a plain\n // element store + load replaces two `DataView` method calls (which JSC in\n // particular does not inline as well).\n SCRATCH_U32[0] = bits;\n return SCRATCH_F32[0]!;\n}\n\n/**\n * A fresh 4-byte companion holding one fp32 word's wire image: the four\n * little-endian bytes of its 32-bit word, byte `k` in bits `8*k`.\n *\n * Generated-layer support, not a codec path: an `fp32` field whose value is a\n * `NaN` cannot be re-encoded from the `number` a JS host stored it in — the host\n * normalizes the payload bits — so the generated message keeps the four raw wire\n * bytes beside the value and re-emits those (MESSAGE_SPEC §6.5). What the decoder\n * hands over is the 32-bit *word*, because a number costs nothing to pass where\n * the byte view it replaced was an allocation per value and a borrowed slice\n * §6.7 forbids; turning that word back into bytes is this function, and it is the\n * same four shifts for every schema (ARCHITECTURE §8).\n *\n * One function and not two. An `into(out, off, bits)` flavour beside it would be\n * the natural companion — it is what the fp32 *array* path would want — but that\n * path was retired before this one moved here (§6.7 killed the view), so the\n * whole family builds this companion per `NaN` scalar and nothing else calls it.\n * Public API with no consumer drifts, so there is exactly one entry point and it\n * allocates: the allocation is per `NaN`, not per field.\n */\nexport function fp32RawBytes(bits: number): Uint8Array {\n const out = new Uint8Array(4);\n out[0] = bits & 0xff;\n out[1] = (bits >>> 8) & 0xff;\n out[2] = (bits >>> 16) & 0xff;\n out[3] = (bits >>> 24) & 0xff;\n return out;\n}\n\n/** Reinterpret the 8 little-endian wire bytes of an fp64, packed into two words. */\nexport function fp64FromBits(lo: number, hi: number): number {\n // The two halves go to the host's own half order (`LO`/`HI`, probed once).\n SCRATCH_U32[LO] = lo;\n SCRATCH_U32[HI] = hi;\n return SCRATCH_F64[0]!;\n}\n","/**\n * Zig-zag mapping for signed integers.\n *\n * Signed values are zig-zag encoded before being written as an unsigned varint, so\n * small magnitudes of either sign stay short. The transform is the standard\n * `(n << 1) ^ (n >> 63)` over 64 bits, computed here on a value already held as two\n * 32-bit *number* halves — the only shape the codec's hot paths ever have it in, and\n * one that allocates nothing (§6.6) where the `bigint` form\n * (`(v << 1n) ^ (v >> 63n)`) allocates four per value.\n *\n * Only the encode direction lives here. The decoder undoes zig-zag inline, where it\n * already holds the halves, and hands them to the visitor beside the value — so a\n * `Long`-returning decode helper would be an object per value the codec may not\n * allocate.\n */\n\nimport { encodeVarintLoHi } from \"./leb128.js\";\n\n/**\n * Zig-zag *encode* a two's-complement 64-bit value held as two 32-bit halves and\n * write the result as a varint into `out` at `pos`; returns the position past\n * the last byte. Equivalent to zig-zagging the value and then writing the varint\n * of the result, for every value in the `int64` domain, with no `bigint`\n * allocated at all. The caller guarantees `VARINT_MAX_BYTES` bytes of room, as\n * for {@link encodeVarintLoHi}.\n */\nexport function encodeZigzagVarintLoHi(\n lo: number,\n hi: number,\n out: Uint8Array,\n pos: number,\n): number {\n // `sgn` is all-ones exactly when the value is negative — the arithmetic\n // `value >> 63` of the 64-bit form, widened across both halves.\n const sgn = -(hi >>> 31) >>> 0;\n return encodeVarintLoHi(\n (((lo << 1) >>> 0) ^ sgn) >>> 0,\n ((((hi << 1) | (lo >>> 31)) >>> 0) ^ sgn) >>> 0,\n out,\n pos,\n );\n}\n","/**\n * The default, pure-TypeScript {@link Kernel}.\n *\n * Always available — no native dependency, no WebAssembly — so SofaBuffers runs\n * unchanged in Node.js, browsers, Electron and bundled builds. Importing this\n * module registers it as the default kernel (idempotently); a native or WASM\n * kernel can later override it via {@link setKernel}.\n */\n\nimport { argumentError } from \"../errors.js\";\nimport { FP32_HANDLE_MIN, FP64_HANDLE_MIN } from \"../constants.js\";\nimport { HI, LO, S_U32, splitI64, splitU64 } from \"../varint/bits64.js\";\nimport { encodeVarintLoHi, encodeVarintNum } from \"../varint/leb128.js\";\nimport { packFp32, packFp64, toBigInt } from \"../varint/num64.js\";\nimport { encodeZigzagVarintLoHi } from \"../varint/zigzag.js\";\nimport type { Kernel } from \"./kernel.js\";\n\n// Largest signed magnitude whose zig-zag (|v|*2) stays an exact integer.\nconst SIGNED_FAST_MAX = 0x10_0000_0000_0000; // 2^52\n\n/**\n * The default, pure-TypeScript {@link Kernel} — active until {@link setKernel}\n * installs another. It implements the bulk encoder transforms with no native or\n * WebAssembly dependency, so it works in every environment.\n */\nexport const jsKernel: Kernel = {\n name: \"js\",\n\n encodeUnsignedVarints(values, out, pos) {\n const n = values.length;\n // An EXACT-WIDTH source settles every per-element guard statically: a\n // `Uint16Array` holds nothing but an integer in 0..65535, so the `typeof`,\n // the sign, the safe-integer bound and the `Number.isInteger` below are all\n // true for every element and belong outside the loop rather than in it. The\n // element load is unboxed too, and the array never changes element kind the\n // way a `number[]` does when a value leaves the small-integer range.\n //\n // Three identity compares, once per array. `u64` is deliberately absent:\n // a `BigUint64Array` element is a `bigint` and would still need the split.\n const ctor = (values as object).constructor;\n // A 64-bit typed source carries its elements as two 32-bit words in memory,\n // and a `Uint32Array` over the same buffer reads them without materialising\n // the `bigint` that indexing the array itself would produce. The varint is\n // then emitted from the halves, exactly as the scalar Long writers do.\n if (ctor === BigUint64Array) {\n const a = values as unknown as BigUint64Array;\n const h = new Uint32Array(a.buffer, a.byteOffset, a.length * 2);\n for (let i = 0; i < n; i++) {\n pos = encodeVarintLoHi(h[i * 2 + LO]!, h[i * 2 + HI]!, out, pos);\n }\n return pos;\n }\n if (ctor === Uint8Array || ctor === Uint16Array || ctor === Uint32Array) {\n const a = values as unknown as Uint32Array;\n for (let i = 0; i < n; i++) {\n let v = a[i]!;\n while (v > 0x7f) {\n out[pos++] = (v & 0x7f) | 0x80;\n v >>>= 7;\n }\n out[pos++] = v;\n }\n return pos;\n }\n for (let i = 0; i < n; i++) {\n const v = values[i]!;\n // Number elements (u8..u32 and any small u64) skip bigint entirely.\n if (typeof v === \"number\" && v >= 0 && v <= Number.MAX_SAFE_INTEGER && Number.isInteger(v)) {\n pos = encodeVarintNum(v, out, pos);\n continue;\n }\n // Anything else goes through the unsigned 64-bit scratch, whose store\n // yields both halves at ~1/28th the cost of a mask-and-shift split\n // (bits64) *and* range-checks in the same breath: `splitU64` reloads the\n // stored value and compares, which differs from the input exactly when it\n // was negative or ≥ 2^64. An element outside the domain (§6.2) is a caller\n // mistake and must be rejected, not reduced modulo 2^64 — the same answer\n // the element-at-a-time streaming path in OStream gives (#106).\n const b = toBigInt(v);\n if (!splitU64(b)) throw argumentError(`unsigned value ${b} out of range`);\n let lo = S_U32[LO]!;\n const hi = S_U32[HI]!;\n // The body of `encodeVarintLoHi`, inlined. This is the one place the\n // duplication earns its keep: it is the innermost loop of the whole\n // encoder, and the JIT does not inline the shared helper at this size, so\n // the call costs ~10% of the per-element budget. `kernelParity` in\n // test/kernel.test.ts pins these bytes against the shared helper over a\n // wide value corpus, so the two cannot drift.\n if (hi === 0) {\n while (lo > 0x7f) {\n out[pos++] = (lo & 0x7f) | 0x80;\n lo >>>= 7;\n }\n out[pos++] = lo;\n continue;\n }\n out[pos++] = (lo & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 7) & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 14) & 0x7f) | 0x80;\n out[pos++] = ((lo >>> 21) & 0x7f) | 0x80;\n const b4 = (lo >>> 28) | ((hi & 0x07) << 4);\n let h = hi >>> 3;\n if (h === 0) {\n out[pos++] = b4;\n continue;\n }\n out[pos++] = b4 | 0x80;\n while (h > 0x7f) {\n out[pos++] = (h & 0x7f) | 0x80;\n h >>>= 7;\n }\n out[pos++] = h;\n }\n return pos;\n },\n\n encodeSignedVarints(values, out, pos) {\n // The signed twin of the exact-width arm above. Zig-zag on an `Int32Array`\n // element cannot leave 32 bits — `-2^31` maps to `2^32-1` — so the whole\n // 64-bit split and its domain check are unreachable for this source.\n const ctorS = (values as object).constructor;\n if (ctorS === BigInt64Array) {\n const a = values as unknown as BigInt64Array;\n const h = new Uint32Array(a.buffer, a.byteOffset, a.length * 2);\n for (let i = 0; i < a.length; i++) {\n pos = encodeZigzagVarintLoHi(h[i * 2 + LO]!, h[i * 2 + HI]!, out, pos);\n }\n return pos;\n }\n if (ctorS === Int8Array || ctorS === Int16Array || ctorS === Int32Array) {\n const a = values as unknown as Int32Array;\n const n = a.length;\n for (let i = 0; i < n; i++) {\n const x = a[i]!;\n let z = ((x << 1) ^ (x >> 31)) >>> 0;\n while (z > 0x7f) {\n out[pos++] = (z & 0x7f) | 0x80;\n z >>>= 7;\n }\n out[pos++] = z;\n }\n return pos;\n }\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n if (typeof v === \"number\" && v >= -SIGNED_FAST_MAX && v <= SIGNED_FAST_MAX && Number.isInteger(v)) {\n pos = encodeVarintNum(v >= 0 ? v * 2 : -v * 2 - 1, out, pos);\n } else {\n // As in encodeUnsignedVarints, the signed scratch round-trip is both\n // the §6.2 domain check and the split: an element outside\n // `-2^63 .. 2^63 - 1` is rejected rather than wrapped (#106). Zig-zag\n // then runs on the two halves, producing the very same bytes as\n // `zigzagEncode` in `bigint` with nothing allocated.\n const b = toBigInt(v);\n if (!splitI64(b)) throw argumentError(`signed value ${b} out of range`);\n pos = encodeZigzagVarintLoHi(S_U32[LO]!, S_U32[HI]!, out, pos);\n }\n }\n return pos;\n },\n\n // Both float packers take one `DataView` over the destination *once the run is\n // long enough to pay for it* — the language-forced handle of CORELIB_PLAN §6.6.2,\n // and the only way to place an IEEE-754 value at a byte offset. It carries no\n // message bytes (the storage is the caller's) and no wire number sizes it.\n //\n // The threshold is arithmetic, not taste. Measured on Node 24:\n // `new DataView(buf.buffer, off, len)` costs **129 ns**, while the handle saves\n // 1.9 ns per `fp32` (4.11 -> 2.23) and 7.3 ns per `fp64` (10.48 -> 3.20). So it\n // breaks even at ~68 `fp32` and ~18 `fp64` elements; below that the scratch route\n // wins, and a two-element array through a handle is a pessimisation.\n packFp32Array(values, out, pos) {\n const n = values.length;\n // A `Float32Array` source already HOLDS the 32-bit wire words, so they are\n // copied rather than read: `values[i]` widens each element to a double, and\n // widening a SIGNALING NaN quiets it (0x7f800001 comes back 0x7fc00001), so\n // reading the values is exactly how an fp32 payload gets lost (§4.6/§6.5).\n // Going through the words is bit-exact for every value, not only NaNs, and it\n // removes any need for a caller to carry the wire bytes beside the numbers.\n if (values instanceof Float32Array) {\n // A short run needs no handle at all. Only a NaN can lose bits in the\n // widening (every other fp32 narrows back exactly through the scratch), so\n // the element is read as a value and the word view is built only when a\n // NaN is actually met: touching `values.buffer` moves a small, on-heap\n // typed array's storage off the heap, and a view plus a `DataView` per\n // 5-element array cost more than the elements themselves.\n if (n < FP32_HANDLE_MIN) {\n let w: Uint32Array | null = null;\n for (let i = 0; i < n; i++) {\n const v = values[i]!;\n if (v === v) {\n pos = packFp32(out, pos, v);\n continue;\n }\n if (w === null) w = new Uint32Array(values.buffer, values.byteOffset, n);\n const x = w[i]!;\n out[pos] = x;\n out[pos + 1] = x >>> 8;\n out[pos + 2] = x >>> 16;\n out[pos + 3] = x >>> 24;\n pos += 4;\n }\n return pos;\n }\n const w = new Uint32Array(values.buffer, values.byteOffset, n);\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n for (let i = 0; i < n; i++) {\n dv.setUint32(pos, w[i]!, true);\n pos += 4;\n }\n return pos;\n }\n if (n < FP32_HANDLE_MIN) {\n for (let i = 0; i < n; i++) pos = packFp32(out, pos, values[i]!);\n return pos;\n }\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n for (let i = 0; i < n; i++) {\n dv.setFloat32(pos, values[i]!, true);\n pos += 4;\n }\n return pos;\n },\n\n packFp64Array(values, out, pos) {\n const n = values.length;\n if (n < FP64_HANDLE_MIN) {\n for (let i = 0; i < n; i++) pos = packFp64(out, pos, values[i]!);\n return pos;\n }\n const dv = new DataView(out.buffer, out.byteOffset, out.byteLength);\n for (let i = 0; i < n; i++) {\n dv.setFloat64(pos, values[i]!, true);\n pos += 8;\n }\n return pos;\n },\n};\n","/**\n * The acceleration seam.\n *\n * The encoder's bulk array paths run through a {@link Kernel} — a small set of\n * self-contained, buffer-oriented transforms over a region the caller has\n * already sized. The default {@link \"./js\"} kernel is pure TypeScript and works\n * everywhere, and is the active kernel unless the caller replaces it: no\n * accelerated build is published, and this interface is the entire seam for one\n * (#115). A C++ (N-API) or WebAssembly build implements the same interface and\n * is swapped in with {@link setKernel} — the caller loads its own module and\n * hands over the kernel it builds — for a speed-up with **no change to the\n * public API**. The boundary is deliberately *bulk* (a whole\n * array per call, into guaranteed capacity) so the cost of crossing into native\n * code is amortised — never one call per element.\n */\n\nimport { jsKernel } from \"./js.js\";\n\n/**\n * Bulk transforms used on the encoder's fast path.\n *\n * Every method writes into `out` starting at `pos` and returns the position just\n * past the last byte written.\n *\n * **`out.length` is the bound, and the only one.** The two packers are handed a\n * region the caller has already sized exactly (4 or 8 bytes an element, a number\n * the caller can compute), so for them \"enough room\" is a guarantee. The two\n * *varint* kernels are not: a varint's length depends on the value, so the caller\n * cannot know the size without encoding it, and asking the source how wide its\n * elements are is exactly the guess that silently truncated messages (§5.1). So a\n * varint kernel must\n *\n * * **never write at or past `out.length`**, and\n * * **keep counting anyway**, returning the position it *would* have reached.\n *\n * The caller compares that against `out.length`: past the end means the message\n * does not fit, which in the block mode is `BUFFER_FULL` — the answer that mode\n * exists to give. The JS kernel satisfies this for free (a typed-array store past\n * the end is dropped while `pos` keeps advancing); a native or WebAssembly kernel\n * must implement it deliberately, counting the remaining elements without storing. Headers, counts and flushing stay in the stream classes; a kernel\n * only moves bytes — with one obligation it cannot delegate, because it is the\n * only code that ever looks at the elements: **the integer kernels must reject\n * an element outside the 64-bit value domain** (CORELIB_PLAN §6.2 — `0 .. 2^64\n * - 1` unsigned, `-2^63 .. 2^63 - 1` signed) by throwing `argumentError`,\n * rather than reducing it modulo 2^64. The stream classes range-check the same\n * values on their element-at-a-time streaming path, so a kernel that skipped\n * the check would make the wire depend on which constructor the caller used\n * (#106). The check is one store, one load and one compare on the `bigint`\n * branch (`splitU64` / `splitI64`); the `number` fast paths are already gated\n * on the domain and pay nothing.\n */\nexport interface Kernel {\n /** A short identifier, surfaced in diagnostics and the parity tests. */\n readonly name: string;\n\n /** Encode each element as an unsigned varint. */\n encodeUnsignedVarints(\n values: ArrayLike<number | bigint>,\n out: Uint8Array,\n pos: number,\n ): number;\n\n /** Zig-zag then varint-encode each element. */\n encodeSignedVarints(\n values: ArrayLike<number | bigint>,\n out: Uint8Array,\n pos: number,\n ): number;\n\n /** Pack each element as a little-endian fp32 (4 bytes). */\n packFp32Array(values: ArrayLike<number>, out: Uint8Array, pos: number): number;\n\n /** Pack each element as a little-endian fp64 (8 bytes). */\n packFp64Array(values: ArrayLike<number>, out: Uint8Array, pos: number): number;\n}\n\n// Initialised directly (not via an import side effect) so that bundlers honouring\n// the package's `\"sideEffects\": false` can never tree-shake the default away.\nlet active: Kernel = jsKernel;\n\n/** Install `kernel` as the active acceleration backend. */\nexport function setKernel(kernel: Kernel): void {\n validateKernel(kernel);\n active = kernel;\n}\n\n/** The currently active kernel (the JS kernel until something replaces it). */\nexport function getKernel(): Kernel {\n return active;\n}\n\n/** Throws if `kernel` is missing a required method — used by {@link setKernel}. */\nfunction validateKernel(kernel: Kernel): void {\n const required: (keyof Kernel)[] = [\n \"encodeUnsignedVarints\",\n \"encodeSignedVarints\",\n \"packFp32Array\",\n \"packFp64Array\",\n ];\n for (const m of required) {\n if (typeof kernel[m] !== \"function\") {\n throw new TypeError(`kernel \"${kernel?.name}\" is missing ${String(m)}()`);\n }\n }\n}\n","/**\n * Encode-side text helper.\n *\n * Two paths turn strings into UTF-8:\n *\n * - {@link utf8Length} / {@link utf8Write} — an allocation-free, two-pass writer\n * used by the encoder's contiguous-write fast path. `writeString` needs the byte\n * length *before* the payload (it goes into the fixlen length word), so the\n * length is scanned first and the bytes are then written straight into the\n * output buffer. This avoids `TextEncoder.encode`'s per-call WHATWG setup cost\n * plus the throwaway `Uint8Array` it allocates and the second copy into the\n * buffer — which V8 profiling showed to be the encoder's dominant cost (a\n * short string cost ~700 ns almost entirely in `TextEncoder`).\n * - {@link utf8WriteSink} — the same walk, emitting one byte at a time into a\n * {@link ByteSink}, for the streaming path where the output buffer is narrower\n * than the payload and the encoder drains between bytes. It replaces a\n * `TextEncoder.encode` into a throwaway array, which was an allocation on a\n * codec path and so is not available to it (CORELIB_PLAN §6.6).\n *\n * **Strict UTF-8 (MESSAGE_SPEC §8, CORELIB_PLAN §6.4).** A `string` is UTF-8\n * text; the encode side is always strict for this Unicode-string target. The\n * platform encoders are lossy — `TextEncoder`, and the hand-rolled fast path it\n * once mirrored, both replace an **unpaired surrogate** with `U+FFFD` — which is\n * the silent data mutation §8 forbids in every mode and direction. Both paths\n * here instead **reject** an unpaired surrogate with an `InvalidArgument`\n * {@link SofabError} (the encode-side image of the decode `INVALID` outcome), so\n * a producer can never emit bytes a strict decoder would refuse. Every *valid*\n * string — ASCII, multibyte BMP, correctly paired astral code points, embedded\n * `U+0000` — still encodes byte-for-byte as before.\n */\n\nimport { argumentError, type SofabError } from \"../errors.js\";\n\n/** An unpaired surrogate at `index` cannot be encoded as valid UTF-8 (§8/§6.4). */\nfunction unpairedSurrogate(index: number): SofabError {\n return argumentError(\n `unpaired surrogate at index ${index}: string value is not valid UTF-8`,\n );\n}\n\n/** Anything that takes UTF-8 one byte at a time — in practice, the encoder itself. */\nexport interface ByteSink {\n /** @internal Append one byte, draining to the flush sink when the buffer is full. */\n putByte(b: number): void;\n}\n\n/**\n * Number of UTF-8 bytes {@link utf8Write} will emit for `text`. For a\n * well-formed string this matches {@link TextEncoder} byte-for-byte (a paired\n * surrogate is 4 bytes). An **unpaired surrogate** is not encodable as UTF-8, so\n * it is **rejected** with {@link SofabError} (`ARGUMENT`), never counted as a\n * `U+FFFD` (3-byte) replacement (MESSAGE_SPEC §8).\n */\nexport function utf8Length(text: string): number {\n const n = text.length;\n // ASCII pre-scan: one compare per character, no branch tree and no running\n // sum. Identifiers, keys and most short strings are pure ASCII, where this\n // returns immediately with `len === n`; anything else resumes the general\n // walk below at the first non-ASCII character, so nothing is scanned twice.\n let a = 0;\n while (a < n && text.charCodeAt(a) < 0x80) a++;\n if (a === n) return n;\n\n let len = a;\n for (let i = a; i < n; i++) {\n const c = text.charCodeAt(i);\n if (c < 0x80) {\n len += 1;\n } else if (c < 0x800) {\n len += 2;\n } else if (c >= 0xd800 && c <= 0xdbff) {\n // High surrogate: a following low surrogate makes a 4-byte code point;\n // otherwise it is an unpaired surrogate — reject, never collapse to U+FFFD.\n const c2 = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c2 >= 0xdc00 && c2 <= 0xdfff) {\n i++;\n len += 4;\n } else {\n throw unpairedSurrogate(i);\n }\n } else if (c >= 0xdc00 && c <= 0xdfff) {\n // Lone low surrogate (a paired one was consumed with its high half above).\n throw unpairedSurrogate(i);\n } else {\n // BMP ≥ 0x800.\n len += 3;\n }\n }\n return len;\n}\n\n/**\n * Write `text` as UTF-8 into `out` at `pos`; returns the position past the last\n * byte. The caller must have ensured {@link utf8Length}(text) bytes of room.\n * Byte-for-byte identical to {@link TextEncoder} for well-formed input; an\n * **unpaired surrogate** is rejected with {@link SofabError} (`ARGUMENT`) rather\n * than written as `U+FFFD` (MESSAGE_SPEC §8). `writeString` runs\n * {@link utf8Length} first, so the fast path rejects before any byte is emitted.\n */\nexport function utf8Write(text: string, out: Uint8Array, pos: number): number {\n const n = text.length;\n // ASCII fast copy, mirroring utf8Length's pre-scan: one compare and one store\n // per character until the first non-ASCII one, then the general walk resumes\n // from there.\n let a = 0;\n while (a < n) {\n const c = text.charCodeAt(a);\n if (c >= 0x80) break;\n out[pos + a] = c;\n a++;\n }\n pos += a;\n if (a === n) return pos;\n\n for (let i = a; i < n; i++) {\n let c = text.charCodeAt(i);\n if (c < 0x80) {\n out[pos++] = c;\n } else if (c < 0x800) {\n out[pos++] = 0xc0 | (c >> 6);\n out[pos++] = 0x80 | (c & 0x3f);\n } else if (c >= 0xd800 && c <= 0xdbff) {\n const c2 = i + 1 < text.length ? text.charCodeAt(i + 1) : 0;\n if (c2 >= 0xdc00 && c2 <= 0xdfff) {\n i++;\n c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);\n out[pos++] = 0xf0 | (c >> 18);\n out[pos++] = 0x80 | ((c >> 12) & 0x3f);\n out[pos++] = 0x80 | ((c >> 6) & 0x3f);\n out[pos++] = 0x80 | (c & 0x3f);\n } else {\n // Unpaired high surrogate — reject, never write U+FFFD.\n throw unpairedSurrogate(i);\n }\n } else if (c >= 0xdc00 && c <= 0xdfff) {\n // Unpaired low surrogate — reject, never write U+FFFD.\n throw unpairedSurrogate(i);\n } else {\n out[pos++] = 0xe0 | (c >> 12);\n out[pos++] = 0x80 | ((c >> 6) & 0x3f);\n out[pos++] = 0x80 | (c & 0x3f);\n }\n }\n return pos;\n}\n\n/**\n * Write `text` as UTF-8 one byte at a time into `sink` — {@link utf8Write}'s walk\n * for an output buffer that cannot take the payload contiguously, where the\n * encoder flushes between bytes (§5.1.3: a payload run is divisible at any byte).\n *\n * Byte-for-byte identical to {@link utf8Write}, unpaired-surrogate rejection\n * included; it differs only in where the bytes go. `writeString` has already run\n * {@link utf8Length}, so a string that cannot be encoded was rejected before the\n * header went out and this walk never meets one.\n */\nexport function utf8WriteSink(text: string, sink: ByteSink): void {\n const n = text.length;\n for (let i = 0; i < n; i++) {\n let c = text.charCodeAt(i);\n if (c < 0x80) {\n sink.putByte(c);\n } else if (c < 0x800) {\n sink.putByte(0xc0 | (c >> 6));\n sink.putByte(0x80 | (c & 0x3f));\n } else if (c >= 0xd800 && c <= 0xdbff) {\n const c2 = i + 1 < n ? text.charCodeAt(i + 1) : 0;\n if (c2 >= 0xdc00 && c2 <= 0xdfff) {\n i++;\n c = 0x10000 + ((c - 0xd800) << 10) + (c2 - 0xdc00);\n sink.putByte(0xf0 | (c >> 18));\n sink.putByte(0x80 | ((c >> 12) & 0x3f));\n sink.putByte(0x80 | ((c >> 6) & 0x3f));\n sink.putByte(0x80 | (c & 0x3f));\n } else {\n throw unpairedSurrogate(i);\n }\n } else if (c >= 0xdc00 && c <= 0xdfff) {\n throw unpairedSurrogate(i);\n } else {\n sink.putByte(0xe0 | (c >> 12));\n sink.putByte(0x80 | ((c >> 6) & 0x3f));\n sink.putByte(0x80 | (c & 0x3f));\n }\n }\n}\n","/**\n * The SofaBuffers encoder.\n *\n * `OStream` writes fields into a **caller-supplied** byte buffer — the corelib\n * allocates no output buffer and never grows or reallocates one it was handed\n * (CORELIB_PLAN §5.1). Two ways to drive it:\n *\n * - **One-shot** (`new OStream(buffer, offset?)`): the buffer must hold the\n * whole message — the size a caller derives from the generated `MAX_SIZE` —\n * and a buffer that fills reports `BUFFER_FULL` rather than growing.\n * - **Streaming** (`new OStream(buffer, offset?, flush?)`): when the buffer\n * fills, the produced bytes go to the `flush` sink and encoding continues —\n * so the buffer can be arbitrarily smaller than the message, **down to a\n * single byte** (§5.1): no single write requires contiguous room, a value\n * larger than the buffer is split across flushes, and the bytes produced are\n * identical either way — which is why this port declares\n * {@link MIN_OUTPUT_BUFFER} = 1, the floor a buffer installed *with* a sink\n * must clear. `offset` reserves room at the front for a lower-layer header,\n * and it is `length - offset` that must clear the floor. Without a `flush`\n * sink there is nowhere to drain to, so no minimum applies.\n *\n * Where the message has no schema-derived bound, the allocating half is the\n * caller's, and CORELIB_PLAN §5.1.2 names the shape it takes: \"install a scratch\n * buffer **with a sink** that appends into the growing result\". `growingOStream`\n * (`./accumulate.ts`) is that caller ready-made — a **helper** (§6.6.1) built out\n * of the streaming mode below, owning storage the encoder never sees the whole\n * of. `OStream` itself has no growth mechanism at all.\n *\n * Generated code typically writes one field per message field; the methods map\n * one-to-one onto the wire types. Problems throw {@link SofabError}.\n *\n * Nested sequences are opened with {@link OStream.writeSequenceBeginLazy}, which\n * holds the header back until the sequence proves it has content, so an\n * all-default one is omitted rather than framed empty (MESSAGE_SPEC §2). Close a\n * `struct`/`union` field or an array wrapper with {@link OStream.writeSequenceEnd}\n * and a wrapper-array *element* with {@link OStream.writeSequenceEndKeep}.\n */\n\nimport {\n ARRAY_MAX,\n FIXLEN_MAX,\n FixlenSubtype,\n ID_MAX,\n MAX_DEPTH,\n MIN_OUTPUT_BUFFER,\n VARINT_MAX_BYTES,\n WireType,\n} from \"../constants.js\";\nimport {\n argumentError,\n bufferFullError,\n} from \"../errors.js\";\nimport {\n getKernel,\n type Kernel,\n} from \"../backend/kernel.js\";\nimport { Long } from \"../long.js\";\nimport { HI, LO, S_U32, splitI64, splitU64 } from \"../varint/bits64.js\";\nimport {\n encodeVarintLoHi,\n encodeVarintNum,\n varintSizeLoHi,\n varintSizeNum,\n} from \"../varint/leb128.js\";\nimport {\n fp32Bits,\n fp64BitsHi,\n fp64BitsLo,\n packFp32,\n packFp64,\n toBigInt,\n} from \"../varint/num64.js\";\nimport { encodeZigzagVarintLoHi } from \"../varint/zigzag.js\";\nimport { type ByteSink, utf8Length, utf8Write, utf8WriteSink } from \"./fixlen.js\";\nimport type { FlushSink } from \"./sink.js\";\n\n/**\n * Largest magnitude a signed scalar takes on the number fast path: its zig-zag\n * image (`|v| * 2`) must stay an exact integer, i.e. `≤ 2^53`.\n */\nconst SIGNED_FAST_MAX = 0x10_0000_0000_0000; // 2^52\n\n/**\n * Validate a caller-supplied output buffer *where it is handed over* — at\n * construction and at every mid-stream {@link OStream.setBuffer} (CORELIB_PLAN\n * §5.1). The offset must land inside the buffer, and, **only** when a flush sink\n * is installed, the usable window must be at least {@link MIN_OUTPUT_BUFFER}\n * bytes: a streaming buffer that cannot take a single byte would otherwise fail\n * partway through a message via the buffer-full path instead of here. Without a\n * sink there is no minimum — no flush can occur, so nothing can be split, and\n * the exact-`MAX_SIZE` case must stay exact.\n */\nfunction checkHandover(\n buffer: Uint8Array,\n offset: number,\n streaming: boolean,\n carried: number,\n): void {\n if (offset < 0 || offset > buffer.length) {\n throw argumentError(`offset ${offset} out of range`);\n }\n if (!Number.isInteger(carried) || carried < 0 || carried > offset) {\n throw argumentError(`carried ${carried} out of range 0..${offset}`);\n }\n if (streaming && buffer.length - offset < MIN_OUTPUT_BUFFER) {\n throw argumentError(\n `output buffer with a flush sink has ${buffer.length - offset} usable ` +\n `byte(s), below MIN_OUTPUT_BUFFER (${MIN_OUTPUT_BUFFER})`,\n );\n }\n}\n\n/**\n * Encoder for the SofaBuffers wire format. Each `write*` method appends one\n * field and maps one-to-one onto a wire type. It writes into the buffer the\n * caller supplies and into no other: it allocates none of its own, grows\n * none it was given, and has no hook through which anything else could grow one\n * for it (CORELIB_PLAN §5.1.2, §6.6). Hand it a buffer that holds the whole\n * message, or one that drains to a {@link FlushSink} as it fills so the message\n * can outgrow it. Invalid arguments and a full buffer with no sink throw\n * {@link SofabError}. To let the buffer follow the message instead, encode into\n * the accumulator `growingOStream` builds — a helper over the streaming mode,\n * not a mode of this class.\n */\nexport class OStream implements ByteSink {\n private buf: Uint8Array;\n private pos: number;\n /**\n * Where the **current flush unit** begins in {@link buf}: the first byte the\n * next {@link flush} hands to the sink.\n */\n private start: number;\n /**\n * Where the **message so far** begins in {@link buf} — what {@link bytes} and\n * {@link bytesUsed} report from.\n *\n * Equal to {@link start} for every ordinary stream, and the two move together:\n * what has not been flushed is the whole of what is still in the buffer. They\n * part only when a caller installs a replacement that **already holds** the\n * earlier bytes of this message (`setBuffer`'s `carried` argument) — the shape\n * an accumulating caller uses, where each new window opens after the bytes the\n * previous one left behind in the same storage. Keeping the two apart is what\n * lets that caller be an ordinary sink (§5.1.5) instead of a growth hook\n * inside the encoder (§6.6).\n */\n private origin: number;\n private readonly flushSink: FlushSink | undefined;\n private depth = 0;\n /**\n * Ids of the innermost open sequences whose header has not been written yet\n * (MESSAGE_SPEC §2 lazy framing, {@link OStream.writeSequenceBeginLazy}).\n * Always a contiguous suffix of the open sequences: writing any field commits\n * the whole run at once, so {@link OStream.writeSequenceEnd} can drop the\n * innermost one by dropping the last entry. Held-back ids are encoder state,\n * never buffer content, so a flush can never split a run.\n *\n * Storage plus an explicit count rather than `push`/`pop`, so the slots are\n * reused across messages and so {@link OStream.commitPending} can zero the\n * count *before* it writes.\n *\n * **Fixed size, sized at construction** from `MAX_DEPTH` — the \"fixed-size\n * state whose size this document fixes\" of CORELIB_PLAN §6.6.2, and the shape\n * §6.0.1 asks for: the run covers the full depth, so it is always a contiguous\n * suffix of the open sequences, every sequence stays canonical however deep it\n * nests, and there is no eager-framing fallback. Nothing is allocated per\n * message, per field or per sequence.\n *\n * A plain array rather than an `Int32Array`: a 255-slot typed array is an\n * external backing store on V8 (~3.1 µs to allocate on Node 24, against ~5 ns\n * for this), and an encoder is constructed per message on the accumulator path.\n * Slots are written before they are read, so it is never read holey.\n */\n private readonly pending: number[];\n /** Valid entries in {@link OStream.pending}. */\n private nPending = 0;\n /**\n * How many buffer installations {@link OStream.setBuffer} has made. Only ever\n * compared for equality across the flush callback, which is how\n * {@link OStream.flush} tells \"the sink copied and returned\" from \"the sink\n * took the buffer and installed a replacement\" — the one distinction §5.1\n * rests the handover contract on, and the one that decides whether the start\n * offset was consumed or re-armed.\n */\n private installs = 0;\n private readonly kernel: Kernel;\n\n /**\n * Encoder over a caller buffer, optionally draining to `flush` as it fills.\n *\n * Those are the only two buffer models there are (CORELIB_PLAN §5.1.1): the\n * buffer the caller hands over, and whatever a sink installs in its place\n * (§5.1.5). There is no third parameter through which the encoder could be\n * given something to enlarge — growing a destination from a write path is what\n * §6.6's second violation row names, whoever owns the allocator.\n *\n * Constructing one is the only allocating step (§6.6): it sizes the hold-back\n * run from `MAX_DEPTH` and reads the active kernel once. No `write*` call after\n * that allocates anything.\n */\n constructor(buffer: Uint8Array, offset = 0, flush?: FlushSink) {\n this.kernel = getKernel();\n this.pending = new Array<number>(MAX_DEPTH);\n checkHandover(buffer, offset, flush !== undefined, 0);\n this.buf = buffer;\n this.start = offset;\n this.origin = offset;\n this.pos = offset;\n this.flushSink = flush;\n }\n\n /** Bytes of the message currently held in the buffer (see {@link bytes}). */\n get bytesUsed(): number {\n return this.pos - this.origin;\n }\n\n /**\n * The encoded message so far, as a view into the working buffer: everything\n * written since construction, the last {@link reset}, or the last flush the\n * sink returned from without installing a buffer. With a flush sink that is\n * normally only the not-yet-flushed tail; on a stream whose sink hands back a\n * replacement carrying the earlier bytes — the accumulator `growingOStream`\n * builds — it is the whole message. The view is valid until the next write.\n */\n bytes(): Uint8Array {\n return this.buf.subarray(this.origin, this.pos);\n }\n\n /**\n * Drain buffered bytes to the flush sink (no-op without one).\n *\n * A sink that returns **without** installing a buffer has copied what it was\n * handed, so the encoder keeps writing into the same buffer — resuming at\n * offset **0**. The start offset belongs to the *installation*, not to the\n * buffer (CORELIB_PLAN §5.1): the buffer-set that armed it — the constructor\n * or {@link OStream.setBuffer} — reserved room in the unit it began, and\n * handing that unit over consumes the reservation. A sink that wants header\n * room in *every* unit re-arms it by calling `setBuffer(buf, offset)` from\n * inside the callback, a new installation like any other; a bare return must\n * not do it implicitly, or the leading bytes would be capacity the rest of the\n * stream could never use and the two shapes would be indistinguishable.\n */\n flush(): void {\n this.drain(0);\n }\n\n /**\n * {@link flush}, plus the number of contiguous bytes the caller wants at the\n * cursor afterwards — `0` when it wants none in particular.\n *\n * Split out from the public `flush` so the figure cannot be invented by a\n * caller: it is the encoder's own reserve request, and a sink that sizes a\n * replacement from it (`growingOStream`) has to be able to trust it. Everything\n * else is identical, including that a sink which returns without installing has\n * *copied* and the cursor resumes at `0`.\n */\n private drain(needed: number): void {\n if (this.flushSink && this.pos > this.start) {\n const installed = this.installs;\n // The installed buffer itself, with the region's coordinates — never a view\n // this encoder built (§6.6: no allocation after construction) and never\n // memory from anywhere else (§5.1.6: pass-through is forbidden).\n //\n // Called as a **method of this stream**, deliberately: a sink written as a\n // plain function then receives the encoder as `this`, which is how\n // `growingOStream` (`./accumulate.ts`) ships a stateless module-level sink\n // and allocates nothing per stream. Hoisting `this.flushSink` into a local\n // here would silently take that away — `test/buffer-ownership.test.ts`\n // pins the receiver.\n this.flushSink(this.buf, this.start, this.pos, needed);\n // A `setBuffer` from inside the callback *is* the new installation and has\n // already placed the cursor at its own offset; only a bare return leaves\n // the old installation in place, and that one is the consumed case.\n if (this.installs === installed) {\n this.start = 0;\n this.origin = 0;\n this.pos = 0;\n }\n }\n }\n\n /**\n * Install a fresh output buffer to write into, mid-stream. Intended for the\n * streaming (flush-sink) mode: call it from inside your flush callback to hand\n * the encoder a new buffer for the next batch of bytes, so encoding continues\n * without interruption. `offset` reserves space at the front of the new\n * buffer. Any not-yet-flushed bytes in the old buffer are dropped, so\n * {@link flush} first (the flush callback fires before you swap).\n *\n * Every call is a **new installation**, and its `offset` applies to the unit\n * it begins and is consumed when that unit is flushed (CORELIB_PLAN §5.1).\n * Passing the buffer the encoder already has is an installation like any\n * other: that is how a sink gets header room in *every* flushed unit — one\n * framing header per packet — where returning bare would resume at `0`.\n *\n * On a stream that has a flush sink the new buffer must leave at least\n * {@link MIN_OUTPUT_BUFFER} usable bytes (`buffer.length - offset`); a smaller\n * one is rejected here, with {@link SofabErrorCode.Argument}, leaving the\n * encoder on the buffer it already had. A sink-less stream has no minimum.\n *\n * `carried` says how many bytes **immediately before `offset`** the\n * replacement already holds of *this* message — normally `0`, because a fresh\n * buffer holds none. A caller that keeps the whole message in one growing\n * store passes the length it copied across, so {@link bytes} keeps reporting\n * the message rather than only the piece written after the swap. It changes\n * nothing on the wire and nothing about flushing: the next flush still begins\n * at `offset`. `growingOStream` is the caller this exists for; it is the\n * §5.1.5 handover, not a growth hook inside the encoder (§6.6).\n *\n * The accumulating stream `growingOStream` builds is an ordinary streaming\n * stream, so this works on it too, and means exactly what it means anywhere\n * else: the not-yet-flushed bytes in the old buffer are dropped, encoding\n * continues into yours, and its sink takes over growing *that* one from the\n * next flush — reserve offset included, since what it copies out is the\n * message rather than the buffer. Encode into a plain\n * `new OStream(buffer, offset, flush?)` to keep the buffer yours instead.\n */\n setBuffer(buffer: Uint8Array, offset = 0, carried = 0): void {\n checkHandover(buffer, offset, this.flushSink !== undefined, carried);\n this.buf = buffer;\n this.start = offset;\n this.origin = offset - carried;\n this.pos = offset;\n // Counted *after* the checks: a rejected buffer is not an installation, and\n // a flush in progress must still see the one it handed over (§5.1).\n this.installs++;\n }\n\n /**\n * Rewind the encoder to empty, reusing the existing buffer. Lets a caller pool\n * one OStream across many messages instead of allocating a fresh buffer per\n * encode. Any view previously returned by {@link bytes} is invalidated.\n */\n reset(): void {\n this.pos = this.origin;\n this.start = this.origin;\n this.depth = 0;\n this.nPending = 0;\n }\n\n // --- scalars ------------------------------------------------------------\n\n /** Write an unsigned integer field. */\n writeUnsigned(id: number, value: number | bigint): void {\n // Fast path: a small non-negative integer never touches bigint.\n if (typeof value === \"number\" && value >= 0 && value <= Number.MAX_SAFE_INTEGER && Number.isInteger(value)) {\n this.header(id, WireType.Unsigned);\n this.putVarintNum(value);\n return;\n }\n const v = toBigInt(value);\n // splitU64 range-checks *and* splits in one store/load pair: the round-trip\n // through the unsigned 64-bit scratch differs from the input exactly when\n // the input was negative or ≥ 2^64 (bits64). The halves must be copied out\n // before `header` runs, because a flush sink it may reach is caller code\n // that can re-enter this encoder and overwrite the shared scratch.\n if (!splitU64(v)) throw argumentError(`unsigned value ${v} out of 64-bit range`);\n const lo = S_U32[LO]!;\n const hi = S_U32[HI]!;\n this.header(id, WireType.Unsigned);\n this.putVarintLoHi(lo, hi);\n }\n\n /** Write a signed integer field (zig-zag encoded). */\n writeSigned(id: number, value: number | bigint): void {\n // Fast path: a small-magnitude integer zig-zags within number precision.\n if (typeof value === \"number\" && value >= -SIGNED_FAST_MAX && value <= SIGNED_FAST_MAX && Number.isInteger(value)) {\n this.header(id, WireType.Signed);\n this.putVarintNum(value >= 0 ? value * 2 : -value * 2 - 1);\n return;\n }\n const v = toBigInt(value);\n // As in writeUnsigned, the signed scratch round-trip is both the `inI64`\n // range check and the split; the halves are read out before `header`.\n if (!splitI64(v)) throw argumentError(`signed value ${v} out of 64-bit range`);\n const lo = S_U32[LO]!;\n const hi = S_U32[HI]!;\n // Zig-zag on the halves — `(n << 1) ^ (n >> 63)` widened across both — so\n // the varint goes out at its exact size (a fixed caller buffer must not see\n // a 10-byte demand for a 2-byte field).\n const sgn = -(hi >>> 31) >>> 0;\n const zLo = (((lo << 1) >>> 0) ^ sgn) >>> 0;\n const zHi = ((((hi << 1) | (lo >>> 31)) >>> 0) ^ sgn) >>> 0;\n this.header(id, WireType.Signed);\n this.putVarintLoHi(zLo, zHi);\n }\n\n /**\n * Write an unsigned 64-bit scalar from a {@link Long} — the `bigint`-free twin\n * of {@link writeUnsigned}, and the scalar counterpart of\n * {@link writeUnsignedArrayLong}. Produces the identical wire.\n *\n * There is no range check and no scratch round-trip: a `Long` *is* two 32-bit\n * halves, so it is in the `uint64` domain by construction — which is the whole\n * of what `splitU64` decides for a `number | bigint`. The halves go straight\n * into the varint writer, so nothing is allocated per value. Nothing needs\n * copying out ahead of `header` either, for the same reason the array writers\n * do not: the halves come off a caller-owned immutable `Long`, not the shared\n * scratch a re-entrant flush sink could overwrite.\n */\n writeUnsignedLong(id: number, value: Long): void {\n this.header(id, WireType.Unsigned);\n this.putVarintLoHi(value.low, value.high);\n }\n\n /**\n * Write a signed 64-bit scalar (zig-zag) from a {@link Long} — the\n * `bigint`-free twin of {@link writeSigned}, and the scalar counterpart of\n * {@link writeSignedArrayLong}. Zig-zag `(n << 1) ^ (n >> 63)` is computed on\n * the lo/hi pair, so the varint goes out at its exact size (a fixed caller\n * buffer must not see a 10-byte demand for a 2-byte field) and no `bigint` is\n * created. A `Long` carries exactly 64 bits, so as in {@link writeUnsignedLong}\n * there is nothing left to range-check.\n */\n writeSignedLong(id: number, value: Long): void {\n this.header(id, WireType.Signed);\n this.putZigzagVarintLoHi(value.low, value.high);\n }\n\n /** Write a boolean field (encoded as the unsigned value 0 or 1). */\n writeBoolean(id: number, value: boolean): void {\n this.header(id, WireType.Unsigned);\n this.putVarintNum(value ? 1 : 0);\n }\n\n /** Write an IEEE-754 32-bit float field. */\n writeFp32(id: number, value: number): void {\n this.fixlenHead(id, 4, FixlenSubtype.Fp32);\n this.putFp32(value);\n }\n\n /**\n * Write an fp32 field from its raw wire bits — the 4 little-endian payload\n * bytes as one 32-bit word, which is exactly what {@link Visitor.fp32} delivers\n * as `bits`.\n *\n * This is the re-encode half of the bit-exactness rule (CORELIB_PLAN §6.5). A JS\n * `number` is a 64-bit double, and widening an fp32 **signaling** NaN into one\n * quiets it, so re-encoding through {@link writeFp32} cannot reproduce such a\n * payload; the bits go out verbatim here, so decode → re-encode is byte-for-byte\n * for every fp32 value, sNaN included. §6.5 requires this path of every\n * double-only target, and names it: \"a 32-bit bits accessor\".\n */\n writeFp32Bits(id: number, bits: number): void {\n this.fixlenHead(id, 4, FixlenSubtype.Fp32);\n this.putFp32Bits(bits >>> 0);\n }\n\n /** Write an IEEE-754 64-bit double field. */\n writeFp64(id: number, value: number): void {\n this.fixlenHead(id, 8, FixlenSubtype.Fp64);\n this.putFp64(value);\n }\n\n /** Write a UTF-8 string field. */\n writeString(id: number, text: string): void {\n // Fast path: scan the UTF-8 byte length, write the fixlen header, then encode\n // the characters straight into the output buffer. This skips\n // `TextEncoder.encode`'s per-call setup + throwaway array + second copy — the\n // encoder's dominant cost on string-heavy messages. It needs the payload to\n // fit contiguously where the cursor stands, which {@link reserveBulk}\n // answers for *any* buffer; where it does not, the chunk-draining `writeRaw`\n // route below takes over, needing no contiguous room at all.\n //\n // Pure ASCII — the overwhelmingly common case for keys, identifiers and\n // short text — needs neither of the general helpers: the UTF-8 byte length\n // is the character count, so the header can go out after one scan and the\n // payload is a straight character-to-byte copy. `utf8Length` / `utf8Write`\n // below remain the single implementation of everything else, including all\n // surrogate handling; this only short-circuits the case where both of them\n // would reduce to exactly this loop.\n const n = text.length;\n let a = 0;\n while (a < n && text.charCodeAt(a) < 0x80) a++;\n if (a === n) {\n if (n > FIXLEN_MAX) {\n throw argumentError(`fixlen length ${n} exceeds ${FIXLEN_MAX}`);\n }\n this.fixlenHead(id, n, FixlenSubtype.String);\n if (this.reserveBulk(n)) {\n const buf = this.buf;\n const p = this.pos;\n for (let k = 0; k < n; k++) buf[p + k] = text.charCodeAt(k);\n this.pos = p + n;\n return;\n }\n utf8WriteSink(text, this);\n return;\n }\n\n // Sized (and surrogate-validated) before the header goes out, so an\n // unencodable string still throws with nothing written.\n const byteLen = utf8Length(text);\n if (byteLen > FIXLEN_MAX) {\n throw argumentError(`fixlen length ${byteLen} exceeds ${FIXLEN_MAX}`);\n }\n this.fixlenHead(id, byteLen, FixlenSubtype.String);\n if (this.reserveBulk(byteLen)) {\n this.pos = utf8Write(text, this.buf, this.pos);\n return;\n }\n // Buffer too narrow to take the payload in one piece: emit it byte by byte,\n // draining the sink in between (§5.1.3 — a payload run is divisible at any\n // byte). Encoding *through* the byte writer rather than into a throwaway\n // array is what keeps this path allocation-free (§6.6).\n utf8WriteSink(text, this);\n }\n\n /** Write a blob (arbitrary bytes) field. */\n writeBlob(id: number, data: Uint8Array): void {\n this.writeFixlen(id, data, FixlenSubtype.Blob);\n }\n\n /**\n * Write a fixed-length field of the given subtype from raw bytes.\n *\n * This is the byte-level entry point — the one writer that takes the subtype\n * from the caller rather than picking it — so the payload is checked\n * **against that subtype** before a byte is written, and it cannot emit a\n * `fixlen_word` a conformant decoder must reject (`ARGUMENT`, §6.3):\n *\n * * subtypes `0x4`–`0x7` are **reserved** — a decoder must treat a field\n * carrying one as malformed (`INVALID`, §4.6/§5.2);\n * * `Fp32` / `Fp64` payloads are **exactly** 4 / 8 bytes — any other declared\n * length for those subtypes is malformed, rejected the moment the word is\n * read (§4.6);\n * * `String` / `Blob` take any length up to `FIXLEN_MAX`.\n *\n * The typed writers ({@link writeFp32}, {@link writeFp64},\n * {@link writeString}) are correct by construction and go straight to the\n * header; only {@link writeBlob}, whose subtype is unconstrained anyway,\n * shares this path.\n */\n writeFixlen(id: number, data: Uint8Array, subtype: FixlenSubtype): void {\n // One predicted-false unsigned compare folds \"reserved\" and \"negative\" into\n // a single test; the integer check (also what rules out `NaN`, which\n // `>>> 0` turns into 0) rides on its short-circuit.\n if ((subtype as number) >>> 0 > FixlenSubtype.Blob || !Number.isInteger(subtype)) {\n throw argumentError(`fixlen subtype ${subtype} is reserved (§4.6: 0x0..0x3)`);\n }\n if (subtype === FixlenSubtype.Fp32 || subtype === FixlenSubtype.Fp64) {\n const want = subtype === FixlenSubtype.Fp32 ? 4 : 8;\n if (data.length !== want) {\n throw argumentError(\n `fixlen ${subtype === FixlenSubtype.Fp32 ? \"fp32\" : \"fp64\"} payload must be ` +\n `exactly ${want} bytes, got ${data.length}`,\n );\n }\n } else if (data.length > FIXLEN_MAX) {\n throw argumentError(`fixlen length ${data.length} exceeds ${FIXLEN_MAX}`);\n }\n this.fixlenHead(id, data.length, subtype);\n this.writeRaw(data);\n }\n\n // --- arrays -------------------------------------------------------------\n\n /**\n * Write an array of unsigned integers (each a varint).\n *\n * **The bulk kernel writes a whole array in one pass and cannot flush**, so it\n * runs only where everything is known to fit. Three cases, and none of them\n * asks the source how wide its elements are:\n *\n * * **block mode** (no sink) — the buffer is meant to hold the whole message,\n * so the kernel always runs and the buffer's length is the bound, checked\n * after the fact. A message that does not fit is `BUFFER_FULL`, which is\n * precisely this mode's answer.\n * * **a stream with room** — `VARINT_MAX_BYTES` per element is the true\n * worst case for any 64-bit value, and a *growing* stream always satisfies\n * it because it grows to whatever is asked.\n * * **a chunk too small for that** — fill it to the last byte, hand it over,\n * carry on, splitting an element where it falls. That is not a fallback but\n * the mode's contract: `MIN_OUTPUT_BUFFER` is 1.\n *\n * What is gone is the fourth case, which asked `values.constructor` for a\n * narrower bound so the kernel would run on a tightly-sized chunk. `constructor`\n * is an ordinary property, an `ArrayLike` can claim any width, and a wrong\n * answer silently truncated the message — §5.1's \"partial output handed back as\n * complete\". The block mode now reaches the kernel without needing the number\n * at all, which is where a tightly-sized buffer actually lives.\n */\n writeUnsignedArray(id: number, values: ArrayLike<number | bigint>): void {\n this.arrayHead(id, WireType.ArrayUnsigned, values.length);\n if (this.flushSink === undefined) {\n // Block mode: the buffer is meant to hold the whole message, so the kernel\n // always runs and the buffer's own length is the only bound — checked once,\n // after, where a message that does not fit is exactly what BUFFER_FULL means.\n this.pos = this.bulkEnd(\n this.kernel.encodeUnsignedVarints(values, this.buf, this.pos),\n values.length,\n );\n } else if (this.reserveBulk(values.length * VARINT_MAX_BYTES)) {\n // A sink, but room for the element's TRUE worst case — which is what a\n // growing stream always has, since it grows to whatever is asked. The bound\n // is arithmetic, not a guess about the source.\n this.pos = this.kernel.encodeUnsignedVarints(values, this.buf, this.pos);\n } else {\n // Streaming (fixed caller buffer): each element is range-checked and\n // split by the same single scratch round-trip the scalar writers use, and\n // the halves are read out before `putVarintLoHi` — which may reach a flush\n // sink, i.e. caller code that can re-enter and overwrite the scratch\n // (bits64).\n for (let i = 0; i < values.length; i++) {\n const v = toBigInt(values[i]!);\n if (!splitU64(v)) throw argumentError(`unsigned value ${v} out of range`);\n const lo = S_U32[LO]!;\n const hi = S_U32[HI]!;\n this.putVarintLoHi(lo, hi);\n }\n }\n }\n\n /** Write an array of signed integers (each zig-zag + varint). See {@link writeUnsignedArray}. */\n writeSignedArray(id: number, values: ArrayLike<number | bigint>): void {\n this.arrayHead(id, WireType.ArraySigned, values.length);\n if (this.flushSink === undefined) {\n // Block mode: the buffer is meant to hold the whole message, so the kernel\n // always runs and the buffer's own length is the only bound — checked once,\n // after, where a message that does not fit is exactly what BUFFER_FULL means.\n this.pos = this.bulkEnd(\n this.kernel.encodeSignedVarints(values, this.buf, this.pos),\n values.length,\n );\n } else if (this.reserveBulk(values.length * VARINT_MAX_BYTES)) {\n // A sink, but room for the element's TRUE worst case — which is what a\n // growing stream always has, since it grows to whatever is asked. The bound\n // is arithmetic, not a guess about the source.\n this.pos = this.kernel.encodeSignedVarints(values, this.buf, this.pos);\n } else {\n // See writeUnsignedArray: range-check and split in one round-trip, halves\n // out before the write, then zig-zag on the halves rather than in\n // `bigint`.\n for (let i = 0; i < values.length; i++) {\n const v = toBigInt(values[i]!);\n if (!splitI64(v)) throw argumentError(`signed value ${v} out of range`);\n this.putZigzagVarintLoHi(S_U32[LO]!, S_U32[HI]!);\n }\n }\n }\n\n /**\n * Write an unsigned 64-bit array from {@link Long}[] — the `bigint`-free path.\n * Produces the identical wire to {@link writeUnsignedArray}; reads each Long's\n * 32-bit halves directly, so no `bigint` is created per element.\n */\n writeUnsignedArrayLong(id: number, values: readonly Long[]): void {\n this.arrayHead(id, WireType.ArrayUnsigned, values.length);\n if (this.reserveBulk(values.length * VARINT_MAX_BYTES)) {\n // One contiguous reserve, then a flat loop over a buffer that cannot move.\n let pos = this.pos;\n const buf = this.buf;\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n pos = encodeVarintLoHi(v.low, v.high, buf, pos);\n }\n this.pos = pos;\n } else {\n // Streaming (fixed caller buffer): reserve one element at a time so the\n // sink drains between elements — the whole point of a fixed buffer is that\n // the array may be far larger than it. Reserving the array's worst case\n // (10 bytes × length) as one contiguous run instead made a 64-bit array\n // unstreamable, and threw *after* arrayHead, leaving a header with no\n // payload (corelib-ts#91). The halves come off the caller's Long before\n // the write, since a flush reaches sink code that could re-enter.\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n this.putVarintLoHi(v.low, v.high);\n }\n }\n }\n\n /**\n * Write a signed 64-bit array (zig-zag) from {@link Long}[] — the `bigint`-free\n * path. Zig-zag `(n << 1) ^ (n >> 63)` is computed on the lo/hi pair.\n */\n writeSignedArrayLong(id: number, values: readonly Long[]): void {\n this.arrayHead(id, WireType.ArraySigned, values.length);\n if (this.reserveBulk(values.length * VARINT_MAX_BYTES)) {\n let pos = this.pos;\n const buf = this.buf;\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n pos = encodeZigzagVarintLoHi(v.low, v.high, buf, pos);\n }\n this.pos = pos;\n } else {\n // See writeUnsignedArrayLong: one element at a time so the sink drains\n // between them, halves read out before a flush can re-enter.\n for (let i = 0; i < values.length; i++) {\n const v = values[i]!;\n this.putZigzagVarintLoHi(v.low, v.high);\n }\n }\n }\n\n /** Write an array of IEEE-754 32-bit floats. */\n writeFp32Array(id: number, values: ArrayLike<number>): void {\n // A Float32Array holds the wire words already, and reading them as numbers\n // would quiet a signaling NaN (§6.5), so it takes a route that copies words\n // on every path, streamed included (corelib-ts#185). Split off here, at the\n // entry, rather than as a branch beside the number loop below: an inlined\n // `instanceof` has a runtime-call slow path, and past it TurboFan no longer\n // trusts the maps it knew, so that loop re-checked `values` and `this` and\n // reloaded both lengths on every element — +12% Ir with the branch empty.\n if (values instanceof Float32Array) {\n this.writeFp32Words(id, values);\n return;\n }\n this.arrayHead(id, WireType.ArrayFixlen, values.length);\n // A fixlen array always carries its fixlen_word — even when empty (§4.8) —\n // so an empty fp32 array stays distinct from an empty fp64 one. The payload\n // loop below simply runs zero times: the field is [ header ][ count = 0 ]\n // [ fixlen_word ] with no elements.\n this.putVarintNum(4 * 8 + FixlenSubtype.Fp32);\n if (this.reserveBulk(values.length * 4)) {\n this.pos = this.kernel.packFp32Array(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) this.putFp32(values[i]!);\n }\n }\n\n /**\n * Write an fp32 array from its raw little-endian element payload. The bytes\n * are emitted verbatim — no per-element `setFloat32` — so a signaling NaN\n * survives bit-for-bit (§4.6), which {@link writeFp32Array} cannot guarantee\n * because it re-quantizes each JS `number`. `payload.length` must be a\n * multiple of 4; the element count is `payload.length / 4`.\n */\n writeFp32ArrayRaw(id: number, payload: Uint8Array): void {\n if ((payload.length & 3) !== 0) {\n throw argumentError(\n `fp32 array payload length ${payload.length} is not a multiple of 4`,\n );\n }\n this.arrayHead(id, WireType.ArrayFixlen, payload.length >> 2);\n this.putVarintNum(4 * 8 + FixlenSubtype.Fp32);\n this.writeRaw(payload);\n }\n\n /** Write an array of IEEE-754 64-bit doubles. */\n writeFp64Array(id: number, values: ArrayLike<number>): void {\n this.arrayHead(id, WireType.ArrayFixlen, values.length);\n // A fixlen array always carries its fixlen_word — even when empty (§4.8) —\n // so an empty fp64 array stays distinct from an empty fp32 one. The payload\n // loop below simply runs zero times: the field is [ header ][ count = 0 ]\n // [ fixlen_word ] with no elements.\n this.putVarintNum(8 * 8 + FixlenSubtype.Fp64);\n if (this.reserveBulk(values.length * 8)) {\n this.pos = this.kernel.packFp64Array(values, this.buf, this.pos);\n } else {\n for (let i = 0; i < values.length; i++) this.putFp64(values[i]!);\n }\n }\n\n // --- sequences ----------------------------------------------------------\n\n /**\n * Open a nested sequence (a fresh id scope) whose header is **held back**\n * until the sequence turns out to have content.\n *\n * MESSAGE_SPEC §2 omits a sequence-typed field whose value equals its declared\n * default, and \"not one child was written\" is exactly that condition —\n * evaluated per child field, recursively, for free, because the message layer\n * already omits every child equal to its default. A sequence closed with\n * nothing in it therefore emits **nothing** instead of a two-byte empty frame,\n * and an all-default message becomes the empty byte string. No byte image is\n * ever compared, so in-memory layout never enters the decision.\n *\n * This is the only way to open a sequence. How it closes decides whether a\n * contentless one survives: {@link OStream.writeSequenceEnd} drops it,\n * {@link OStream.writeSequenceEndKeep} forces the frame out.\n */\n writeSequenceBeginLazy(id: number): void {\n // §4.9/§6.2: refuse to open more than MAX_DEPTH nested sequences. This is a\n // bound on a caller-supplied value, so it reports Argument — the category\n // the C and Java ports use for the same check.\n if (this.depth >= MAX_DEPTH) {\n throw argumentError(`nesting exceeds MAX_DEPTH (${MAX_DEPTH})`);\n }\n // Validate here, not at commit time: the header may never be written, and a\n // bad id must still be rejected at the call that supplied it. (Same cheap\n // integer/range test as `header`.)\n if (id >>> 0 !== id || id > ID_MAX) {\n throw argumentError(`field id ${id} out of range 0..${ID_MAX}`);\n }\n // The run covers the full MAX_DEPTH (see `pending`), so it is *always* a\n // contiguous suffix of the open sequences and every sequence stays canonical\n // however deep it nests — what CORELIB_PLAN §6.0.1 (\"How deep the hold-back\n // reaches\") requires. No eager-framing fallback, and no allocation.\n this.pending[this.nPending++] = id;\n this.depth++;\n }\n\n /**\n * Close the current sequence, letting it **vanish** if it received no content.\n *\n * Use it wherever absence encodes the same value as an empty frame: a\n * `struct`/`union` field, and an array field whose declared `default` is the\n * empty collection (MESSAGE_SPEC §2). Where the frame must be visible, close\n * with {@link OStream.writeSequenceEndKeep} instead.\n *\n * An end with no matching begin is not rejected: the encoder writes what it is\n * told, and the resulting bytes are then malformed, which is the decoder's\n * verdict to make. No other port refuses it. The depth counter stops at zero\n * so the MAX_DEPTH check on begin cannot be fooled by an underflow.\n */\n writeSequenceEnd(): void {\n if (this.nPending !== 0) {\n // The innermost open sequence is the last held-back one (the run is a\n // suffix of the open sequences), and it never got content: drop it —\n // header and end marker both.\n this.nPending--;\n if (this.depth > 0) this.depth--;\n return;\n }\n this.ensure(1);\n this.buf[this.pos++] = WireType.SequenceEnd; // id 0, type 7 -> byte 0x07\n if (this.depth > 0) this.depth--;\n }\n\n /**\n * Close the current sequence, **keeping** its frame even when it received no\n * content.\n *\n * Behaves like a write: it first emits any held-back headers — this frame's\n * and every enclosing one's — and then the end marker, so an empty sequence\n * reaches the wire as `begin` + `end`.\n *\n * Required wherever the frame carries information beyond its contents:\n * - a **wrapper-array element** (`struct`/`union`/nested row): element\n * presence is what carries a dynamic array's length — *highest present id +\n * 1* (MESSAGE_SPEC §5.1) — so dropping an all-default element would change\n * the decoded length, not just the bytes;\n * - an array field already known to **differ from a non-empty declared\n * `default`**: absence would reconstruct that default, so the empty frame is\n * the only encoding of \"explicitly empty\" (§2, §3).\n *\n * The two failure directions are not symmetric, which is why this is the safe\n * choice when in doubt: using it where {@link OStream.writeSequenceEnd} would\n * do costs one non-canonical empty frame that a decoder normalizes away, while\n * the reverse silently changes an array's length.\n */\n writeSequenceEndKeep(): void {\n if (this.nPending !== 0) this.commitPending();\n this.ensure(1);\n this.buf[this.pos++] = WireType.SequenceEnd; // id 0, type 7 -> byte 0x07\n if (this.depth > 0) this.depth--;\n }\n\n // --- internals ----------------------------------------------------------\n\n /** Ensure exactly `value`'s varint size, then write it (number fast path). */\n private putVarintNum(value: number): void {\n // Single-byte fast path. Every value reaching here is non-negative (ids,\n // lengths, counts, zig-zagged scalars, booleans), so `< 0x80` is exactly\n // \"one byte\", and `pos < buf.length` is exactly \"there is room for it\".\n // This is the most-executed line in the encoder — every field header, every\n // fixlen word and every array count goes through it — and it skips the\n // sizing pass, the `ensure` call and the encode call in one test.\n const pos = this.pos;\n if (value < 0x80 && pos < this.buf.length) {\n this.buf[pos] = value;\n this.pos = pos + 1;\n return;\n }\n this.putVarintNumSlow(value);\n }\n\n /**\n * The multi-byte / needs-room tail of {@link putVarintNum}, kept in its own\n * method so the single-byte test above stays small enough for the JIT to\n * inline into every `header` / `fixlenHead` / `arrayHead` call site.\n */\n private putVarintNumSlow(value: number): void {\n if (this.tryEnsure(varintSizeNum(value))) {\n this.pos = encodeVarintNum(value, this.buf, this.pos);\n return;\n }\n // Buffer too small for the whole varint: emit it a byte at a time, draining\n // the sink in between (§5.1). The `% 128` form covers the full 0 .. 2^53\n // domain, unlike the bitwise loop `encodeVarintNum` uses below 2^32.\n while (value > 0x7f) {\n this.putByte((value % 128) | 0x80);\n value = Math.floor(value / 128);\n }\n this.putByte(value);\n }\n\n /**\n * Write a 64-bit value, held as two 32-bit halves, as a varint.\n *\n * Deliberately just a bounds check and two calls: this is what the array\n * loops call per element, and it only pays its way while it is small enough\n * for the JIT to inline. Spelling the drain case out here instead — three\n * more lines — cost 16-19% on an array streamed through a 32/64-byte buffer,\n * where most elements take the fast path and want it inlined.\n */\n private putVarintLoHi(lo: number, hi: number): void {\n if (this.buf.length - this.pos >= VARINT_MAX_BYTES) {\n this.pos = encodeVarintLoHi(lo, hi, this.buf, this.pos);\n return;\n }\n this.putVarintLoHiSlow(lo, hi);\n }\n\n /**\n * A full buffer that is nonetheless wide enough to hold any varint: drain it\n * and retry the worst case, which is exactly what `ensure(VARINT_MAX_BYTES)`\n * did before §5.1 and is still the common streaming case. Sizing the value\n * first instead — the narrow-buffer path in {@link putVarintLoHiTight} — cost\n * +125 instructions on every element of an array streamed through a\n * one-element-wide buffer.\n */\n private putVarintLoHiSlow(lo: number, hi: number): void {\n if (this.buf.length - this.start >= VARINT_MAX_BYTES) {\n this.flush();\n if (this.buf.length - this.pos >= VARINT_MAX_BYTES) {\n this.pos = encodeVarintLoHi(lo, hi, this.buf, this.pos);\n return;\n }\n }\n this.putVarintLoHiTight(lo, hi);\n }\n\n /**\n * Zig-zag {@link putVarintLoHi}: `(n << 1) ^ (n >> 63)` on the halves. Keeps\n * its own worst-case fast path so the signed array loop reaches the combined\n * zig-zag-and-encode writer directly, exactly as it did before; the drain and\n * narrow-buffer cases are the same for both signs, so they are shared.\n */\n private putZigzagVarintLoHi(lo: number, hi: number): void {\n if (this.buf.length - this.pos >= VARINT_MAX_BYTES) {\n this.pos = encodeZigzagVarintLoHi(lo, hi, this.buf, this.pos);\n return;\n }\n const sgn = -(hi >>> 31) >>> 0;\n this.putVarintLoHi(\n (((lo << 1) >>> 0) ^ sgn) >>> 0,\n ((((hi << 1) | (lo >>> 31)) >>> 0) ^ sgn) >>> 0,\n );\n }\n\n /**\n * The narrow-buffer tail of {@link putVarintLoHi}: the buffer could not hold a\n * worst-case varint even empty. Sizing the value exactly keeps such a buffer\n * from flushing for room it does not need; only when it cannot hold the varint\n * *at all* does the value get split across flushes, seven bits at a time.\n */\n private putVarintLoHiTight(lo: number, hi: number): void {\n lo >>>= 0;\n hi >>>= 0;\n if (this.tryEnsure(varintSizeLoHi(lo, hi))) {\n this.pos = encodeVarintLoHi(lo, hi, this.buf, this.pos);\n return;\n }\n for (;;) {\n const more = hi !== 0 || lo > 0x7f;\n this.putByte(more ? (lo & 0x7f) | 0x80 : lo);\n if (!more) return;\n lo = ((lo >>> 7) | (hi << 25)) >>> 0;\n hi >>>= 7;\n }\n }\n\n /**\n * Write the 4 little-endian bytes of an fp32 (§4.6).\n *\n * Through the shared scratch, not a `DataView` over the buffer: building that\n * handle costs ~129 ns against the ~2 ns it saves on one value (§6.6.2 allows the\n * handle, arithmetic forbids it here). The bulk array path amortizes one over the\n * whole run instead — see the kernel.\n */\n private putFp32(value: number): void {\n if (this.buf.length - this.pos >= 4) {\n this.pos = packFp32(this.buf, this.pos, value);\n return;\n }\n this.putFp32Slow(value);\n }\n\n private putFp32Slow(value: number): void {\n if (this.tryEnsure(4)) {\n this.pos = packFp32(this.buf, this.pos, value);\n return;\n }\n // The bytes live in a local word rather than a scratch array, so a flush\n // sink that re-enters the encoder between them cannot overwrite the tail.\n this.putFp32Bits(fp32Bits(value));\n }\n\n /**\n * Write the 4 little-endian bytes of an fp32 held as a 32-bit word (§4.6) — the\n * path {@link OStream.writeFp32Bits} takes, and the tail of\n * {@link OStream.putFp32Slow}.\n */\n private putFp32Bits(bits: number): void {\n if (this.buf.length - this.pos >= 4) {\n const buf = this.buf;\n let p = this.pos;\n buf[p++] = bits & 0xff;\n buf[p++] = (bits >>> 8) & 0xff;\n buf[p++] = (bits >>> 16) & 0xff;\n buf[p++] = bits >>> 24;\n this.pos = p;\n return;\n }\n // Too narrow for four contiguous bytes: split across flushes, byte by byte\n // (this port declares MIN_OUTPUT_BUFFER = 1, so it splits atomic units too).\n this.putByte(bits & 0xff);\n this.putByte((bits >>> 8) & 0xff);\n this.putByte((bits >>> 16) & 0xff);\n this.putByte(bits >>> 24);\n }\n\n /**\n * {@link writeFp32Array} for a `Float32Array` source: its own 32-bit words go\n * out, never a `number`, which is what keeps a signaling NaN intact (§6.5) —\n * on the bulk path (the kernel copies words too) and on the streamed one alike,\n * so a small buffer produces the one-shot bytes (§5.1.4).\n *\n * Kept to the header and the bulk call, the streaming loop in its own method:\n * with the loop in this body an 8-element one-shot array cost +416 Ir/op\n * (+8.8%) over the pre-#185 encoder, split like this +1.1% (Callgrind).\n */\n private writeFp32Words(id: number, values: Float32Array): void {\n this.arrayHead(id, WireType.ArrayFixlen, values.length);\n this.putVarintNum(4 * 8 + FixlenSubtype.Fp32);\n if (this.reserveBulk(values.length * 4)) {\n this.pos = this.kernel.packFp32Array(values, this.buf, this.pos);\n } else {\n this.putFp32Words(values);\n }\n }\n\n /**\n * The streamed half of {@link writeFp32Words}: one `Uint32Array` over the\n * source per call, the same handle the bulk kernel takes (§6.6.2); reading it gives each word's value whatever the\n * host byte order, and the shifts below store it little-endian. The words go\n * out one run per stretch of free buffer, with `buf`/`pos` in locals, and the\n * split points are {@link putFp32}'s: drain when fewer than 4 bytes are free,\n * split an element byte by byte only when the buffer itself is narrower than 4.\n */\n private putFp32Words(values: Float32Array): void {\n const w = new Uint32Array(values.buffer, values.byteOffset, values.length);\n const n = w.length;\n let i = 0;\n while (i < n) {\n if (this.buf.length - this.pos < 4 && !this.tryEnsure(4)) {\n this.putFp32Bits(w[i++]!);\n continue;\n }\n // Re-read after the drain: a sink may have installed another buffer (§5.1.5).\n const buf = this.buf;\n let p = this.pos;\n const end = Math.min(n, i + ((buf.length - p) >> 2));\n for (; i < end; i++) {\n const b = w[i]!;\n buf[p] = b & 0xff;\n buf[p + 1] = (b >>> 8) & 0xff;\n buf[p + 2] = (b >>> 16) & 0xff;\n buf[p + 3] = b >>> 24;\n p += 4;\n }\n this.pos = p;\n }\n }\n\n /** Write the 8 little-endian bytes of an fp64 (§4.6) — see {@link putFp32}. */\n private putFp64(value: number): void {\n if (this.buf.length - this.pos >= 8) {\n this.pos = packFp64(this.buf, this.pos, value);\n return;\n }\n this.putFp64Slow(value);\n }\n\n private putFp64Slow(value: number): void {\n if (this.tryEnsure(8)) {\n this.pos = packFp64(this.buf, this.pos, value);\n return;\n }\n // Both halves are read out *before* the first byte goes out, for the reason\n // in putFp32Slow: a flush between them reaches re-entrant caller code.\n const lo = fp64BitsLo(value);\n const hi = fp64BitsHi(value);\n this.putByte(lo & 0xff);\n this.putByte((lo >>> 8) & 0xff);\n this.putByte((lo >>> 16) & 0xff);\n this.putByte(lo >>> 24);\n this.putByte(hi & 0xff);\n this.putByte((hi >>> 8) & 0xff);\n this.putByte((hi >>> 16) & 0xff);\n this.putByte(hi >>> 24);\n }\n\n /**\n * Append one byte, draining to the sink first when the buffer is full.\n *\n * @internal Public only because {@link utf8WriteSink} writes through it — the\n * narrow-buffer string path (§5.1.3). Not part of the field-writing API.\n */\n putByte(b: number): void {\n if (this.pos === this.buf.length) this.ensureSome(1);\n this.buf[this.pos++] = b;\n }\n\n /**\n * Write a field header, the `(id << 3) | wireType` tag, as a varint.\n *\n * This is the single choke point every field write passes through — the\n * scalar, fixlen, float, string, blob and both array writers all reach the\n * wire through `header` / `fixlenHead` / `arrayHead`, and `fixlenHead` and\n * `arrayHead` are themselves nothing but `header` plus a follow-up varint. So\n * this is also where a held-back sequence run is committed: the field about to\n * be written is content, which means every enclosing sequence is non-default\n * and must be framed after all (MESSAGE_SPEC §2).\n *\n * The only writers that do *not* pass through here are the two sequence\n * closers, which must not commit ({@link OStream.writeSequenceEnd}) or commit\n * explicitly ({@link OStream.writeSequenceEndKeep}), and\n * {@link OStream.writeSequenceBeginLazy}, which writes no byte at all.\n */\n private header(id: number, type: WireType): void {\n // `id >>> 0 !== id` rejects every non-integer, negative and ≥ 2^32 value in\n // one cheap coercion (ToUint32 is exact only on 0 .. 2^32-1 integers), so\n // the remaining bound is the ID_MAX ceiling. Equivalent to the\n // `id < 0 || id > ID_MAX || !Number.isInteger(id)` triple it replaces, minus\n // the `Number.isInteger` call on every field write.\n if (id >>> 0 !== id || id > ID_MAX) {\n throw argumentError(`field id ${id} out of range 0..${ID_MAX}`);\n }\n if (this.nPending !== 0) this.commitPending();\n // (id << 3) | type as a number: id ≤ 2^31-1, so the word stays ≤ 2^34.\n this.putVarintNum(id * 8 + type);\n }\n\n /**\n * Write out the held-back sequence headers, **outermost first**, and clear the\n * run. Runs at most once per non-default sequence, never per field — the cost\n * on the hot path is the single `nPending` test in {@link header}.\n *\n * The count is zeroed before the first byte goes out, so a write re-entered\n * from a flush sink cannot emit the same run twice.\n */\n private commitPending(): void {\n const n = this.nPending;\n // Zero the count *first*, before a single byte is written. Deliberate, and\n // the ordering matters: the writes below can fill the buffer and call the\n // flush sink, which is caller code and may re-enter this encoder (that is\n // what `setBuffer` is for, and a sink is free to write a framing field of\n // its own). A re-entrant `header()` must find an empty run, or it would\n // emit these same ids a second time. The loop counts with the local `n`, so\n // clearing the field does not cut short the run it is already emitting.\n this.nPending = 0;\n const pending = this.pending;\n for (let i = 0; i < n; i++) {\n this.putVarintNum(pending[i]! * 8 + WireType.SequenceStart);\n }\n }\n\n private fixlenHead(id: number, length: number, subtype: FixlenSubtype): void {\n this.header(id, WireType.Fixlen);\n this.putVarintNum(length * 8 + subtype);\n }\n\n private arrayHead(id: number, type: WireType, count: number): void {\n // §4.7/§4.8: element_count range is 0..ARRAY_MAX; a zero-count array is a\n // valid, fully-specified empty array on the wire.\n if (count < 0 || count > ARRAY_MAX) {\n throw argumentError(`array count ${count} out of range 0..${ARRAY_MAX}`);\n }\n this.header(id, type);\n this.putVarintNum(count);\n }\n\n /**\n * Copy `data` out, flushing/growing as needed (large payloads stay chunked).\n *\n * The whole-payload case — the common one, and the only one on a buffer sized\n * from `MAX_SIZE` or on the accumulator — is a single `set` of the caller's\n * array: a `memcpy`, and no view at all.\n *\n * **A payload split across flushes takes a per-piece view: a language-forced\n * handle under CORELIB_PLAN §6.6.2.** `TypedArray.set` is the only `memcpy`\n * this language exposes and it takes a *typed array* as its source, so copying a\n * *range* of one needs a `subarray` — §6.6.2's \"the only way to name a region of\n * the caller's buffer is a wrapper over it\". It has the two properties that\n * clause requires: it carries no message bytes (the storage is the caller's, on\n * both ends) and no wire number sizes it (a handle over a thousand bytes costs\n * what a handle over ten costs). The allocation-free alternative is a byte loop,\n * measured at 358 MB/s against 10,963 MB/s for `set`.\n *\n * It never leaves this method: `set` consumes it and no caller can reach it, so\n * §6.7's ban on exposing a value that outlives its callback is untouched — and so\n * is §5.1.6, which is why the copy happens at all rather than the payload being\n * handed to the sink. §6.6.2 asks the port to make such handles visible rather\n * than invisible: the README itemises it (§9.6) and `heap-free-codec.test.ts`\n * pins its count and kind.\n */\n private writeRaw(data: Uint8Array): void {\n const total = data.length;\n let off = 0;\n while (off < total) {\n const room = this.ensureSome(total - off);\n if (off === 0 && room === total) {\n this.buf.set(data, this.pos);\n } else {\n this.buf.set(data.subarray(off, off + room), this.pos);\n }\n this.pos += room;\n off += room;\n }\n }\n\n /**\n * Make room for `n` contiguous bytes at `pos` if the buffer can hold them at\n * all: `true` when it can (flushing or growing as needed), `false` when a\n * fixed caller buffer is simply smaller than `n` and the value must be split\n * across flushes instead — CORELIB_PLAN §5.1 puts the floor on the output\n * buffer at a single byte, so no write may demand a contiguous run.\n *\n * The one case that still fails is a buffer with no sink to drain to: there is\n * nowhere for a split to put the earlier bytes, so it reports BufferFull here,\n * before anything is written, exactly as {@link ensure} did.\n */\n private tryEnsure(n: number): boolean {\n if (this.buf.length - this.pos >= n) return true;\n this.drain(n);\n if (this.buf.length - this.pos >= n) return true;\n if (this.flushSink === undefined) {\n throw bufferFullError(\n `output buffer full: need ${n} more bytes, have ${this.buf.length - this.pos}`,\n );\n }\n return false;\n }\n\n /**\n * Reserve `n` contiguous bytes for a bulk write — the whole payload of an\n * array or a string, written in one pass into a buffer that cannot move under\n * it. Every caller has an element-at-a-time route to fall back on when this\n * says no, producing the identical bytes, so a `false` here is never an error.\n *\n * The room already at the cursor counts on **any** buffer, which is what makes\n * the one-shot `new OStream(buf)` case — a caller buffer sized from the\n * schema's `MAX_SIZE`, the shape CORELIB_PLAN §5.1 puts first — the fast one:\n * without it a message encoded into a caller's own buffer took `TextEncoder`\n * for every string and the element loop for every array, measured at 1.9 µs\n * against 0.16 µs for the same five-field message.\n *\n * Beyond that room only a **sink** may be asked, and only by draining. Emptying\n * the buffer is the one thing that can produce room without an allocation\n * anywhere (§6.6), and it is legal wherever this is called — every caller has\n * just written a complete header, so the cursor is on a boundary between atomic\n * units (§5.1.3). A sink that installs a larger replacement (§5.1.5) therefore\n * re-opens the bulk route by itself, which is how the accumulating helper keeps\n * it. Nothing is *demanded*: a `false` sends the caller down its\n * element-at-a-time route, which produces the identical bytes, so a fixed\n * buffer too narrow for the worst case never turns into a spurious\n * `BUFFER_FULL`.\n */\n private reserveBulk(n: number): boolean {\n if (this.buf.length - this.pos >= n) return true;\n if (this.flushSink === undefined) return false;\n this.drain(n);\n return this.buf.length - this.pos >= n;\n }\n\n /**\n * Commit the position a bulk kernel returned, in the **block** mode.\n *\n * Nothing reserves room in front of that kernel, and nothing could: the bytes an\n * array takes are only known once it is encoded, and the estimate that used to\n * stand in — the source's own `constructor`, which any object can set — silently\n * truncated the message when it was wrong (§5.1). Here the bound is the buffer's\n * own length, applied afterwards. The varint kernels stop writing at\n * `out.length` and keep counting (see {@link Kernel}), so a `pos` past the end\n * is the exact shortfall and nothing was written outside the buffer.\n *\n * This is the block mode's error and only its: the buffer is meant to hold the\n * whole message, so one that does not fit is exactly what `BUFFER_FULL` means.\n * The streaming mode never gets here, and `BUFFER_FULL` is unreachable there by\n * contract.\n */\n private bulkEnd(pos: number, count: number): number {\n if (pos > this.buf.length) {\n throw bufferFullError(\n `output buffer full: an array of ${count} elements needs ` +\n `${pos - this.buf.length} more bytes`,\n );\n }\n return pos;\n }\n\n /**\n * Ensure `n` contiguous bytes are free at `pos`; returns `pos` for chaining.\n *\n * The only remaining caller is the one-byte sequence-end marker, which is\n * indivisible: there is no smaller piece to split it into, so a buffer that\n * cannot take it has nothing left to report but `BUFFER_FULL`.\n */\n private ensure(n: number): number {\n if (!this.tryEnsure(n)) {\n throw bufferFullError(\n `output buffer full: need ${n} more bytes, have ${this.buf.length - this.pos}`,\n );\n }\n return this.pos;\n }\n\n /** Ensure *some* room (up to `want`); returns how many bytes are available. */\n private ensureSome(want: number): number {\n let room = this.buf.length - this.pos;\n if (room === 0) {\n this.flush();\n room = this.buf.length - this.pos;\n if (room === 0) throw bufferFullError(\"output buffer full\");\n }\n return Math.min(room, want);\n }\n}\n\n/**\n * The most varint bytes ONE element of `values` can take.\n *\n * `VARINT_MAX_BYTES` (10) is the answer for a source whose elements could be any\n * 64-bit value, and for an exactly-sized caller buffer it is the wrong question:\n * a bounded schema sizes that buffer from the element's TRUE maximum (3 bytes for\n * a `u16`), so `count * 10` never fits and the bulk kernel is unreachable for\n * precisely the arrays it would pay on. An exact-width source settles it —\n * `Uint16Array` elements are 0..65535, three varint bytes at most — so the\n * reservation can be the real one and the bulk path becomes reachable.\n *\n * Zig-zag does not widen it: `i16`'s -32768 maps to 65535, the same three bytes.\n */\nfunction maxVarintBytes(values: ArrayLike<unknown>): number {\n switch ((values as object).constructor) {\n case Uint8Array:\n case Int8Array:\n return 2;\n case Uint16Array:\n case Int16Array:\n return 3;\n case Uint32Array:\n case Int32Array:\n return 5;\n default:\n // BigUint64Array / BigInt64Array land here too, and ten is their real\n // answer: a 64-bit element can need every byte.\n return VARINT_MAX_BYTES;\n }\n}\n","/**\n * `growingOStream` — the caller that lets the buffer follow the message.\n *\n * **This is the static helper layer, not the codec** (CORELIB_PLAN §6.6.1). The\n * codec is {@link OStream}: it writes into the buffer it was handed and has no\n * way to enlarge one. Where the schema bounds the message, generated code sizes\n * one buffer from `MAX_SIZE` and a plain `new OStream(buf)` is the whole story.\n * Where it does not, §5.1.2 names exactly one shape for the unbounded case:\n *\n * > Install a scratch buffer **with a sink** that appends into the growing\n * > result; the scratch is subject to `MIN_OUTPUT_BUFFER` like any\n * > sink-installed buffer.\n *\n * That is what this file builds, so neither generated code nor a hand-written\n * one-shot encode has to write it again. The scratch and the result are the same\n * storage: the encoder is installed over the free tail of a buffer this module\n * owns, and when it fills, the flush callback fires, this module enlarges its\n * storage and installs the next tail with {@link OStream.setBuffer} — §5.1.5's\n * taking sink, and §6.6.1's second row, a helper reached from inside a callback\n * the codec made. Because the encoder was writing *into the result all along*,\n * absorbing a flush is one assignment: there is no per-flush copy.\n *\n * The predecessor was a `BufferOwner` hook: the encoder called it from\n * `ensureSome`, i.e. from every `write*`, and kept the buffer it returned. That\n * is §6.6's second violation row — \"the codec allocates nothing itself but\n * requires a growable destination and grows it … it moved the allocator call one\n * type away, where a source-level audit no longer sees it\" — and the hook is gone\n * with it (A2-0159).\n *\n * **No subclass, deliberately.** An `OStream` subclass overriding `bytes()` was\n * the obvious shape and cost 2.3x on `encode: composite`: a program that uses\n * both `growingOStream()` and `new OStream(buf)` would then have two receiver\n * maps at every `os.write*` call site, and V8 stops inlining a polymorphic one.\n * `setBuffer`'s `carried` argument buys the same behaviour with one map and one\n * extra number in the encoder, and a stateless module-level sink keeps the\n * per-stream cost at exactly what it was: one buffer.\n */\n\nimport { argumentError } from \"../errors.js\";\nimport { OStream } from \"./ostream.js\";\nimport type { FlushSink } from \"./sink.js\";\n\n/**\n * Capacity {@link growingOStream} starts from when the caller names none. Only a\n * starting point: the accumulator enlarges itself as the message grows, so this\n * trades an initial allocation against the number of enlargements, and decides\n * nothing about the bytes. A caller that knows roughly how big its message is\n * passes that instead and pays for one allocation.\n */\nconst DEFAULT_CAPACITY = 256;\n\n/**\n * Smallest free tail the accumulator will install. Any value at or above\n * `MIN_OUTPUT_BUFFER` is correct — the encoder splits every atomic unit — so\n * this only keeps `growingOStream(1)` from flushing once per byte until the\n * geometric growth takes over.\n */\nconst MIN_WINDOW = 16;\n\n/**\n * Bytes per slab the accumulator carves its buffers out of (see\n * {@link accumulatorBuffer}). Node's own `Buffer.allocUnsafe` pool is 8 KiB for\n * the same reason and the same trade-off.\n */\nconst SLAB_BYTES = 8192;\n\n/**\n * The largest buffer taken from a slab. Half a slab, so a carve can never leave\n * most of a fresh slab unusable, and a request bigger than this gets storage of\n * its own — where one allocation per message is amortised by the message anyway.\n */\nconst SLAB_MAX_TAKE = SLAB_BYTES >>> 1;\n\nlet slab: Uint8Array | null = null;\n/** How much of {@link slab} has been handed out; never given back. */\nlet slabUsed = 0;\n\n/**\n * Storage for the accumulator {@link growingOStream} builds: `n` bytes, carved\n * from a shared slab.\n *\n * V8 keeps a typed array's bytes inside the JS heap only up to **64 bytes**; one\n * byte more and the backing store is an external allocation, which on Node 24\n * measures ~1.4 µs — against ~60 ns for a slab carve, and against the ~300 ns it\n * takes to *encode* a small message. That single allocation was 45% of the\n * profile of `encode: typical message` and the reason the workload ran at 15 MB/s\n * while decode ran at 28. Carving amortises it over a whole slab.\n *\n * A carved region is handed out **once** and never recycled, so this changes\n * nothing an encoder or its caller can observe: two accumulators never share\n * bytes, and a slab is fresh (zero-filled) storage, so no previous message's\n * bytes can be read out of one. What it does change is lifetime — a retained\n * `bytes()` view keeps its whole slab alive, exactly as a retained\n * `Buffer.allocUnsafe` slice does — which is why {@link OStream.bytes} already\n * documents `.slice()` for a view that must outlive the encode.\n */\nfunction accumulatorBuffer(n: number): Uint8Array {\n if (n > SLAB_MAX_TAKE) return new Uint8Array(n);\n let s = slab;\n if (s === null || s.length - slabUsed < n) {\n s = slab = new Uint8Array(SLAB_BYTES);\n slabUsed = 0;\n }\n const from = slabUsed;\n slabUsed = from + n;\n return s.subarray(from, slabUsed);\n}\n\n/**\n * The accumulating flush sink (§5.1.5), shared by every accumulating stream and\n * holding no state of its own.\n *\n * `OStream.flush` invokes the sink as a **method** of the stream, so `this` here\n * is the encoder that flushed and `buffer` is the storage it was writing into.\n * That is why `growingOStream` allocates **nothing** per stream beyond the\n * storage itself: no closure, no context, no accumulator object.\n * `test/buffer-ownership.test.ts` pins the receiver, since a refactor of `flush`\n * that hoisted the sink into a local would break it.\n *\n * The encoder writes into the result all along, so the flushed bytes are already\n * where they belong: absorbing a flush is nothing at all. What is left is to make\n * room and re-open the encoder over the free tail, telling it how much of the\n * replacement is message it has already written (`carried`), so\n * {@link OStream.bytes} keeps reporting the message.\n *\n * **Where the message begins is `this.bytesUsed`, never `0`.** At a flush the\n * cursor is `end`, so the message occupies `[end - bytesUsed, end)`. The two\n * coincide on an ordinary accumulating stream — and part the moment a caller\n * installs a buffer with a reserve offset, which `growingOStream` permits like\n * any other streaming stream. Copying from `0` there would fold the reserved\n * bytes into the message and hand back a wire image with junk in front of it.\n *\n * **`needed` decides how much room to make.** A bulk write asks for its whole\n * payload contiguously; without that number this could only double blindly, and\n * a large array written into a small accumulator would fall back to the\n * element-at-a-time route on every attempt — correct bytes, but none of the\n * kernel's speed. `MIN_WINDOW` is the floor, so an ordinary flush behaves as\n * before.\n */\nconst ACCUMULATE = function (\n this: OStream,\n buffer: Uint8Array,\n _start: number,\n end: number,\n needed = 0,\n): void {\n const used = this.bytesUsed;\n const window = needed > MIN_WINDOW ? needed : MIN_WINDOW;\n if (buffer.length - end >= window) {\n // The tail already holds what was asked for: re-open over it, with the\n // message's own extent as `carried`. No copy, and no allocation at all.\n this.setBuffer(buffer, end, used);\n return;\n }\n let cap = buffer.length * 2;\n const want = used + window;\n if (cap < want) cap = want;\n const next = accumulatorBuffer(cap);\n next.set(buffer.subarray(end - used, end));\n this.setBuffer(next, used, used);\n} as FlushSink;\n\n/**\n * An {@link OStream} whose **buffer follows the message** — the ready-made form\n * of the caller CORELIB_PLAN §5.1.2 puts the allocation in.\n *\n * It is the one-liner for the 90% case, where the message comfortably fits in\n * memory:\n *\n * ```ts\n * const os = growingOStream();\n * os.writeUnsigned(1, 42);\n * const wire = os.bytes(); // the whole message, as a view valid until the next write\n * ```\n *\n * {@link OStream.bytes} is therefore the **whole** message here rather than a\n * not-yet-flushed tail, and no write reports `BUFFER_FULL`. It is an ordinary\n * streaming stream in every other respect: {@link OStream.setBuffer} works and\n * means what it always means — the not-yet-flushed bytes in the old buffer are\n * dropped and encoding continues into yours, which the accumulator then grows in\n * turn.\n *\n * @param initialCapacity bytes to start from; the accumulator enlarges itself\n * whenever the message outgrows it, so this only trades an initial allocation\n * against the number of enlargements and never limits the message. A caller with\n * a rough size in hand should pass it: 100 KB of *small fields* grows by doubling\n * and costs nine enlargements from the 256-byte default. A single large field\n * does not — a bulk write hands the sink its `needed`, so the buffer reaches that\n * size in one step and the write keeps its bulk route.\n */\nexport function growingOStream(initialCapacity = DEFAULT_CAPACITY): OStream {\n if (!Number.isInteger(initialCapacity) || initialCapacity < 1) {\n throw argumentError(`initial capacity ${initialCapacity} must be a positive integer`);\n }\n return new OStream(accumulatorBuffer(initialCapacity), 0, ACCUMULATE);\n}\n","import type { Visitor } from \"./istream.js\";\n\n/**\n * The scope a consumer declined — what the decoder dispatches to while it\n * consumes a subtree {@link Visitor.sequenceBegin} answered `false` for.\n *\n * It declares no callback at all, so every dispatch short-circuits on it through\n * the optional call the decoder already uses, and the arguments are never\n * evaluated: nothing inside a declined subtree is decoded into existence, and no\n * piece of a payload is reported.\n *\n * A sentinel rather than a `skipping` flag tested at each dispatch, and the\n * difference is measured: the flag put a branch on every dispatch of every\n * decode, declined or not, and cost `decode: typical message` about 4% Ir/op.\n * This costs a live decode nothing, and nothing asks for it by name any more:\n * the receiver caps (§6.2.1) test whether the *callback for this field* exists,\n * which is the broader question — a declined scope and a visitor that simply\n * declares no handler both skip the field, and neither may be capped. Declaring\n * nothing is what makes this sentinel answer `no` to every one of those probes.\n *\n * Frozen and empty, so it adds one hidden class to the decoder's dispatch sites\n * and no more.\n */\nexport const SKIP: Visitor = Object.freeze({});\n","/**\n * The decoder: one resumable state machine, and the only one.\n *\n * `DecoderState` consumes input a chunk at a time and never needs to hold more\n * than a single varint (≤10 bytes) or one fixlen element (≤8 bytes), so it can be\n * fed arbitrarily small chunks: every multi-byte construct saves its progress in\n * instance fields and continues on the next {@link push}. String / blob payloads\n * are reported in pieces and array elements as they arrive — nothing is\n * materialised whole, and nothing is allocated (CORELIB_PLAN §6.6).\n *\n * **One implementation, both entry points.** The one-shot {@link decode} is a\n * single {@link push} of the whole buffer, not a second decoder: §6.7.1 forbids\n * the one-shot path from behaving differently, and §5.3.1 names \"a second\n * implementation of every rule\" as the defect a single surface exists to prevent.\n * Speed comes from a *fast lane* instead: a field whose words can be read without\n * resume bookkeeping — ten bytes in hand, or a varint that terminates inside the\n * chunk ({@link varintQuick}) — is decoded inline, with no per-byte state reload.\n * Only a construct that really does straddle the chunk boundary goes through the\n * resumable switch, so a contiguous message runs the fast lane end to end.\n *\n * **Nothing here allocates** (§6.6). The parse stack is a fixed\n * {@link MAX_DEPTH}-slot `Int32Array` sized at construction; the varint and float\n * accumulators are plain number fields; payloads are reported as `(src, start,\n * end)` into the caller's own fed chunk rather than as views this decoder would\n * have to create (§6.6.3). The single exception the language forces is a `bigint`\n * for an integer beyond 2^53, which is a *value*, not storage (§6.6.3's \"a value\n * is not storage\") — and it is not created for ids, lengths, counts, or any value\n * that fits a `number`.\n */\n\nimport {\n ARRAY_MAX,\n ArrayKind,\n DecodeStatus,\n FIXLEN_MAX,\n FP32_HANDLE_MIN,\n FP64_HANDLE_MIN,\n FixlenSubtype,\n ID_MAX,\n MAX_DEPTH,\n VARINT_MAX_BYTES,\n WireType,\n} from \"../constants.js\";\nimport type { FeedStatus } from \"../constants.js\";\nimport { SofabError, SofabErrorCode, argumentError, invalidMsgError } from \"../errors.js\";\nimport { Long } from \"../long.js\";\nimport { HI, LO, joinI64, joinU64 } from \"../varint/bits64.js\";\nimport { fp32FromBits, fp64FromBits } from \"../varint/num64.js\";\nimport { SKIP } from \"./skip.js\";\nimport type {\n ArrayTarget,\n BoolArrayTarget,\n FloatArrayTarget,\n IntegerArrayTarget,\n Visitor,\n} from \"./istream.js\";\n\nconst enum S {\n Header,\n ScalarU,\n ScalarS,\n FixlenWord,\n FixlenFp,\n FixlenBytes,\n ArrayCount,\n ArrayElem,\n ArrayElemWord,\n ArrayFp,\n}\n\nconst TWO32 = 0x1_0000_0000; // 2^32, for combining the 32-bit halves\n\ntype TypedIntCtor =\n | Uint8ArrayConstructor\n | Uint16ArrayConstructor\n | Uint32ArrayConstructor\n | Int8ArrayConstructor\n | Int16ArrayConstructor\n | Int32ArrayConstructor\n | BigUint64ArrayConstructor\n | BigInt64ArrayConstructor;\n\n/**\n * What each exact-width destination can hold, so {@link IntegerArrayTarget.typed}\n * is checked against the stated bound ONCE per array rather than per element.\n * Keyed by constructor: the check is a map lookup, not a chain of `instanceof`.\n */\nconst TYPED_CAPACITY = new Map<TypedIntCtor, { min: number; max: number }>([\n [Uint8Array, { min: 0, max: 0xff }],\n [Uint16Array, { min: 0, max: 0xffff }],\n [Uint32Array, { min: 0, max: 0xffffffff }],\n [Int8Array, { min: -0x80, max: 0x7f }],\n [Int16Array, { min: -0x8000, max: 0x7fff }],\n [Int32Array, { min: -0x80000000, max: 0x7fffffff }],\n // The 64-bit pair is the accumulator's own range on both sides, so any bound a\n // caller can state fits: `min`/`max` here are the sentinels the fit test needs,\n // not numbers anything is compared against (the fill writes raw halves).\n [BigUint64Array, { min: 0, max: Number.POSITIVE_INFINITY }],\n [BigInt64Array, { min: Number.NEGATIVE_INFINITY, max: Number.POSITIVE_INFINITY }],\n]);\n\n/**\n * {@link TYPED_CAPACITY} with the six narrow constructors answered by identity\n * first: the check runs once per array, and on a short array a `Map` probe keyed\n * by an object was a measurable share of it. A narrow answer also lets the\n * caller skip the two 64-bit `instanceof` tests.\n */\nfunction typedCapacity(ctor: unknown): { min: number; max: number } | undefined {\n if (ctor === Uint8Array) return CAP_U8;\n if (ctor === Int8Array) return CAP_I8;\n if (ctor === Uint16Array) return CAP_U16;\n if (ctor === Int16Array) return CAP_I16;\n if (ctor === Uint32Array) return CAP_U32;\n if (ctor === Int32Array) return CAP_I32;\n return TYPED_CAPACITY.get(ctor as TypedIntCtor);\n}\nconst CAP_U8 = TYPED_CAPACITY.get(Uint8Array)!;\nconst CAP_I8 = TYPED_CAPACITY.get(Int8Array)!;\nconst CAP_U16 = TYPED_CAPACITY.get(Uint16Array)!;\nconst CAP_I16 = TYPED_CAPACITY.get(Int16Array)!;\nconst CAP_U32 = TYPED_CAPACITY.get(Uint32Array)!;\nconst CAP_I32 = TYPED_CAPACITY.get(Int32Array)!;\n\n/** Whether `d` is one of the two 64-bit destinations, which fill through halves. */\nfunction is64(d: object): boolean {\n return d instanceof BigUint64Array || d instanceof BigInt64Array;\n}\n\n/**\n * Which destination an accepted {@link ArrayTarget} named — resolved once, at the\n * hand-off, so the drains switch on a small integer instead of re-deciding per\n * element which field of the target is set.\n */\nconst enum BM {\n /** {@link IntegerArrayTarget.values} — number-first. */\n Values,\n /**\n * {@link IntegerArrayTarget.values} for a bound that fits 32 bits — every\n * `u8`..`u32` array, which is most of them. The element *is* its low half then:\n * no halves to join, no `bigint` to consider, and the bound is two comparisons\n * on a small integer. Worth its own arm at 22 Ir/element (`array<u16>`:\n * 209 434 -> 181 866 Ir/op over 1000 elements).\n */\n Values32,\n /**\n * {@link IntegerArrayTarget.typed} — an exact-width typed array. The bound is\n * compared exactly as in {@link Values32} (§7.1 forbids masking, and a typed\n * store masks), so this arm buys the STORE and not the verdict: unboxed, and\n * with none of the element-kind transitions a `number[]` takes when a value\n * leaves the small-integer range.\n */\n Typed,\n /**\n * {@link IntegerArrayTarget.typed} holding a `BigUint64Array` / `BigInt64Array`.\n * Filled through a `Uint32Array` over the same buffer, two halves per element,\n * so a 64-bit array costs no `bigint` at all — the store a `BigUint64Array`\n * would otherwise demand one for.\n */\n Typed64,\n /** {@link IntegerArrayTarget.bool} — one normalized byte per element. */\n Bool,\n /** {@link IntegerArrayTarget.longs} — a {@link Long} per element, no `bigint`. */\n Longs,\n /** {@link IntegerArrayTarget.lo} / `hi` — raw halves, nothing allocated. */\n Halves,\n /** {@link FloatArrayTarget.f32} — values. */\n F32,\n /** {@link FloatArrayTarget.bits} — the wire words, so an fp32 sNaN survives. */\n F32Bits,\n /** {@link FloatArrayTarget.f64}. */\n F64,\n}\n\nexport class DecoderState {\n /** The caller's visitor — bound at construction, or re-bound by {@link begin}. */\n private root: Visitor;\n /**\n * Where fields are dispatched right now: {@link root}, or {@link SKIP} while a\n * declined subtree is being consumed. Two shapes at most at every call site,\n * which is what the flat visitor buys: with one visitor object per *message*\n * instead of one per nested scope, the dispatch sites below stay\n * (bi)morphic rather than degrading to a megamorphic lookup per call.\n */\n private cur: Visitor;\n /**\n * Depth at which the current skipped subtree was opened, or `-1` when nothing\n * is being skipped. The scope that returned `false` from\n * {@link Visitor.sequenceBegin} closes at this depth, and skipping ends there.\n */\n private skipFrom = -1;\n\n /**\n * **No receiver cap lives here** (§6.2.1). This decoder used to hold\n * `maxArrayCount` / `maxStringLen` / `maxBlobLen`, defaulted to the format\n * ceilings when the caller supplied none — which is precisely the shape §6.2.1\n * forbids: \"a codec **MUST NOT** hold a limit of its own, **MUST NOT** supply a\n * default for one it was not given, **MUST NOT** read an omitted argument as\n * *unlimited*, and **MUST NOT** clamp to one\", and \"a format ceiling (§6.2)\n * reached because no cap was stated is the **format's** bound, not a receiver\n * cap, and a port **MUST NOT** present it as one\". Reporting `LimitExceeded`\n * against `ARRAY_MAX`/`FIXLEN_MAX` did exactly that.\n *\n * The caps now have **one implementation** and it is not here: generated code\n * compares them in its own flat visitor, at `arrayBegin` / `fixlenBegin` — both\n * of which this decoder raises at the count / length header, before a byte of\n * payload is emitted and behind the MESSAGE_SPEC §7.3 tag test — and a wrapper\n * array's elements, which reach no visitor callback, are capped by the\n * `StringSeq` / `BlobSeq` collectors from bounds passed to their\n * constructors. §6.2.1: \"A port whose codec offers the check **MUST NOT** also\n * emit it into the generated layer, and a port that enforces it in generated\n * code **MUST NOT** ask the codec to enforce it too.\"\n *\n * The format ceilings below (`ARRAY_MAX`, `FIXLEN_MAX`, `MAX_DEPTH`, the varint\n * bound) are *not* receiver caps and stay here: they bound what the wire may\n * express, and exceeding one is `INVALID` (§6.2).\n */\n\n /**\n * The id of every open sequence, indexed by the depth it was opened at, so a\n * scope close can name the sequence it closes. Fixed size, sized from\n * {@link MAX_DEPTH} at construction — the \"fixed-size parse stack\" §6.6.2\n * allows, and the reason nothing here grows a stack per message.\n *\n * A plain array rather than an `Int32Array`, and the difference is 3 µs: V8\n * keeps a typed array's bytes inside the JS heap only up to 64 bytes, so a\n * 255-slot one is an *external* allocation — measured at ~3.1 µs on Node 24,\n * against ~5 ns for this. That is paid per decoder, and the one-shot\n * {@link decode} builds a decoder per message, so it was the whole cost of\n * decoding a small one. Slots are written before they are read (a scope is\n * opened before it closes), so the array is never read holey.\n */\n private readonly seqIds: number[] = new Array<number>(MAX_DEPTH);\n /** Number of nested sequences currently open — 0 at the root scope. */\n private depth = 0;\n\n private state = S.Header;\n\n /**\n * The terminal-refusal latch: the rejection this stream was stopped by, or\n * `null` while it is still healthy. **One latch, two codes** — §5.3.1 gives the\n * rule one implementation, and §6.3 makes both of these rejections terminal:\n *\n * - `INVALID_MSG` (§5.2.1: \"malformed **regardless of what follows** … no —\n * terminal\") — no later bytes can make malformed input valid;\n * - `LIMIT_EXCEEDED` (§6.3: \"A **terminal**, receiver-local **policy**\n * rejection\") — well-formed bytes the receiver's cap refuses.\n *\n * They are latched together and **kept apart by their code**, which is the\n * distinction §6.3 requires: a limit rejection \"**MUST NOT** be reported as\n * `InvalidMessage`\", so the code is re-raised as itself and each stays the\n * refusal it was.\n *\n * Latching is not bookkeeping, it is the terminality: both rejections are\n * raised *mid-field* — the UTF-8 check inside a payload piece, a cap inside the\n * count or length callback — so the machine is left at a position the visitor\n * never finished. Resume it and the refused field's own bytes are re-read as\n * headers, delivering fields that were never on the wire.\n *\n * The rejection is written here by {@link latch} and nowhere else: this\n * machine's own malformation findings arrive through {@link fail}, and the ones\n * raised above it — the §6.4.5 UTF-8 verdict, and the receiver caps §6.2.1\n * keeps out of this codec — arrive as a throw out of a visitor callback, caught\n * once in {@link push}.\n */\n private refusal: SofabError | null = null;\n\n /**\n * A `DataView` over the chunk currently being fed, and the chunk it addresses —\n * the **language-forced handle** of CORELIB_PLAN §6.6.2, and the only way\n * JavaScript lets a reader take an IEEE-754 value from a byte offset. Without it\n * a float costs four or eight byte loads, a shift ladder and a round trip\n * through a scratch word; with it, one call.\n *\n * It qualifies because it carries no message bytes (it addresses the *caller's*\n * chunk) and no wire number sizes it (its extent is the chunk's). Built lazily\n * and only where it pays: a float **array** whose remaining run inside this chunk\n * clears {@link FP32_HANDLE_MIN} / {@link FP64_HANDLE_MIN}. A scalar float, a\n * short array, a message with no float at all, and a byte-at-a-time feed each\n * build none. Once built it is kept while the same chunk is being fed, and it\n * never leaves this class.\n */\n private view: DataView | null = null;\n private viewOf: Uint8Array | null = null;\n\n /** The current field's id. */\n private id = 0;\n\n // Resumable varint accumulator, as two unsigned 32-bit halves (vLo / vHi) plus\n // the byte count so far. Number-only: a `bigint` is built once, at the end, and\n // only for full 64-bit *values* (never for ids, lengths or counts).\n private vLo = 0;\n private vHi = 0;\n private vBytes = 0;\n private vComplete = false;\n\n /**\n * Resumable fp32 / fp64 accumulator, as two little-endian 32-bit words rather\n * than a byte array: a typed array would be a per-decoder allocation, and two\n * number fields hold the same 8 bytes. Byte `k` lands in bits `8*k` of `fpLo`\n * (k < 4) or of `fpHi`, so the pair is already in wire (little-endian) order.\n */\n private fpLo = 0;\n private fpHi = 0;\n private need = 0;\n private have = 0;\n\n // fixlen string/blob streaming\n private fixSub: FixlenSubtype = FixlenSubtype.String;\n private fixLen = 0;\n private fixOff = 0;\n\n // array\n private arrKind: ArrayKind = ArrayKind.Unsigned;\n private arrIsFixlen = false;\n private arrCount = 0;\n private arrIndex = 0;\n /**\n * The destination the visitor handed over for the array being decoded, or\n * `null` while no hand-off is in force — which is every array the visitor\n * declined, and every array at all for a visitor that declares no\n * {@link Visitor.arrayBulk}.\n *\n * **The one reference this machine keeps into the caller's storage between\n * `feed` calls.** Everything else it holds past a callback is its own (§6.6):\n * a payload is reported as coordinates into the caller's chunk and never\n * retained. An array that straddles chunks has to remember where its elements\n * go, so this lives from the hand-off to `arrayEnd` — and is dropped there,\n * by {@link endArray}, and by {@link release} for a machine going back to the\n * pool.\n */\n private bulk: ArrayTarget | null = null;\n /** Which destination {@link bulk} named; meaningless while it is `null`. */\n private bulkMode: BM = BM.Values;\n /**\n * The `Uint32Array` over a 64-bit typed destination (see {@link BM.Typed64}),\n * or over an `f32` destination once it has taken a NaN (see {@link f32StoreWord}).\n */\n private bulk64: Uint32Array | null = null;\n\n constructor(visitor: Visitor = SKIP) {\n this.root = visitor;\n this.cur = visitor;\n this.begin(visitor);\n }\n\n /**\n * (Re)bind this machine to a visitor, clearing every trace of whatever it\n * decoded before.\n *\n * Constructing a decoder is the one allocating step (§6.6), and the one-shot\n * {@link decode} would otherwise pay it per message — which on a 37-byte message\n * is most of the cost. So {@link decode} keeps one machine and re-binds it here;\n * this method is what makes that indistinguishable from a fresh one.\n *\n * **Only the fields a fresh decode can *read* are cleared**, and the list is\n * exhaustive by construction rather than by inspection: every other field is\n * written before it is read, on every path that reads it — `id` at each header,\n * `vLo`/`vHi` by whichever varint reader ran (a fresh accumulation starts from\n * zero because `vBytes` is 0), `vComplete` by the `varintStep` whose result is\n * being tested, `fpLo`/`fpHi`/`need` by {@link fpBegin}, `fix*` by\n * {@link fixlenWord}, `arrKind`/`arrIsFixlen` by {@link dispatch} and\n * `arrCount`/`arrIndex` by the count word and `bulkMode` by the hand-off the\n * same word makes (`bulk` *is* cleared: it is the caller's storage, and a\n * machine that starts a fresh decode must not still be pointing at the last\n * one's), `seqIds[d]` when the scope at `d`\n * opens. `have` is the one exception and *is* cleared: the `S.ArrayFp` bulk loop\n * reads it to decide whether an element is half-arrived.\n *\n * `view`/`viewOf` are not cleared either, and deliberately: {@link dataView}\n * keys the cached handle on the chunk it addresses, so a stale one is rebuilt the\n * moment a different chunk arrives and reused — correctly — when the same buffer\n * is decoded again. {@link release} still drops it, which is where it matters:\n * a pooled machine must not keep the caller's last chunk alive between calls.\n *\n * Clearing them all anyway cost 5573 → 5324 Ir/op on `decode: typical message`\n * (~4.5%), which is what a 21-field wipe costs when the message is 37 bytes. The\n * invariant is held by `pooled-decoder-state.test.ts`, which aborts a decode in\n * every construct and then reuses the machine.\n */\n begin(visitor: Visitor): void {\n this.root = visitor;\n this.cur = visitor;\n this.skipFrom = -1;\n this.depth = 0;\n this.state = S.Header;\n this.refusal = null;\n this.vBytes = 0;\n this.have = 0;\n this.bulk = null;\n this.bulk64 = null;\n }\n\n /**\n * Drop the references a pooled machine would otherwise keep alive: the caller's\n * visitor, and the handle onto the caller's chunk.\n */\n release(): void {\n this.root = SKIP;\n this.cur = SKIP;\n this.view = null;\n this.viewOf = null;\n // A decode aborted inside an array leaves the visitor's destination here;\n // a pooled machine must not keep it alive (see {@link bulk}).\n this.bulk = null;\n this.bulk64 = null;\n }\n\n /** Feed `input` to the machine, dispatching to the bound visitor. */\n push(input: Uint8Array): void {\n // A latched refusal is terminal (§5.2.1, §6.3). Once one has been raised the\n // stream consumes nothing further and drives no visitor callbacks — it just\n // re-reports the original rejection, under its own code. One\n // perfectly-predicted branch per chunk.\n const latched = this.refusal;\n if (latched !== null) throw new SofabError(latched.code, latched.message);\n\n try {\n this.run(input);\n } catch (e) {\n // Neither terminal rejection is necessarily raised *by* this machine. §6.4.5\n // puts the strict UTF-8 check where a string is materialized and §6.2.1 puts\n // the receiver caps in the layer that holds the numbers, so both are decided\n // inside a visitor callback and arrive here as a throw out of the loop. They\n // are the same two rejections this machine raises itself, and §5.3.1 allows\n // a rule only one implementation, so they go through the one latch rather\n // than beside it. Unlatched, the next chunk resumes parsing mid-field and\n // hands the refused field's own bytes to the visitor as fields that were\n // never on the wire.\n //\n // `Argument` is latched for a third reason, and it is about this machine\n // rather than about the message: a target the hand-off cannot fill is\n // refused *after* the count word has been consumed and the element state\n // entered, so the position `run` was holding dies with the stack. Left\n // unlatched, the next chunk would resume mid-array at the wrong offset and\n // hand the visitor fields that were never on the wire — exactly what this\n // block exists to prevent. The caller's mistake does not become a verdict\n // about the bytes: the code stays `ARGUMENT` through the latch, as the\n // other two stay themselves.\n //\n // The two message codes stay distinct through it — §6.3: a cap rejection\n // \"MUST NOT be reported as `InvalidMessage`\", so it is re-raised as\n // `LIMIT_EXCEEDED` and never becomes `INVALID`.\n if (\n this.refusal === null &&\n e instanceof SofabError &&\n (e.code === SofabErrorCode.InvalidMsg ||\n e.code === SofabErrorCode.LimitExceeded ||\n e.code === SofabErrorCode.Argument)\n ) {\n this.latch(e);\n }\n throw e;\n }\n }\n\n /**\n * The decode loop itself. {@link push} wraps it, so the terminal-refusal latch\n * is applied in exactly one place — including to a rejection the visitor raised\n * — and this stays the plain state machine.\n */\n private run(input: Uint8Array): void {\n const n = input.length;\n let i = 0;\n\n while (i < n) {\n // ---- fast lane -----------------------------------------------------\n // At a clean field boundary, decode the whole field inline whenever its\n // words can be read without resume bookkeeping — which {@link varintQuick}\n // decides per word, so the lane keeps working in the last bytes of a chunk\n // rather than stopping ten bytes short of it. That matters more than it\n // sounds: a 37-byte message is *all* tail, and a lane that gave up there\n // would run half of every small message down the resumable ladder.\n //\n // Everything that cannot finish here — a value whose varint straddles the\n // chunk, a payload longer than it, an array, a float with fewer than its\n // bytes left — sets up its resumable state and drops into the switch below,\n // so no rule is implemented twice.\n if (this.state === S.Header && this.vBytes === 0) {\n // A one-byte header, read without a call. Every id below 16 is one byte,\n // which is most fields of most messages, and {@link varintQuick} is past\n // what the JIT will inline — so calling it per field costs a real call and\n // spills the cursor. Measured on `decode: typical message`: 6708 → 5573\n // Ir/op for this and the two value sites below, ~17%.\n let h: number;\n const hb = input[i]!;\n if (hb < 0x80) {\n this.vLo = hb;\n this.vHi = 0;\n h = i + 1;\n } else h = this.varintQuick(input, i, n);\n if (h >= 0) {\n i = h;\n const type = this.vLo & 7;\n // §4.9/§6.2: the ceiling binds *every* field header, the sequence end\n // included — a sequence end's id is discarded, but discarded is not\n // unvalidated. Splitting and checking the id before dispatching on the\n // wire type keeps this one unconditional guard on the header path with\n // no per-wire-type exception. (Inlined for the one-word header every\n // small id has: `vUpper` is only needed once the high half is in play.)\n const id = this.vHi === 0 ? this.vLo >>> 3 : this.vUpper();\n if (id > ID_MAX) this.fail(`field id ${id} out of range`);\n\n if (type === WireType.SequenceEnd) {\n this.endSequence();\n continue;\n }\n this.id = id;\n // Announce the header before the value — and before the value's own\n // header word — so a visitor sees the field stream in wire order. It\n // carries no verdict of its own: a schema bound waits for the word\n // behind it (§4.1.1; see Visitor.fieldBegin).\n this.cur.fieldBegin?.(id, type as WireType);\n\n if (type === WireType.Unsigned) {\n // The same one-byte read for the value (see the header above). `0x80`\n // stands in at end-of-chunk, so the fallback suspends as it should.\n let v: number;\n const b0 = i < n ? input[i]! : 0x80;\n if (b0 < 0x80) {\n this.vLo = b0;\n this.vHi = 0;\n v = i + 1;\n } else v = this.varintQuick(input, i, n);\n if (v < 0) {\n this.state = S.ScalarU;\n continue;\n }\n i = v;\n // vUnsigned() inlined: on this path the halves are already in hand,\n // and this is the most-executed dispatch in the decoder.\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n this.cur.unsigned?.(\n id,\n hi <= 0x1fffff ? hi * TWO32 + lo : joinU64(lo, hi),\n lo,\n hi,\n );\n continue;\n }\n if (type === WireType.Signed) {\n let v: number;\n const b0 = i < n ? input[i]! : 0x80;\n if (b0 < 0x80) {\n this.vLo = b0;\n this.vHi = 0;\n v = i + 1;\n } else v = this.varintQuick(input, i, n);\n if (v < 0) {\n this.state = S.ScalarS;\n continue;\n }\n i = v;\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n const mask = -(lo & 1) >>> 0;\n this.cur.signed?.(\n id,\n this.vSigned(),\n ((((lo >>> 1) | (hi << 31)) >>> 0) ^ mask) >>> 0,\n ((hi >>> 1) ^ mask) >>> 0,\n );\n continue;\n }\n if (type === WireType.Fixlen) {\n const w = this.varintQuick(input, i, n);\n if (w < 0) {\n this.state = S.FixlenWord;\n continue;\n }\n i = this.fixlenWord(input, w, n);\n continue;\n }\n // Arrays and sequence starts have no inline form worth writing: an\n // array is driven by the element loops in the switch, and a sequence\n // start is one call either way.\n this.dispatch(type);\n continue;\n }\n }\n\n // ---- resumable path ------------------------------------------------\n switch (this.state) {\n case S.Header: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const type = this.vLo & 7;\n const id = this.vUpper();\n if (id > ID_MAX) this.fail(`field id ${id} out of range`);\n if (type === WireType.SequenceEnd) {\n this.endSequence();\n break;\n }\n this.id = id;\n this.cur.fieldBegin?.(id, type as WireType);\n this.dispatch(type);\n break;\n }\n\n case S.ScalarU: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n this.state = S.Header;\n this.cur.unsigned?.(this.id, this.vUnsigned(), this.vLo >>> 0, this.vHi >>> 0);\n break;\n }\n\n case S.ScalarS: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n this.state = S.Header;\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n const mask = -(lo & 1) >>> 0;\n this.cur.signed?.(\n this.id,\n this.vSigned(),\n ((((lo >>> 1) | (hi << 31)) >>> 0) ^ mask) >>> 0,\n ((hi >>> 1) ^ mask) >>> 0,\n );\n break;\n }\n\n case S.FixlenWord: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n i = this.fixlenWord(input, i, n);\n break;\n }\n\n case S.FixlenFp: {\n i = this.fpStep(input, i, n);\n if (this.have < this.need) return;\n this.state = S.Header;\n if (this.fixSub === FixlenSubtype.Fp32) {\n this.cur.fp32?.(this.id, fp32FromBits(this.fpLo), this.fpLo >>> 0);\n } else {\n this.cur.fp64?.(this.id, fp64FromBits(this.fpLo, this.fpHi));\n }\n break;\n }\n\n case S.FixlenBytes: {\n const take = Math.min(n - i, this.fixLen - this.fixOff);\n this.emitBytes(input, i, i + take);\n i += take;\n this.fixOff += take;\n if (this.fixOff === this.fixLen) this.state = S.Header;\n break;\n }\n\n case S.ArrayCount: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const count = this.vNum();\n // `ARRAY_MAX` is the FORMAT's ceiling (§6.2), not a receiver cap: it\n // bounds what the wire may express, so exceeding it is `INVALID` for\n // every receiver however it is configured. A receiver cap on this count\n // is generated code's, compared inside the `arrayBegin` raised below —\n // still at the count word, still before any element is delivered, and\n // only for a field this visitor actually reads (§6.2.1).\n if (count > ARRAY_MAX) this.fail(\"array count out of range\");\n this.arrCount = count;\n this.arrIndex = 0;\n if (this.arrIsFixlen) {\n // §4.8: a fixlen array always carries its element-length word — even\n // when empty — so the true element kind (fp32 vs fp64) stays known.\n // The kind is knowable only once that word arrives, so arrayBegin\n // waits for it (handled in S.ArrayElemWord).\n this.state = S.ArrayElemWord;\n } else if (count === 0) {\n // §4.7: a zero-count integer array is empty — no payload follows and\n // no element-length word exists (element width is API-only).\n //\n // Offered all the same, and closed through {@link endArray} like any\n // other array: a visitor holding one destination per field would\n // otherwise read the *previous* array's elements out of it, having\n // been told nothing. An empty array is a fact about this field, and\n // the destination has to end up saying so.\n this.cur.arrayBegin?.(this.id, this.arrKind, 0);\n this.askBulk(this.arrKind, 0);\n this.endArray();\n } else {\n this.state = S.ArrayElem;\n this.cur.arrayBegin?.(this.id, this.arrKind, count);\n this.askBulk(this.arrKind, count);\n }\n break;\n }\n\n case S.ArrayElem: {\n const count = this.arrCount;\n const safeEnd = n - VARINT_MAX_BYTES;\n // A destination was handed over: delivery is one call, out of line, and\n // none of it is carried in this switch (see uBulkArm).\n if (this.bulk !== null) {\n i =\n this.arrKind === ArrayKind.Unsigned\n ? this.uBulkArm(input, i, n, count, safeEnd)\n : this.sBulkArm(input, i, n, count, safeEnd);\n break;\n }\n // No destination: the elements are walked over, not decoded into\n // existence (§6.7.2's `skip` intent). Nothing distinguishes the two\n // integer kinds here — the zig-zag only matters to a value nobody asked\n // for — so one arm serves both, and the decode switch is one case\n // smaller for it.\n let idx = this.arrIndex;\n // Only scan ahead from a clean element boundary: a varint left half-read\n // by the previous chunk lives in the accumulator, and `varintFull` would\n // start a fresh one and drop it.\n if (this.vBytes === 0) {\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n idx++;\n }\n this.arrIndex = idx;\n }\n if (idx === count) {\n this.state = S.Header;\n this.cur.arrayEnd?.(this.id);\n break;\n }\n if (i >= n) break;\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n this.advanceArray();\n break;\n }\n\n case S.ArrayElemWord: {\n i = this.varintStep(input, i);\n if (!this.vComplete) return;\n const sub = this.vLo & 7;\n const size = this.vUpper();\n if (sub === FixlenSubtype.Fp32 && size === 4) {\n this.arrKind = ArrayKind.Fp32;\n this.fpBegin(4);\n } else if (sub === FixlenSubtype.Fp64 && size === 8) {\n this.arrKind = ArrayKind.Fp64;\n this.fpBegin(8);\n } else {\n this.fail(\"invalid fixlen array element type\");\n }\n if (this.arrCount === 0) {\n // §4.8: an empty fixlen array is [ header ][ count = 0 ][ fixlen_word ]\n // with no payload — the word above yielded the true element kind.\n this.cur.arrayBegin?.(this.id, this.arrKind, 0);\n this.askBulk(this.arrKind, 0);\n this.endArray();\n } else {\n this.state = S.ArrayFp;\n this.cur.arrayBegin?.(this.id, this.arrKind, this.arrCount);\n this.askBulk(this.arrKind, this.arrCount);\n }\n break;\n }\n\n case S.ArrayFp: {\n const count = this.arrCount;\n const size = this.need;\n if (this.bulk !== null) {\n const is32 = this.arrKind === ArrayKind.Fp32;\n i = this.fpBulkArm(input, i, n, count, size, is32);\n break;\n }\n // No destination: step over the elements. A float run is fixed-width,\n // so skipping is arithmetic — no handle, no byte loads, nothing decoded\n // (§6.7.2). Only an element straddling the chunk goes through the\n // accumulator below, which is where the resume lives.\n if (this.have === 0) {\n const run = Math.min(count - this.arrIndex, ((n - i) / size) | 0);\n i += run * size;\n this.arrIndex += run;\n }\n if (this.arrIndex === count) {\n this.state = S.Header;\n this.cur.arrayEnd?.(this.id);\n break;\n }\n if (i >= n) break;\n i = this.fpStep(input, i, n);\n if (this.have < this.need) return;\n this.fpBegin(size); // next element starts from a clear accumulator\n this.advanceArray();\n break;\n }\n }\n }\n }\n\n /**\n * Where the decode stands (§5.2.1), *without* promoting it to an error:\n * {@link DecodeStatus.Complete} when the stream ended exactly at a field\n * boundary, {@link DecodeStatus.Incomplete} when it ended inside a field (a\n * partial varint, an unfinished payload / array, or a still-open nested\n * sequence). A trailing `Incomplete` is a truncation the caller decides how to\n * treat (§5.2.4), not an error this machine raises.\n *\n * **Only these two, and only on a healthy machine.** This is read in exactly\n * one place — after a {@link push} that returned — and a push that met a\n * terminal refusal does not return: it throws, this call is never reached, and\n * the verdict travels out on the error it threw. So `Invalid` is not a value\n * this can produce, and neither is the \"refused by a cap\" state the outcome\n * triple cannot name (§6.3). Nothing here re-reports a latched refusal, because\n * nothing needs to: the throw is the whole report, and a report with one\n * carrier has nothing to drift out of step with.\n *\n * The cursor's own answer would be wrong for a refused stream, which is why the\n * refusal must not fall through to it: a cap is compared in `arrayBegin` /\n * `fixlenBegin`, raised with the header and the count / length word consumed and\n * the payload not yet entered — a cursor that reads as a clean field boundary,\n * and so as `Complete`. {@link push}'s latch is what keeps that unreachable.\n */\n outcome(): FeedStatus {\n const atBoundary =\n this.state === S.Header && this.vBytes === 0 && this.depth === 0;\n return atBoundary ? DecodeStatus.Complete : DecodeStatus.Incomplete;\n }\n\n // --- helpers ------------------------------------------------------------\n\n /**\n * Reject the input as malformed: latch the terminal `INVALID` verdict and throw\n * `INVALID_MSG`. Every malformation *this machine* finds goes through here, so\n * none of them can be caught and then decoded past — §5.2.1's \"no — terminal\".\n * Declared `never` so a call ends control flow exactly like the `throw` it\n * replaced.\n */\n private fail(message: string): never {\n throw this.latch(invalidMsgError(message));\n }\n\n /**\n * Record `e` as the terminal refusal that stopped this stream, and hand it back\n * to be thrown. The only writer of {@link refusal} — §5.3.1's one\n * implementation of the rule — for a rejection raised here and for one raised\n * above this machine and caught in {@link push} alike. The error is stored, not\n * its text: the code travels with it, so `INVALID_MSG` and `LIMIT_EXCEEDED`\n * each stay themselves (§6.3).\n */\n private latch<E extends SofabError>(e: E): E {\n this.refusal = e;\n // Nothing more will be decoded, so the visitor's destination is dropped here\n // as it would have been at `arrayEnd`: a latched stream the caller keeps must\n // not keep *their* storage alive with it (§6.6; see {@link bulk}).\n this.bulk = null;\n this.bulk64 = null;\n return e;\n }\n\n /**\n * Act on a complete `fixlen_word` sitting in the varint accumulator: validate\n * it, announce the field, and either read the float inline (when its bytes are\n * in this chunk) or set up the resumable payload state. Shared by the fast lane\n * and the `S.FixlenWord` arm, so the §4.6 rules exist once.\n */\n private fixlenWord(input: Uint8Array, i: number, n: number): number {\n const sub = this.vLo & 7;\n const len = this.vUpper();\n // §4.6: reserved subtypes and a wrong float width are malformed the moment\n // the word is read — before any payload byte is consumed or waited for\n // (§5.2.3).\n if (sub > FixlenSubtype.Blob) this.fail(`invalid fixlen subtype ${sub}`);\n if (len > FIXLEN_MAX) this.fail(\"fixlen length out of range\");\n\n if (sub === FixlenSubtype.Fp32 || sub === FixlenSubtype.Fp64) {\n const want = sub === FixlenSubtype.Fp32 ? 4 : 8;\n if (len !== want) this.fail(\"fixlen float length mismatch\");\n this.fixSub = sub as FixlenSubtype;\n if (n - i >= want) {\n this.state = S.Header;\n // A *scalar* float is assembled from byte loads, not through a handle:\n // building one costs ~129 ns against the ~2-8 ns it would save on a single\n // value. §6.6.2 permits the handle; arithmetic rules it out here. Only the\n // array drain below reads enough floats from one chunk to amortize it.\n const lo = u32le(input, i);\n if (want === 4) {\n // The bits are what came off the wire; §6.5 needs the value *and* them,\n // because a double cannot carry an fp32 signaling NaN.\n this.cur.fp32?.(this.id, fp32FromBits(lo), lo);\n } else {\n this.cur.fp64?.(this.id, fp64FromBits(lo, u32le(input, i + 4)));\n }\n return i + want;\n }\n this.fpBegin(want);\n this.state = S.FixlenFp;\n return i;\n }\n\n this.fixSub = sub as FixlenSubtype;\n this.fixLen = len;\n this.fixOff = 0;\n // Announce the field at its LENGTH WORD, before any payload — the counterpart\n // of arrayBegin at the count word. This is the enforcement point §6.2.1 names\n // for a receiver cap on the declared length, and generated code compares its\n // cap inside this very callback: nothing below has run yet, so a rejection\n // costs no allocation, and only a field the visitor declares a callback for\n // is reached at all (a skipped field is never capped). It is decidable here,\n // and only here for a message that ends right after the word (§5.2.3: INVALID\n // over INCOMPLETE).\n this.cur.fixlenBegin?.(this.id, this.fixSub, len);\n if (len === 0) {\n // Still one delivery, so a zero-length payload is announced exactly like\n // any other: an empty range of the caller's own chunk.\n this.emitBytes(input, i, i);\n this.state = S.Header;\n return i;\n }\n const take = Math.min(n - i, len);\n if (take > 0) {\n this.emitBytes(input, i, i + take);\n this.fixOff = take;\n i += take;\n }\n this.state = this.fixOff === len ? S.Header : S.FixlenBytes;\n return i;\n }\n\n private dispatch(type: number): void {\n switch (type) {\n case WireType.Unsigned:\n this.state = S.ScalarU;\n break;\n case WireType.Signed:\n this.state = S.ScalarS;\n break;\n case WireType.Fixlen:\n this.state = S.FixlenWord;\n break;\n case WireType.ArrayUnsigned:\n this.arrKind = ArrayKind.Unsigned;\n this.arrIsFixlen = false;\n this.state = S.ArrayCount;\n break;\n case WireType.ArraySigned:\n this.arrKind = ArrayKind.Signed;\n this.arrIsFixlen = false;\n this.state = S.ArrayCount;\n break;\n case WireType.ArrayFixlen:\n this.arrIsFixlen = true; // element kind resolved at the element-length word\n this.state = S.ArrayCount;\n break;\n case WireType.SequenceStart:\n this.beginSequence();\n break;\n default:\n this.fail(`invalid wire type ${type}`);\n }\n }\n\n /**\n * Open a nested sequence: offer it to the visitor, note its id, and descend.\n *\n * A visitor that answers `false` declines the whole subtree — no callback of\n * any kind fires inside it, its own {@link Visitor.sequenceEnd} included, and a\n * scope opened within it is never offered either. The subtree is still *parsed*\n * (a sequence is framed by markers, not by a length, so its end has to be\n * found) and every format ceiling still applies; what stops is delivery.\n */\n private beginSequence(): void {\n const d = this.depth;\n // §4.9/§6.2: reject nesting deeper than MAX_DEPTH.\n if (d >= MAX_DEPTH) this.fail(`nesting exceeds MAX_DEPTH (${MAX_DEPTH})`);\n if (this.cur !== SKIP && this.root.sequenceBegin?.(this.id, d + 1) === false) {\n this.skipFrom = d;\n this.cur = SKIP;\n }\n this.seqIds[d] = this.id;\n this.depth = d + 1;\n this.state = S.Header;\n }\n\n private endSequence(): void {\n const d = this.depth;\n if (d === 0) this.fail(\"unbalanced sequence end\");\n this.state = S.Header;\n const closed = d - 1;\n this.depth = closed;\n if (this.skipFrom >= 0) {\n // The declined subtree ends where it began; nothing was delivered inside\n // it, and its own end is part of it.\n if (this.skipFrom === closed) {\n this.skipFrom = -1;\n this.cur = this.root;\n }\n return;\n }\n this.root.sequenceEnd?.(this.seqIds[closed]!, d);\n }\n\n private advanceArray(): void {\n if (++this.arrIndex === this.arrCount) {\n this.state = S.Header;\n this.cur.arrayEnd?.(this.id);\n }\n }\n\n /**\n * Close an array delivered through the hand-off: back to the header state, drop\n * the visitor's destination, announce the end. Every bulk array ends here, so\n * the reference into the caller's storage cannot outlive the array it was made\n * for (§6.6; see {@link bulk}).\n *\n * The per-element arms keep their own two lines instead of calling this: they\n * can never hold a destination — the hand-off's arms have already taken over\n * before they run — and the call showed up on `decode: typical`.\n */\n private endArray(): void {\n this.state = S.Header;\n const t = this.bulk;\n if (t !== null) this.trimPlain(t, this.arrIndex);\n this.bulk = null;\n this.bulk64 = null;\n this.cur.arrayEnd?.(this.id);\n }\n\n /**\n * Cut a plain-array destination to the `written` elements this array actually\n * put in it, so a destination reused across arrays — the shape the hand-off\n * exists for — can never hand back the previous array's tail, and its `length`\n * always means \"elements of *this* array\".\n *\n * At the end rather than at the hand-off, and that is measured: clearing it up\n * front turns every element write into a grow (`array<u16>` 181 583 -> 231 815\n * Ir/op, worse than the per-element path it replaces), where one length store\n * per array costs nothing. A pre-sized destination — the fast shape, every write\n * in bounds — is left exactly as it was.\n *\n * The typed destinations are not trimmed and cannot be: their length is the\n * caller's allocation, checked against `count` at the hand-off, and `count` is\n * how far this fill wrote.\n */\n private trimPlain(t: ArrayTarget, written: number): void {\n const mode = this.bulkMode;\n if (mode !== BM.Values && mode !== BM.Values32 && mode !== BM.Longs) return;\n const out =\n mode === BM.Longs\n ? (t as IntegerArrayTarget).longs!\n : (t as IntegerArrayTarget).values!;\n if (out.length > written) out.length = written;\n }\n\n /**\n * Offer the bulk hand-off for the array that just began, and resolve the answer\n * once (CORELIB_PLAN §5.3.1's one implementation, and {@link ArrayTarget}'s\n * contract): after this, the element loops know which destination to write to\n * from {@link bulkMode} and re-decide nothing per element.\n *\n * Raised after `arrayBegin` and before the first element, so a receiver cap on\n * the count (§6.2.1) is still compared in `arrayBegin` and a rejected array is\n * never offered. A visitor that declares no `arrayBulk` pays one short-circuited\n * optional call per array.\n *\n * **An empty array is offered too**, with `count` of 0. There is nothing to\n * write, but there is something to say: a destination held across fields would\n * otherwise still be holding the last array's elements, and its length is the\n * only place this one's emptiness could show up (see {@link trimPlain}).\n */\n private askBulk(kind: ArrayKind, count: number): void {\n // `cur` is SKIP inside a declined subtree and declares nothing, so the offer\n // short-circuits there exactly like every other callback (§6.2.1's \"a skipped\n // field is never capped\" falls out the same way).\n const t = this.cur.arrayBulk?.(this.id, kind, count) ?? null;\n if (t === null) {\n this.bulk = null;\n this.bulk64 = null;\n return;\n }\n // A view left from an earlier array would point into *its* storage, and the\n // `f32` route builds its own only when it finds this slot empty.\n this.bulk64 = null;\n // Resolve *before* storing: a target this machine cannot fill is a caller\n // mistake (§6.3's third row), and it is refused with nothing written and the\n // array still on the per-element path's terms.\n this.bulkMode = this.resolveTarget(t, kind, count);\n this.bulk = t;\n }\n\n /**\n * Which destination `t` names — or an `Argument` refusal if it names none, more\n * than one, one that contradicts the array's element kind, or one too short to\n * hold `count` elements.\n *\n * These are caller mistakes rather than message verdicts, so they are\n * `InvalidArgument` (§6.3) and not `INVALID_MSG`: the same bytes decode fine for\n * a visitor that hands over a destination it can actually fill. Checked once per\n * array, which is why the fill loops need no guard of their own.\n */\n private resolveTarget(t: ArrayTarget, kind: ArrayKind, count: number): BM {\n if (kind === ArrayKind.Fp32 || kind === ArrayKind.Fp64) {\n const f = t as FloatArrayTarget;\n const is32 = kind === ArrayKind.Fp32;\n // An fp32 array takes values *or* wire words; an fp64 array takes values,\n // its `Float64Array` already carrying every bit (a payload NaN included).\n const dest = is32 ? (f.f32 ?? f.bits) : f.f64;\n // Every destination counts here, not only the float ones: a target\n // carrying a leftover `bool` beside its `f64` would otherwise be accepted\n // and the `bool` silently left empty — which also SUPPRESSES the refusal\n // that same `bool` alone would have earned. \"Exactly one\" has to mean one\n // out of all of them, or the check only holds for the fields it happens to\n // look at.\n const named =\n (f.f32 !== undefined ? 1 : 0) +\n (f.bits !== undefined ? 1 : 0) +\n (f.f64 !== undefined ? 1 : 0) +\n ((t as BoolArrayTarget).bool !== undefined ? 1 : 0);\n const want = is32 ? \"f32 or bits\" : \"f64\";\n if (dest === undefined || named !== 1) {\n throw argumentError(\n `array ${this.id}: an ${is32 ? \"fp32\" : \"fp64\"} array needs` +\n ` exactly the ${want} destination`,\n );\n }\n if (dest.length < count) {\n throw argumentError(\n `array ${this.id}: ${is32 ? \"fp32\" : \"fp64\"} destination holds` +\n ` ${dest.length} of ${count} elements`,\n );\n }\n if (!is32) return BM.F64;\n return f.bits !== undefined ? BM.F32Bits : BM.F32;\n }\n\n // The bool destination carries no bound, so it is settled before the four\n // halves are even looked at.\n const bt = t as BoolArrayTarget;\n if (bt.bool !== undefined) {\n const other = t as IntegerArrayTarget;\n const float = t as FloatArrayTarget;\n // The float fields are checked too — see the float branch above: a target\n // with two destinations must be refused whichever pair it names.\n if (\n other.values !== undefined ||\n other.longs !== undefined ||\n other.typed !== undefined ||\n other.lo !== undefined ||\n other.hi !== undefined ||\n float.f32 !== undefined ||\n float.bits !== undefined ||\n float.f64 !== undefined\n ) {\n throw argumentError(`array ${this.id}: an array target needs exactly one destination`);\n }\n if (kind !== ArrayKind.Unsigned) {\n throw argumentError(`array ${this.id}: a bool destination needs an unsigned array`);\n }\n if (bt.bool.length < count) {\n throw argumentError(\n `array ${this.id}: bool destination holds ${bt.bool.length} of ${count} elements`,\n );\n }\n return BM.Bool;\n }\n const it = t as IntegerArrayTarget;\n const halves = it.lo !== undefined || it.hi !== undefined;\n const named =\n (it.values !== undefined ? 1 : 0) +\n (it.longs !== undefined ? 1 : 0) +\n (it.typed !== undefined ? 1 : 0) +\n (halves ? 1 : 0);\n if (named !== 1) {\n throw argumentError(\n `array ${this.id}: an integer array target needs exactly one destination` +\n ` (values, typed, longs, or lo+hi), got ${named}`,\n );\n }\n // The bound governs every element about to be written, so a bound that is not\n // one is refused before the first of them — the same reasoning the receiver\n // bounds in `seq.ts` are checked at construction for (§6.2.1, §6.3).\n if (\n (it.minLo >>> 0) !== it.minLo ||\n (it.minHi >>> 0) !== it.minHi ||\n (it.maxLo >>> 0) !== it.maxLo ||\n (it.maxHi >>> 0) !== it.maxHi\n ) {\n throw argumentError(\n `array ${this.id}: the element bound must be four unsigned 32-bit halves`,\n );\n }\n // An interval that cannot contain anything is a mistake in the *call*, and it\n // has to be judged in the signedness the array's kind will compare it in: the\n // widest unsigned bound handed to a signed array reads as `maxHi | 0 === -1`,\n // an empty interval, and every element of a well-formed message would be\n // refused as `INVALID`. §6.3 keeps those apart — this one is `ARGUMENT`.\n const signed = kind === ArrayKind.Signed;\n const minHi = signed ? it.minHi | 0 : it.minHi;\n const maxHi = signed ? it.maxHi | 0 : it.maxHi;\n if (minHi > maxHi || (minHi === maxHi && it.minLo > it.maxLo)) {\n throw argumentError(\n `array ${this.id}: the element bound is empty` +\n ` (min ${it.minHi}:${it.minLo} > max ${it.maxHi}:${it.maxLo})`,\n );\n }\n if (it.typed !== undefined) {\n // Split by signedness so each check site sees at most the three narrow\n // constructors of its own sign (plus the 64-bit one): four maps stay\n // polymorphic and V8 inlines `length`/`constructor` for them. One shared\n // site saw all six, went megamorphic, and paid a generic accessor call per\n // array (6.5 % of the arena's 434 B round trip).\n return kind === ArrayKind.Signed\n ? this.typedModeS(it, it.typed, kind, count)\n : this.typedModeU(it, it.typed, kind, count);\n }\n if (halves) {\n const lo = it.lo;\n const hi = it.hi;\n if (lo === undefined || hi === undefined) {\n throw argumentError(`array ${this.id}: the halves destination needs both lo and hi`);\n }\n if (lo.length < count || hi.length < count) {\n throw argumentError(\n `array ${this.id}: halves destination holds` +\n ` ${Math.min(lo.length, hi.length)} of ${count} elements`,\n );\n }\n return BM.Halves;\n }\n // A plain array needs no length: it grows on write. What it does need is to\n // be a real `Array` — a typed one would take the writes and silently drop\n // every index past its own length, and it is the one destination shape whose\n // length is not checked. Its *tail* is cut where the fill ended, not here:\n // emptying it at the hand-off would make every write a grow, which measured\n // 181 583 -> 231 815 Ir/op on `array<u16>` — the whole win and then some.\n // {@link trimPlain} does it at the end instead, for nothing.\n if (it.longs !== undefined) {\n if (!Array.isArray(it.longs)) {\n throw argumentError(`array ${this.id}: the longs destination must be an Array`);\n }\n return BM.Longs;\n }\n if (!Array.isArray(it.values)) {\n throw argumentError(`array ${this.id}: the values destination must be an Array`);\n }\n // The 32-bit arm is legal exactly when no legal element can reach the high\n // half — which is what a bound with both high halves zero says.\n return it.minHi === 0 && it.maxHi === 0 ? BM.Values32 : BM.Values;\n }\n\n /** The typed-destination check of {@link resolveTarget} for an unsigned array. */\n private typedModeU(\n it: IntegerArrayTarget,\n d: NonNullable<IntegerArrayTarget[\"typed\"]>,\n kind: ArrayKind,\n count: number,\n ): BM {\n if (d.length < count) {\n throw argumentError(\n `array ${this.id}: typed destination holds ${d.length} of ${count} elements`,\n );\n }\n // A destination NARROWER than the bound could not represent every legal\n // element, and a typed store would MASK it rather than refuse it — which is\n // the one thing §7.1 forbids. So the width is settled once, here, against\n // the bound the caller stated; the fill loop then needs no guard of its own\n // beyond that same bound.\n const cap = typedCapacity(d.constructor);\n const signed = kind === ArrayKind.Signed;\n if ((cap === undefined || cap.max === Number.POSITIVE_INFINITY) && is64(d)) {\n // The 64-bit pair covers the whole accumulator, so no bound can fall\n // outside it and there is nothing to compare. What it does need is the\n // view the fill writes halves through, built once per array.\n if (signed !== d instanceof BigInt64Array) {\n throw argumentError(\n `array ${this.id}: a 64-bit typed destination must match the array's signedness`,\n );\n }\n this.bulk64 = new Uint32Array(d.buffer, d.byteOffset, d.length * 2);\n return BM.Typed64;\n }\n const minV = signed ? (it.minHi | 0) * TWO32 + it.minLo : it.minHi * TWO32 + it.minLo;\n const maxV = signed ? (it.maxHi | 0) * TWO32 + it.maxLo : it.maxHi * TWO32 + it.maxLo;\n if (cap === undefined) {\n throw argumentError(`array ${this.id}: unsupported typed destination`);\n }\n if (minV < cap.min || maxV > cap.max) {\n throw argumentError(\n `array ${this.id}: the element bound ${minV}..${maxV} does not fit the` +\n ` typed destination (${cap.min}..${cap.max})`,\n );\n }\n return BM.Typed;\n }\n\n /** The signed twin of {@link typedModeU}: textually identical, for its own inline caches. */\n private typedModeS(\n it: IntegerArrayTarget,\n d: NonNullable<IntegerArrayTarget[\"typed\"]>,\n kind: ArrayKind,\n count: number,\n ): BM {\n if (d.length < count) {\n throw argumentError(\n `array ${this.id}: typed destination holds ${d.length} of ${count} elements`,\n );\n }\n // A destination NARROWER than the bound could not represent every legal\n // element, and a typed store would MASK it rather than refuse it — which is\n // the one thing §7.1 forbids. So the width is settled once, here, against\n // the bound the caller stated; the fill loop then needs no guard of its own\n // beyond that same bound.\n const cap = typedCapacity(d.constructor);\n const signed = kind === ArrayKind.Signed;\n if ((cap === undefined || cap.max === Number.POSITIVE_INFINITY) && is64(d)) {\n // The 64-bit pair covers the whole accumulator, so no bound can fall\n // outside it and there is nothing to compare. What it does need is the\n // view the fill writes halves through, built once per array.\n if (signed !== d instanceof BigInt64Array) {\n throw argumentError(\n `array ${this.id}: a 64-bit typed destination must match the array's signedness`,\n );\n }\n this.bulk64 = new Uint32Array(d.buffer, d.byteOffset, d.length * 2);\n return BM.Typed64;\n }\n const minV = signed ? (it.minHi | 0) * TWO32 + it.minLo : it.minHi * TWO32 + it.minLo;\n const maxV = signed ? (it.maxHi | 0) * TWO32 + it.maxLo : it.maxHi * TWO32 + it.maxLo;\n if (cap === undefined) {\n throw argumentError(`array ${this.id}: unsupported typed destination`);\n }\n if (minV < cap.min || maxV > cap.max) {\n throw argumentError(\n `array ${this.id}: the element bound ${minV}..${maxV} does not fit the` +\n ` typed destination (${cap.min}..${cap.max})`,\n );\n }\n return BM.Typed;\n }\n\n /**\n * The whole `S.ArrayUElem` arm for an array whose destination was handed over:\n * drain what this chunk holds, store a straddling tail element, close the array\n * when it ends. Returns the new read position; the caller's `break` then either\n * re-enters this state for the next chunk or leaves it, exactly as before.\n *\n * **Out of line, for the reason {@link fpDrain} already gives.** Everything\n * written into {@link push}'s switch is paid for by every decode that never\n * reaches it, so this arm is three lines at the call site and a method here.\n * Carrying its body in the switch instead cost `decode: typical` 5092 -> 5099\n * Ir/op and `decode: u64 array` 705.0k -> 708.5k; giving each bulk arm a state\n * of its own — which keeps the per-element arms untouched but adds three labels\n * — cost 5163 on `typical`, worse than either. What is left is what the\n * hand-off costs a decode that never takes it: 0.34% (5075 -> 5092, 702.5k ->\n * 705.0k), in the loop's own size.\n *\n * Suspension needs no signal of its own: a varint that did not complete consumed\n * the chunk to its end, so the returned position is `n` and the decode loop exits\n * on its own condition.\n *\n * **One loop per destination**, chosen once (see {@link bulkMode}) rather than\n * branched on per element: the shapes differ only in what a stored element *is*,\n * and a loop deciding that per element would give back what the hand-off saves.\n * `arrIndex` is likewise written once per drain instead of once per element,\n * which is part of why a bulk fill costs less than *discarding* the same\n * elements. A refusal mid-loop leaves it at the last committed value; nothing\n * reads it afterwards, because that verdict is terminal (§5.2.1).\n */\n private uBulkArm(\n input: Uint8Array,\n i: number,\n n: number,\n count: number,\n safeEnd: number,\n ): number {\n const t = this.bulk as IntegerArrayTarget;\n const mode = this.bulkMode;\n const minLo = t.minLo;\n const minHi = t.minHi;\n const maxLo = t.maxLo;\n const maxHi = t.maxHi;\n // Drain, then tail, then drain again — in **one** call. A short array is all\n // tail (the drain only runs where a whole varint is guaranteed to be in the\n // chunk, which the last ten bytes never are), so returning to the decode\n // switch per tail element put two calls and a re-read of the bound on every\n // element of exactly the arrays with the fewest to amortise them.\n for (;;) {\n if (this.vBytes === 0) {\n let idx = this.arrIndex;\n if (mode === BM.Values32) {\n const out = t.values!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n // A high half of its own puts the element past every 32-bit bound, so\n // one test covers \"too large to be this type\" and \"outside the bound\".\n if (this.vHi !== 0 || lo < minLo || lo > maxLo) this.outOfBound(idx);\n out[idx++] = lo;\n }\n } else if (mode === BM.Typed) {\n // The same two comparisons Values32 makes — the bound is the message's\n // verdict and a typed store would mask it away (§7.1) — over a\n // destination whose width `resolveTarget` has already matched to that\n // bound, so the store itself needs no guard.\n const out = t.typed!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n if (this.vHi !== 0 || lo < minLo || lo > maxLo) this.outOfBound(idx);\n out[idx++] = lo;\n }\n } else if (mode === BM.Typed64) {\n // Two raw halves per element, straight into the 64-bit array's own\n // storage: no `bigint` is built, which the element store this replaces\n // would have demanded one for.\n const out = this.bulk64!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n if (\n hi < minHi ||\n (hi === minHi && lo < minLo) ||\n hi > maxHi ||\n (hi === maxHi && lo > maxLo)\n ) {\n this.outOfBound(idx);\n }\n // `LO`/`HI` are the host's half order, probed once in `bits64` — the\n // same question this indexing asks, already answered there.\n out[idx * 2 + LO] = lo;\n out[idx * 2 + HI] = hi;\n idx++;\n }\n } else if (mode === BM.Bool) {\n // §4.4: every non-zero reads as `true`, and `1` is the only value an\n // encoder may write back — so the normalization is the store.\n const out = (this.bulk as BoolArrayTarget).bool;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n out[idx++] = this.vLo !== 0 || this.vHi !== 0 ? 1 : 0;\n }\n } else if (mode === BM.Values) {\n const out = t.values!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n if (\n hi < minHi ||\n (hi === minHi && lo < minLo) ||\n hi > maxHi ||\n (hi === maxHi && lo > maxLo)\n ) {\n this.outOfBound(idx);\n }\n out[idx++] = hi <= 0x1fffff ? hi * TWO32 + lo : joinU64(lo, hi);\n }\n } else if (mode === BM.Longs) {\n const out = t.longs!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n if (\n hi < minHi ||\n (hi === minHi && lo < minLo) ||\n hi > maxHi ||\n (hi === maxHi && lo > maxLo)\n ) {\n this.outOfBound(idx);\n }\n out[idx++] = new Long(lo, hi);\n }\n } else {\n const oLo = t.lo!;\n const oHi = t.hi!;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const lo = this.vLo >>> 0;\n const hi = this.vHi >>> 0;\n if (\n hi < minHi ||\n (hi === minHi && lo < minLo) ||\n hi > maxHi ||\n (hi === maxHi && lo > maxLo)\n ) {\n this.outOfBound(idx);\n }\n oLo[idx] = lo;\n oHi[idx] = hi;\n idx++;\n }\n }\n this.arrIndex = idx;\n }\n if (this.arrIndex === count) {\n this.endArray();\n return i;\n }\n if (i >= n) return i;\n // One element out of the resumable accumulator: the straddling case, and\n // every element of an array that sits in the last ten bytes of a chunk.\n i = this.varintStep(input, i);\n if (!this.vComplete) return i;\n // Out of line, like the float arm's: inlined here it makes this method big\n // enough that V8 optimises the fill loops above it worse (the float twin\n // measured 37 542 -> 49 154 Ir/op from exactly this).\n this.bulkStoreU(this.arrIndex, this.vLo >>> 0, this.vHi >>> 0);\n if (++this.arrIndex === count) {\n this.endArray();\n return i;\n }\n }\n }\n\n /** The signed twin of {@link uBulkArm}: the same shape, with the zig-zag undone. */\n private sBulkArm(\n input: Uint8Array,\n i: number,\n n: number,\n count: number,\n safeEnd: number,\n ): number {\n const t = this.bulk as IntegerArrayTarget;\n const mode = this.bulkMode;\n const minLo = t.minLo;\n const minHi = t.minHi | 0;\n const maxLo = t.maxLo;\n const maxHi = t.maxHi | 0;\n for (;;) {\n if (this.vBytes === 0) {\n let idx = this.arrIndex;\n while (idx < count && i <= safeEnd) {\n i = this.varintFull(input, i);\n const raw = this.vLo >>> 0;\n const rawHi = this.vHi >>> 0;\n const mask = -(raw & 1) >>> 0;\n const lo = ((((raw >>> 1) | (rawHi << 31)) >>> 0) ^ mask) >>> 0;\n const hi = ((rawHi >>> 1) ^ mask) >>> 0;\n const shi = hi | 0;\n if (\n shi < minHi ||\n (shi === minHi && lo < minLo) ||\n shi > maxHi ||\n (shi === maxHi && lo > maxLo)\n ) {\n this.outOfBound(idx);\n }\n if (mode === BM.Typed) {\n (t.typed as Int32Array)[idx] = lo | 0;\n } else if (mode === BM.Typed64) {\n const o = this.bulk64!;\n o[idx * 2 + LO] = lo;\n o[idx * 2 + HI] = hi;\n } else if (mode === BM.Values || mode === BM.Values32) {\n // vSigned() inlined: the halves are in hand and this runs per element.\n let v: number | bigint;\n if (rawHi <= 0x1fffff) {\n const r = rawHi * TWO32 + raw; // raw zig-zag, ≤ 2^53-1\n v = r % 2 === 0 ? r / 2 : -(r + 1) / 2;\n } else {\n v = joinI64(lo, hi);\n }\n t.values![idx] = v;\n } else if (mode === BM.Longs) {\n t.longs![idx] = new Long(lo, hi);\n } else {\n t.lo![idx] = lo;\n t.hi![idx] = hi;\n }\n idx++;\n }\n this.arrIndex = idx;\n }\n if (this.arrIndex === count) {\n this.endArray();\n return i;\n }\n if (i >= n) return i;\n i = this.varintStep(input, i);\n if (!this.vComplete) return i;\n this.bulkStoreS(this.arrIndex, this.vLo >>> 0, this.vHi >>> 0);\n if (++this.arrIndex === count) {\n this.endArray();\n return i;\n }\n }\n }\n\n /** The float twin of {@link uBulkArm}; a straddling element resumes through {@link fpStep}. */\n private fpBulkArm(\n input: Uint8Array,\n i: number,\n n: number,\n count: number,\n size: number,\n isFp32: boolean,\n ): number {\n if (this.have === 0 && this.arrIndex < count && n - i >= size) {\n const t = this.bulk as FloatArrayTarget;\n const run = Math.min(count - this.arrIndex, ((n - i) / size) | 0);\n let idx = this.arrIndex;\n const bitsOut = this.bulkMode === BM.F32Bits ? t.bits! : null;\n if (run >= (isFp32 ? FP32_HANDLE_MIN : FP64_HANDLE_MIN)) {\n // Past the threshold the handle pays for itself — for the wire words as\n // much as for the values: one `getUint32` beats four byte loads and a\n // shift per element (an fp32 run into `bits` measured 80 934 -> 37 611\n // Ir/op over 1000 elements).\n const dv = this.dataView(input);\n if (bitsOut !== null) {\n for (let k = 0; k < run; k++) {\n bitsOut[idx++] = dv.getUint32(i, true);\n i += 4;\n }\n } else if (isFp32) {\n const out = t.f32!;\n for (let k = 0; k < run; k++) {\n const v = dv.getFloat32(i, true);\n if (v === v) out[idx] = v;\n else this.f32StoreWord(out, idx, dv.getUint32(i, true));\n idx++;\n i += 4;\n }\n } else {\n const out = t.f64!;\n for (let k = 0; k < run; k++) {\n out[idx++] = dv.getFloat64(i, true);\n i += 8;\n }\n }\n } else if (bitsOut !== null) {\n // Below it, byte loads and no handle at all — the §6.6.2 count is the\n // one `fpDrain` already justified, unchanged by this hand-off.\n for (let k = 0; k < run; k++) {\n bitsOut[idx++] = u32le(input, i);\n i += 4;\n }\n } else if (isFp32) {\n const out = t.f32!;\n for (let k = 0; k < run; k++) {\n const w = u32le(input, i);\n if ((w & 0x7fffffff) > 0x7f800000) this.f32StoreWord(out, idx, w);\n else out[idx] = fp32FromBits(w);\n idx++;\n i += 4;\n }\n } else {\n const out = t.f64!;\n for (let k = 0; k < run; k++) {\n out[idx++] = fp64FromBits(u32le(input, i), u32le(input, i + 4));\n i += 8;\n }\n }\n this.arrIndex = idx;\n }\n if (this.arrIndex === count) {\n this.endArray();\n return i;\n }\n if (i >= n) return i;\n i = this.fpStep(input, i, n);\n if (this.have < this.need) return i;\n const lo = this.fpLo;\n const hi = this.fpHi;\n this.fpBegin(size); // next element starts from a clear accumulator\n this.bulkStoreFp(this.arrIndex, lo, hi, isFp32);\n if (++this.arrIndex === count) this.endArray();\n return i;\n }\n\n /**\n * Store an fp32 NaN into a `Float32Array` destination by its wire word (§4.6).\n * Widening a NaN to a double quiets a signaling one (and an engine may purify\n * the payload of any NaN it reads from a typed array), so a NaN never goes\n * through a value: it is written through a word view over the destination's own\n * storage. Every other fp32 survives the double exactly, which is why the view\n * is built lazily, on the array's first NaN, and never on the common path —\n * touching `.buffer` moves a small typed array's storage off the heap. It is\n * kept in {@link bulk64} for the rest of the array, so the count is one per\n * array however many NaNs the wire carries (§6.6.2).\n */\n private f32StoreWord(out: Float32Array, idx: number, word: number): void {\n let w = this.bulk64;\n if (w === null) w = this.bulk64 = new Uint32Array(out.buffer, out.byteOffset, out.length);\n w[idx] = word;\n }\n\n /** Store one float element that straddled a chunk boundary (see {@link bulkStoreU}). */\n private bulkStoreFp(idx: number, lo: number, hi: number, isFp32: boolean): void {\n const t = this.bulk as FloatArrayTarget;\n if (!isFp32) t.f64![idx] = fp64FromBits(lo, hi);\n else if (this.bulkMode === BM.F32Bits) t.bits![idx] = lo >>> 0;\n else if ((lo & 0x7fffffff) > 0x7f800000) this.f32StoreWord(t.f32!, idx, lo >>> 0);\n else t.f32![idx] = fp32FromBits(lo);\n }\n\n /**\n * Store one unsigned element that straddled a chunk boundary — the tail a drain\n * loop cannot take, resumed from the varint accumulator. At most one per chunk,\n * so it re-decides the destination rather than duplicating three loops.\n */\n private bulkStoreU(idx: number, lo: number, hi: number): void {\n const t = this.bulk as IntegerArrayTarget;\n if (\n hi < t.minHi ||\n (hi === t.minHi && lo < t.minLo) ||\n hi > t.maxHi ||\n (hi === t.maxHi && lo > t.maxLo)\n ) {\n this.outOfBound(idx);\n }\n if (this.bulkMode === BM.Values || this.bulkMode === BM.Values32) {\n t.values![idx] = this.vUnsigned();\n } else if (this.bulkMode === BM.Typed) {\n (t.typed as Uint32Array)[idx] = lo;\n } else if (this.bulkMode === BM.Typed64) {\n const o = this.bulk64!;\n o[idx * 2 + LO] = lo;\n o[idx * 2 + HI] = hi;\n } else if (this.bulkMode === BM.Bool) {\n (this.bulk as BoolArrayTarget).bool[idx] = lo !== 0 || hi !== 0 ? 1 : 0;\n } else if (this.bulkMode === BM.Longs) {\n t.longs![idx] = new Long(lo, hi);\n } else {\n t.lo![idx] = lo;\n t.hi![idx] = hi;\n }\n }\n\n /** The signed twin of {@link bulkStoreU}; `raw`/`rawHi` are the zig-zag halves. */\n private bulkStoreS(idx: number, raw: number, rawHi: number): void {\n const t = this.bulk as IntegerArrayTarget;\n const mask = -(raw & 1) >>> 0;\n const lo = ((((raw >>> 1) | (rawHi << 31)) >>> 0) ^ mask) >>> 0;\n const hi = ((rawHi >>> 1) ^ mask) >>> 0;\n const shi = hi | 0;\n if (\n shi < (t.minHi | 0) ||\n (shi === (t.minHi | 0) && lo < t.minLo) ||\n shi > (t.maxHi | 0) ||\n (shi === (t.maxHi | 0) && lo > t.maxLo)\n ) {\n this.outOfBound(idx);\n }\n if (this.bulkMode === BM.Values || this.bulkMode === BM.Values32) {\n t.values![idx] = this.vSigned();\n } else if (this.bulkMode === BM.Typed) (t.typed as Int32Array)[idx] = lo | 0;\n else if (this.bulkMode === BM.Typed64) {\n const o = this.bulk64!;\n o[idx * 2 + LO] = lo;\n o[idx * 2 + HI] = hi;\n } else if (this.bulkMode === BM.Longs) t.longs![idx] = new Long(lo, hi);\n else {\n t.lo![idx] = lo;\n t.hi![idx] = hi;\n }\n }\n\n /**\n * Refuse an element outside the bound its target declared (§7.3): the message\n * says a thing the schema does not allow, so it is `INVALID` and terminal, the\n * same verdict at the same point as a generated per-element guard raises today.\n * The destination keeps everything written before this element — see\n * {@link ArrayTarget}.\n */\n private outOfBound(index: number): never {\n // The prefix stands and the tail goes, exactly as on a completed array: what\n // is left is what this array wrote (see {@link trimPlain}).\n const t = this.bulk;\n if (t !== null) this.trimPlain(t, index);\n this.fail(`array ${this.id}: element ${index} outside the schema bound`);\n }\n\n /**\n * Report one payload piece: the caller's own fed chunk plus the coordinates of\n * the piece inside it (§6.6.3). No view is created — this decoder allocates\n * nothing (§6.6) and exposes no borrowed slice of its own (§6.7); `src` is the\n * very array the caller passed to `feed`, so whoever wants the bytes copies\n * them out of memory it already owns, during the call.\n */\n private emitBytes(src: Uint8Array, start: number, end: number): void {\n const v = this.cur;\n if (this.fixSub === FixlenSubtype.String) {\n v.string?.(this.id, this.fixLen, this.fixOff, src, start, end);\n } else {\n v.blob?.(this.id, this.fixLen, this.fixOff, src, start, end);\n }\n }\n\n /**\n * Consume varint bytes from `input` at `i` into the {@link vLo} / {@link vHi}\n * accumulator, resuming across chunk boundaries; sets {@link vComplete} when a\n * terminator byte arrives. Number-only — no per-byte `bigint`.\n */\n private varintStep(input: Uint8Array, i: number): number {\n // Fast path: a one-byte varint, which is what every small id, length, count\n // and scalar is. Resolved with a single load and no resume bookkeeping.\n if (this.vBytes === 0) {\n const n0 = input.length;\n const b0 = input[i]!;\n if (b0 < 0x80) {\n this.vLo = b0;\n this.vHi = 0;\n this.vComplete = true;\n return i + 1;\n }\n // Two- and three-byte varints resolved inline — that is every id past 15,\n // every mid-sized length or count, and the zig-zag of a small signed\n // scalar.\n if (i + 1 < n0) {\n const b1 = input[i + 1]!;\n if (b1 < 0x80) {\n this.vLo = (b0 & 0x7f) | (b1 << 7);\n this.vHi = 0;\n this.vComplete = true;\n return i + 2;\n }\n if (i + 2 < n0) {\n const b2 = input[i + 2]!;\n if (b2 < 0x80) {\n this.vLo = (b0 & 0x7f) | ((b1 & 0x7f) << 7) | (b2 << 14);\n this.vHi = 0;\n this.vComplete = true;\n return i + 3;\n }\n }\n }\n // Longer, and the whole of it is in this chunk: take the unrolled reader,\n // which needs no per-byte resume state at all.\n if (n0 - i >= VARINT_MAX_BYTES) return this.varintFull(input, i);\n }\n\n // A completed varint leaves `vBytes` at 0 and `vLo`/`vHi` stale, so a fresh\n // accumulation must start from zero rather than from those dead halves.\n const k0 = this.vBytes;\n let lo = k0 === 0 ? 0 : this.vLo;\n let hi = k0 === 0 ? 0 : this.vHi;\n let k = k0;\n const n = input.length;\n while (i < n) {\n if (k >= VARINT_MAX_BYTES) this.fail(\"varint overflow\");\n const b = input[i++]!;\n if (k < 4) lo |= (b & 0x7f) << (7 * k);\n else if (k === 4) {\n lo |= (b & 0x0f) << 28;\n hi |= (b >> 4) & 0x07;\n } else {\n // 10th byte (k === 9) has only bit 63 below 64; any higher payload bit\n // would spill past bit 63 and is a >64-bit overflow.\n if (k === 9 && ((b & 0x7f) >> 1) !== 0) this.fail(\"varint overflow\");\n hi |= (b & 0x7f) << (7 * k - 32);\n }\n k++;\n if ((b & 0x80) === 0) {\n this.vLo = lo;\n this.vHi = hi;\n this.vBytes = 0;\n this.vComplete = true;\n return i;\n }\n }\n // Out of chunk mid-varint. If the accumulator is already full, the byte that\n // filled it had its continuation flag set (a terminator returns above), so an\n // 11th byte is *required* — past the 10-byte / 64-bit maximum (§4.1.3). That\n // is decided by bytes already in hand, so it is INVALID now rather than a\n // suspend that {@link outcome} would report as INCOMPLETE: §5.2.3 gives INVALID\n // precedence, and the verdict must not depend on where the chunk boundaries\n // fell.\n if (k >= VARINT_MAX_BYTES) this.fail(\"varint overflow\");\n this.vLo = lo;\n this.vHi = hi;\n this.vBytes = k;\n this.vComplete = false;\n return i;\n }\n\n /**\n * Decode the varint at `i` **if that needs no resume bookkeeping**, returning\n * the index past it, or `-1` when it does (leaving the accumulator untouched,\n * so the resumable ladder starts the word from scratch).\n *\n * Three cases, in the order they are worth testing:\n *\n * * ten bytes in hand — the unrolled {@link varintFull}, no bounds checks at\n * all;\n * * a one-byte varint — every small id, length, count and scalar;\n * * a two-byte one — every id past 15, and mid-sized lengths and counts.\n *\n * Past that the word may straddle the chunk, and only the ladder can carry the\n * state across `feed` calls.\n */\n private varintQuick(input: Uint8Array, i: number, n: number): number {\n if (n - i >= VARINT_MAX_BYTES) return this.varintFull(input, i);\n if (i >= n) return -1;\n const b0 = input[i]!;\n if (b0 < 0x80) return this.setVarint(b0, 0, i + 1);\n if (i + 1 < n) {\n const b1 = input[i + 1]!;\n if (b1 < 0x80) return this.setVarint((b0 & 0x7f) | (b1 << 7), 0, i + 2);\n if (i + 2 < n) {\n const b2 = input[i + 2]!;\n if (b2 < 0x80) {\n return this.setVarint((b0 & 0x7f) | ((b1 & 0x7f) << 7) | (b2 << 14), 0, i + 3);\n }\n }\n }\n return -1;\n }\n\n /**\n * Decode one varint that is **guaranteed** to lie wholly within `input` — the\n * caller has checked that {@link VARINT_MAX_BYTES} bytes remain — into\n * {@link vLo} / {@link vHi}, returning the index past it.\n *\n * Unrolled and branch-per-byte: with the bytes known to be present there is no\n * bounds check, no resume counter and no `k`-dispatch per byte, which is the\n * whole per-byte cost of the resumable loop above. Reports the same `>64-bit`\n * overflow as that loop.\n */\n private varintFull(input: Uint8Array, i: number): number {\n let b = input[i]!;\n let lo = b & 0x7f;\n let hi = 0;\n if (b < 0x80) return this.setVarint(lo, 0, i + 1);\n\n b = input[i + 1]!;\n lo |= (b & 0x7f) << 7;\n if (b < 0x80) return this.setVarint(lo, 0, i + 2);\n\n b = input[i + 2]!;\n lo |= (b & 0x7f) << 14;\n if (b < 0x80) return this.setVarint(lo, 0, i + 3);\n\n b = input[i + 3]!;\n lo |= (b & 0x7f) << 21;\n if (b < 0x80) return this.setVarint(lo, 0, i + 4);\n\n // 5th byte straddles the 32-bit boundary: 4 bits to lo, 3 bits to hi.\n b = input[i + 4]!;\n lo |= (b & 0x0f) << 28;\n hi = (b >> 4) & 0x07;\n if (b < 0x80) return this.setVarint(lo, hi, i + 5);\n\n b = input[i + 5]!;\n hi |= (b & 0x7f) << 3;\n if (b < 0x80) return this.setVarint(lo, hi, i + 6);\n\n b = input[i + 6]!;\n hi |= (b & 0x7f) << 10;\n if (b < 0x80) return this.setVarint(lo, hi, i + 7);\n\n b = input[i + 7]!;\n hi |= (b & 0x7f) << 17;\n if (b < 0x80) return this.setVarint(lo, hi, i + 8);\n\n b = input[i + 8]!;\n hi |= (b & 0x7f) << 24;\n if (b < 0x80) return this.setVarint(lo, hi, i + 9);\n\n // 10th byte: only bit 63 (1 payload bit) remains below 64; any higher payload\n // bit, or a continuation into an 11th byte, is a >64-bit overflow.\n b = input[i + 9]!;\n if (((b & 0x7f) >> 1) !== 0) this.fail(\"varint overflow\");\n hi |= (b & 0x7f) << 31;\n if (b < 0x80) return this.setVarint(lo, hi, i + 10);\n\n this.fail(\"varint overflow\");\n }\n\n /** Publish a fully-decoded varint and the cursor past it (see {@link varintFull}). */\n private setVarint(lo: number, hi: number, i: number): number {\n this.vLo = lo;\n this.vHi = hi;\n this.vBytes = 0;\n this.vComplete = true;\n return i;\n }\n\n /**\n * The accumulated varint as an unsigned value, number-first: a `number` when it\n * fits exactly (`≤ 2^53-1`, which covers all ids, u8..u32 and small u64s), a\n * `bigint` only beyond that.\n */\n private vUnsigned(): number | bigint {\n // Unsigned: vHi's bit 31 must not read as negative. vHi ≤ 0x1fffff (2^21-1)\n // ⇔ vHi*2^32 + lo ≤ 2^53-1.\n const hi = this.vHi >>> 0;\n return hi <= 0x1fffff\n ? hi * TWO32 + (this.vLo >>> 0)\n : joinU64(this.vLo >>> 0, hi); // one bigint, not four (bits64)\n }\n\n /** The accumulated zig-zag varint as a signed value, number-first (see {@link vUnsigned}). */\n private vSigned(): number | bigint {\n const hi = this.vHi >>> 0;\n if (hi <= 0x1fffff) {\n const r = hi * TWO32 + (this.vLo >>> 0); // raw zig-zag, ≤ 2^53-1\n return r % 2 === 0 ? r / 2 : -(r + 1) / 2;\n }\n const lo = this.vLo >>> 0;\n const mask = -(lo & 1) >>> 0;\n return joinI64(\n ((((lo >>> 1) | (hi << 31)) >>> 0) ^ mask) >>> 0,\n ((hi >>> 1) ^ mask) >>> 0,\n );\n }\n\n /**\n * The accumulated varint as a JS number — exact for ids/lengths/counts.\n *\n * The `>>> 0` is load-bearing: `vHi` is accumulated with 32-bit bitwise ops, so\n * bit 63 of the varint lands on its sign bit and the value reads back negative,\n * sliding past the `count > ARRAY_MAX` guard.\n */\n private vNum(): number {\n return (this.vHi >>> 0) * TWO32 + (this.vLo >>> 0);\n }\n\n /** The accumulated varint with its low 3 tag bits stripped (`value >> 3`). */\n private vUpper(): number {\n return (this.vHi >>> 0) * (TWO32 / 8) + (this.vLo >>> 3);\n }\n\n /**\n * The handle over `input`, built on demand and reused while the same chunk is\n * being fed (see {@link view}).\n */\n private dataView(input: Uint8Array): DataView {\n if (this.viewOf !== input) {\n this.view = new DataView(input.buffer, input.byteOffset, input.byteLength);\n this.viewOf = input;\n }\n return this.view!;\n }\n\n /** Accumulate up to `need` raw float bytes into {@link fpLo} / {@link fpHi}. */\n private fpStep(input: Uint8Array, i: number, n: number): number {\n let have = this.have;\n const need = this.need;\n while (have < need && i < n) {\n const b = input[i++]!;\n if (have < 4) this.fpLo |= b << (have << 3);\n else this.fpHi |= b << ((have - 4) << 3);\n have++;\n }\n this.have = have;\n return i;\n }\n\n /** Start a fresh fp accumulation of `need` bytes. */\n private fpBegin(need: number): void {\n this.need = need;\n this.have = 0;\n this.fpLo = 0;\n this.fpHi = 0;\n }\n}\n\n/**\n * The four little-endian bytes at `i` as one unsigned 32-bit word — the float\n * routes that do not clear the {@link FP32_HANDLE_MIN} threshold read their raw\n * bits this way, with no handle over the chunk.\n */\nfunction u32le(b: Uint8Array, i: number): number {\n return (b[i]! | (b[i + 1]! << 8) | (b[i + 2]! << 16) | (b[i + 3]! << 24)) >>> 0;\n}\n","/**\n * The SofaBuffers decoder: `IStream`, and the visitor it drives.\n *\n * The **visitor is the only decode surface** (CORELIB_PLAN §5.3.1). There is no\n * pull parser, no iterator, no cursor and no convenience wrapper that decodes by\n * another route: a second surface is a second implementation of every rule in the\n * spec, and the divergences that produces are invisible to the shared vectors,\n * which exercise whichever surface the driver happened to pick.\n *\n * `IStream` is a push parser: bind a {@link Visitor} at construction, feed bytes\n * with {@link IStream.feed}, and it calls one method per decoded field. It is a\n * resumable state machine, so the chunks can be any size — a whole message, a\n * network packet, or a single byte — and a field that straddles a chunk boundary\n * is picked up seamlessly on the next call.\n *\n * The visitor is **flat**: one object receives the whole message, and nesting is\n * reported as {@link Visitor.sequenceBegin} / {@link Visitor.sequenceEnd} events\n * carrying the sequence's id and depth. A visitor per nested scope would make\n * every dispatch site here megamorphic — one hidden class per generated message\n * class in the tree — and would put a per-scope object on the decode path; one\n * flat visitor keeps the call sites (bi)morphic and the decoder allocation-free\n * (§6.6). Descending and skipping are unchanged by that choice: `sequenceBegin`\n * answers `false` to decline a subtree whole, and a field whose callback the\n * visitor does not implement is skipped.\n *\n * There is no finish / finalize step (§5.2.4) and no status accessor beside the\n * call: {@link IStream.feed} *returns* the outcome for the bytes consumed so far,\n * and that return value is the whole answer. A message that merely ends inside a\n * field is reported — never thrown — as {@link DecodeStatus.Incomplete}; only a\n * *malformed* message throws ({@link SofabErrorCode.InvalidMsg}), which is this\n * port's channel for {@link DecodeStatus.Invalid}. The caller owns end-of-input\n * and decides whether a trailing `Incomplete` is a truncation error.\n *\n * **One fact, one channel.** Each outcome leaves by exactly one route — two of\n * the three by the return value, the refusals by the throw — because a second way\n * to ask the same question is a second thing to keep in step, and this family\n * shipped the drift: a `status()` accessor answered `COMPLETE` for a message\n * `feed` had already refused. §5.3.1 makes the general form of the argument for\n * decode surfaces (\"every additional surface is a second implementation of every\n * rule in this document\"); the accessor was the same mistake one size down.\n */\n\nimport { DecodeStatus } from \"../constants.js\";\nimport type { ArrayKind, FeedStatus, FixlenSubtype, WireType } from \"../constants.js\";\nimport { incompleteError } from \"../errors.js\";\nimport type { Long } from \"../long.js\";\nimport { DecoderState } from \"./state.js\";\n\n/**\n * Where an array's elements are written when the visitor takes the **bulk\n * hand-off** ({@link Visitor.arrayBulk}): the destination it already owns, handed\n * over once, instead of one callback per element.\n *\n * **Why this replaced the per-element callbacks.** There used to be an\n * `arrayUnsigned` / `arraySigned` / `arrayFp32` / `arrayFp64` beside this, one call\n * per element. Measured with `bench/run_callgrind.sh`'s method over 1000-element\n * arrays (Ir/op for a message that is one array), against this hand-off filling\n * the same destination:\n *\n * | array | per element (removed) | hand-off | |\n * |---|---:|---:|---:|\n * | `array<u16>` into a `number[]` | 235 433 | 184 025 | −21.8% |\n * | `array<u64>` into a `Long[]` | 576 206 | 429 113 | −25.5% |\n * | `array<u64>` into {@link IntegerArrayTarget.lo}/`hi` | 498 618 | 299 180 | −40.0% |\n * | `array<fp64>` into a `Float64Array` | 93 520 | 36 890 | −60.6% |\n * | `array<fp32>` into a `Float32Array` | 94 497 | 35 259 | −62.7% |\n *\n * Floats gain most because their *reading* was already bulk (the §6.6.2 handle in\n * the element drain), so the callback was very nearly all that was left.\n *\n * **A short array is not the exception.** The fixed cost — the offer, the\n * target's resolution, the bound's validation — is about 600 Ir, but the hand-off\n * takes a whole array in one call, tail elements included, so it is paid once:\n * four elements at the end of a 37-byte message cost 578 Ir against the 563 the\n * removed callbacks cost, and everything longer is the table above.\n *\n * **What did move is the consumer's side, for a consumer that folds.** An element\n * callback let a reader sum, hash or convert *inside* the delivery; reading a\n * filled destination is a second pass. A reader that wants the values where they\n * are — which is what generated code wants — has no second pass and gets the\n * table. A reader that folds pays one: the same four-element array costs 1 063 Ir\n * if it sums the destination at `arrayEnd`, against 563 folding per element.\n * It is a cheaper pass than the calls it replaced on any array long enough to\n * matter, and on a four-element one it is not.\n *\n * **Declining costs nothing at all.** An array no visitor takes is walked over\n * rather than decoded: `array<fp64>` 36 890 → 9 383 Ir/op, `array<u16>` 184 025 →\n * 152 082.\n *\n * **This is how array elements are delivered — the only way.** There is no\n * callback per element beside it: §5.3.1 allows a rule one implementation, and\n * two delivery routes for the same elements were two places for the element bound\n * to be compared, two resume paths to keep in step, and a standing invitation for\n * generated code to take the slower one. `arrayBegin` and `arrayEnd` still fire\n * for every array; returning `null` declines delivery, and the elements are then\n * walked over without being decoded into existence — the `skip` half of §6.7.2's\n * two intents, which is what a visitor that declares no `arrayBulk` gets for\n * every array.\n *\n * **The destination is filled ascending from index 0**, one write per element,\n * and it must stay valid — same object, same length — until `arrayEnd`, which for\n * a chunked decode is several {@link IStream.feed} calls later. A plain-array\n * destination (`values` / `longs`) is **cut to the elements written when the array\n * ends** — including to zero for an array that is empty on the wire, and to the\n * prefix when an element is refused — so reusing one across arrays or messages can\n * never leave the previous array's tail behind, and after `arrayEnd` its `length`\n * is exactly this array's element count. (Cutting at the end rather than emptying\n * up front is measured: emptying first makes every element write a grow, which\n * cost `array<u16>` 181 583 → 231 815 Ir/op.) A typed destination is neither cut\n * nor emptied — it cannot be — and must already hold `count` elements.\n *\n * A decode that fails *inside* an array for any other reason — malformed bytes, or\n * input that simply ends — leaves the destination holding what had been written\n * when it stopped. `length` is a statement about the array only once `arrayEnd`\n * has been raised or an element has been refused. This is the one\n * place the codec holds a reference to the caller's storage between calls (§6.6\n * otherwise holds nothing past a callback), and the reference is dropped at\n * `arrayEnd` and whenever a pooled machine is released.\n *\n * **A refused element leaves the destination holding the prefix**: everything\n * before it is written, the offending element and everything after it is not, and\n * a plain-array destination is cut to exactly that length. Like every `INVALID`\n * verdict it is terminal (§5.2.1).\n */\nexport type ArrayTarget = IntegerArrayTarget | FloatArrayTarget | BoolArrayTarget;\n\n/**\n * A `boolean` array's destination: one byte per element, `0` or `1`.\n *\n * It carries **no bound**, and that is the whole reason it is a shape of its own\n * rather than a {@link IntegerArrayTarget.typed} `Uint8Array`. §4.4 gives a boolean\n * no width bound — every non-zero wire value is `true` — so there is no interval to\n * state and nothing for the width check to compare. A raw store would be wrong\n * twice over: 256 would mask to `0` and turn `true` into `false`. The decoder\n * NORMALIZES instead, writing `1` for any non-zero, which is also the only value\n * §4.4 lets an encoder emit back — so a filled destination re-encodes canonically\n * with no conversion step in between.\n */\nexport interface BoolArrayTarget {\n bool: Uint8Array;\n}\n\n/**\n * An integer array's destination and the **element bound** to enforce while\n * filling it — for an `ArrayKind.Unsigned` or `ArrayKind.Signed` array.\n *\n * Exactly one destination must be set (`values`, `longs`, or `lo` *and* `hi`);\n * any other combination is a caller mistake and is refused with\n * {@link SofabErrorCode.Argument} before a single element is written.\n *\n * **The bound is four halves, and it is never optional.** The interval is the\n * schema's — `0..65535` for a `u16`, `-2^63..2^63-1` for an `i64` — so its\n * violation is `INVALID`, a statement about the message (§6.2.1 keeps a\n * *receiver* cap off a field the schema already bounds; a receiver cap on the\n * element *count* is compared by the visitor in `arrayBegin`, as before, and this\n * hand-off happens after it).\n *\n * Halves rather than a `number` pair because a `number` cannot express the\n * 64-bit domain: `u64`'s bound is `2^64-1` and `Number.MAX_SAFE_INTEGER` is\n * `2^53-1`, so a `number` bound both *rejects valid messages* at the top of the\n * range and makes the comparison a mixed `bigint`/`number` one, which measured\n * +35% on `array<u64>` — worse than the per-element path it replaces. Two\n * unsigned 32-bit comparisons are exact and cost nothing.\n *\n * For a **signed** array the halves are the two's-complement ones (an `i16`\n * minimum of `-32768` is `minLo = 0xffff8000`, `minHi = 0xffffffff`).\n * {@link Long.fromBigInt} is the ready-made way to compute them from the schema's\n * bound once.\n *\n * The codec **compares** the bound; it never owns one (§6.2.1). There is no\n * default and no \"unbounded\" spelling, because an integer element always has a\n * declared width: the widest `u64` interval is `0 .. 0xffffffff_ffffffff` and is\n * stated as such.\n */\nexport interface IntegerArrayTarget {\n /**\n * Number-first destination: each element as the `value` its per-element\n * callback would have received — a `number` when it fits exactly (`≤ 2^53-1`,\n * every `u8`..`u32` and small 64-bit values) and a `bigint` beyond that. The\n * right destination for `u8`..`u32` / `i8`..`i32` arrays, where no `bigint` is\n * ever built.\n *\n * A real `Array` — grown as it fills and cut to length when the array ends, so\n * it need not be pre-sized and never carries a previous array's tail. A typed\n * array here is refused with {@link SofabErrorCode.Argument}: it would take the\n * writes and silently drop everything past its own length.\n */\n values?: (number | bigint)[];\n /**\n * Destination taking each element as a {@link Long} — no `bigint` is\n * materialised at all, which is most of why this is a quarter cheaper than the\n * per-element path for a 64-bit array (see {@link ArrayTarget}). A real\n * `Array`, cut to length at the array's end, exactly like {@link values}.\n */\n longs?: Long[];\n /**\n * Allocation-free destination: the element's low half at `lo[index]` and its\n * high half at `hi[index]` (for a signed array, the two's-complement halves).\n * Both must be set and both must hold at least `count` elements. The fastest\n * shape there is — nothing is allocated per element, not even a `Long`.\n */\n /**\n * Exact-width destination: one typed array whose element width IS the schema's\n * declared width — a `Uint16Array` for a `u16` array, an `Int8Array` for an\n * `i8` one. Must hold at least `count` elements.\n *\n * **The bound is still compared, and that is not negotiable.** A typed array\n * *masks* on store (`a[0] = 70000` in a `Uint16Array` is 4464), and\n * MESSAGE_SPEC §7.1 makes an element outside the declared width INVALID —\n * neither masked to the width nor kept. So this destination buys the storage,\n * never the verdict: the fill loop compares exactly as {@link values} does and\n * refuses the same elements.\n *\n * What it does buy is the store (unboxed, and no element-kind transition the\n * way a `number[]` takes when a value leaves the small-integer range), the\n * memory (2 bytes for a `u16`, against a tagged slot), and the *encoder's*\n * side, where the width is then statically known.\n *\n * The bound must fit the array's own width: a destination narrower than the\n * interval could not represent every legal element, and is refused with\n * {@link SofabErrorCode.Argument} rather than silently masking.\n */\n typed?:\n | Uint8Array\n | Uint16Array\n | Uint32Array\n | Int8Array\n | Int16Array\n | Int32Array\n | BigUint64Array\n | BigInt64Array;\n lo?: Uint32Array;\n /** The high halves; see {@link lo}. */\n hi?: Uint32Array;\n /** Low half of the smallest element the schema allows. */\n minLo: number;\n /** High half of the smallest element the schema allows. */\n minHi: number;\n /** Low half of the largest element the schema allows. */\n maxLo: number;\n /** High half of the largest element the schema allows. */\n maxHi: number;\n}\n\n/**\n * A float array's destination — for an `ArrayKind.Fp32` or `ArrayKind.Fp64`\n * array. Exactly one of the two must be set, it must match the element width the\n * array's own `fixlen_word` declared (§4.8), and it must hold at least `count`\n * elements; anything else is refused with {@link SofabErrorCode.Argument} before\n * a single element is written.\n *\n * There is no bound here: §4.6 gives a float no schema interval to violate, so\n * there is nothing to compare and nothing for the caller to state.\n *\n * An `fp32` array chooses between the two: {@link f32} takes values, {@link bits}\n * takes the wire words. The choice is real, not stylistic — reading an `fp32`\n * through a double quiets a *signaling* NaN (`0x7fa00001` comes back\n * `0x7fe00001`), so a reader that must reproduce `fp32` payloads bit-for-bit\n * (§4.6/§6.5) takes {@link bits}. `fp64` needs no such choice: a `Float64Array`\n * carries all 64 bits, payload NaNs included.\n */\nexport interface FloatArrayTarget {\n /** Value destination for an `ArrayKind.Fp32` array. */\n f32?: Float32Array;\n /**\n * Bit destination for an `ArrayKind.Fp32` array: each element as its 4 wire\n * bytes in one little-endian 32-bit word — the same number `OStream.writeFp32Bits`\n * takes, so a payload read through this and written back reproduces the wire\n * exactly, signaling NaNs included.\n */\n bits?: Uint32Array;\n /** Destination for an `ArrayKind.Fp64` array. */\n f64?: Float64Array;\n}\n\n/**\n * Receives decoded fields from an {@link IStream} — the one decode surface\n * (§5.3.1). Every method is optional and defaults to a no-op, so a visitor\n * implements only the fields it cares about and silently skips the rest, which is\n * the `skip` half of the two per-field intents §6.7.2 allows (the other being\n * `read`: take the value, in the call).\n *\n * **One visitor per message, not per scope.** Nested sequences arrive as\n * {@link sequenceBegin} / {@link sequenceEnd} events on this same object, each\n * carrying the sequence's `id` and its `depth` (1 for a sequence opened at the\n * root). Generated code routes on those two numbers, which it knows statically\n * from the schema.\n *\n * **Nothing handed to a visitor outlives the call.** A `string` / `blob` payload\n * is reported in pieces as a range of the caller's *own* fed chunk (§6.6.3): the\n * decoder creates no view over it and holds no storage of its own (§6.6, §6.7),\n * so a consumer that wants the value copies it out — during the call — into\n * storage it owns. {@link PayloadAcc} and {@link decodeUtf8} are the ready-made\n * way to do that.\n */\nexport interface Visitor {\n /**\n * A field **header**: its `id` and `wire` type, announced the moment the header\n * varint is complete — before the value, and before the value's own header word\n * (a fixlen length word, an array count word, the fields of a nested sequence).\n *\n * An observation point for a reader that wants the field stream as it arrives —\n * which id, in which scope, in which order — without implementing the value\n * callbacks it would otherwise take to see the same thing.\n *\n * **A schema bound does not belong here.** The header settles `id` and `wire`,\n * and nothing else. An element id past the schema `count` (MESSAGE_SPEC\n * §7.1/§5.1) looks decidable from the id alone, and it is not: §7.3 applies that\n * bound only to a field whose *subtype* has confirmed it is the declared one,\n * and a contradicting subtype is skipped rather than rejected. The subtype\n * arrives in the fixlen word, so the verdict is due at {@link fixlenBegin}.\n * CORELIB_PLAN §4.1.1 makes the timing normative: a message ending inside that\n * word is `INCOMPLETE` even when the id would violate a schema bound, because\n * the low 3 bits of an unfinished varint must not influence an outcome even\n * though they are already arithmetically fixed.\n *\n * Called exactly once per field, in every scope, for every wire type — the\n * sequence *end* marker excepted: it closes a scope rather than opening a field\n * and its id is discarded (§4.9). For a nested sequence it fires before\n * {@link sequenceBegin}.\n *\n * Throwing from it rejects the field — for a verdict the header really does\n * settle on its own, such as an id this reader will not accept in any shape.\n */\n fieldBegin?(id: number, wire: WireType): void;\n /**\n * An unsigned integer field.\n *\n * `value` is number-first: a `number` when the value fits exactly\n * (`≤ 2^53-1`, covering ids, u8..u32 and small u64s) and a `bigint` only beyond\n * that. `lo` / `hi` are the exact 64 bits as two unsigned 32-bit halves — the\n * ones the varint reader already holds — for a consumer that wants the value\n * bit-exactly without going through `bigint` arithmetic ({@link Long.fromBits}\n * builds a `Long` from them). Both describe the same value; use whichever fits.\n */\n unsigned?(id: number, value: number | bigint, lo: number, hi: number): void;\n /**\n * A signed integer field. `value` is number-first like {@link unsigned}\n * (`|value| ≤ 2^53-1` ⇒ `number`); `lo` / `hi` are the **decoded**\n * (zig-zag-undone) two's-complement halves.\n */\n signed?(id: number, value: number | bigint, lo: number, hi: number): void;\n /**\n * An IEEE-754 32-bit float field.\n *\n * `value` is a JS `number` — a 64-bit double — and widening a *signaling* NaN\n * into a double quiets it (sets the is-quiet bit), so `value` cannot represent\n * an fp32 sNaN faithfully. `bits` is the exact 4 wire bytes as one little-endian\n * 32-bit word, which can: re-encode from it with\n * {@link OStream.writeFp32Bits} and the payload round-trips bit-for-bit\n * (§4.6/§6.5). It is the \"32-bit bits accessor\" §6.5 names, and it is always\n * present — a number costs nothing to pass and needs no opt-in flag, where the\n * byte view it replaces was an allocation per value and a borrowed slice §6.7\n * forbids.\n */\n fp32?(id: number, value: number, bits: number): void;\n /** An IEEE-754 64-bit double field. `value` is exact — a double is 64 bits wide. */\n fp64?(id: number, value: number): void;\n /**\n * Start of a `string`/`blob` field: `total` payload bytes follow, in one or more\n * {@link string}/{@link blob} calls.\n *\n * The counterpart of {@link arrayBegin}, and it exists for the same reason: a\n * receiver-side bound on the *declared length* is decided by this word, not by\n * the payload. Without it a visitor could only see `total` once payload bytes\n * arrive, so a message that ends right after an over-bound length word would\n * escape the check and degrade to `INCOMPLETE`, where §5.2.3 requires `INVALID`.\n *\n * Called exactly once per field, before any payload call — including for a\n * zero-length payload, which is still announced here and then delivered as one\n * empty range.\n */\n fixlenBegin?(id: number, subtype: FixlenSubtype, total: number): void;\n /**\n * A piece of a UTF-8 string field: the bytes `src[start..end)`, at `offset` of\n * a `total`-byte payload.\n *\n * `src` is the **caller's own chunk** — the exact array passed to\n * {@link IStream.feed} (or to {@link decode}) — handed back with the piece's\n * coordinates (§6.6.3). The decoder builds no view over it, keeps no storage,\n * and hands out no borrowed slice of its own (§6.6, §6.7). Once `feed` returns,\n * the caller may reuse that memory, so a consumer that wants the value copies it\n * out **during the call**: {@link PayloadAcc} joins pieces into a buffer it\n * owns, and {@link decodeUtf8} turns a range straight into a string.\n *\n * The bytes are **not validated**. §6.4.5 puts the UTF-8 check where a string is\n * *materialized* — a piece may end mid-code-point, and a skipped field is never\n * validated at all — so on this surface the caller who materializes owns the\n * check. {@link decodeUtf8} is it, and a hand-rolled one must be built **fatal**\n * (`new TextDecoder(\"utf-8\", { fatal: true })`): JavaScript's default\n * `TextDecoder` substitutes `U+FFFD`, which §6.4 forbids in either direction.\n */\n string?(\n id: number,\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n ): void;\n /** A piece of a blob field — see {@link string} for the `src`/`start`/`end` contract. */\n blob?(\n id: number,\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n ): void;\n /** Start of an array; `count` elements of `kind` follow. */\n arrayBegin?(id: number, kind: ArrayKind, count: number): void;\n /**\n * Offer of the **bulk hand-off**: return the destination this visitor has\n * already allocated for array `id` and the decoder fills it directly, one write\n * per element and no callback at all; return `null` (or leave this method\n * unimplemented) to be served element by element as before.\n *\n * Called once per array, after {@link arrayBegin} and before the first element —\n * so a receiver cap on `count` is still compared where it always was, in\n * `arrayBegin`, and a rejected array is never offered. **An array that is empty\n * on the wire is offered too**, with `count` of 0: there is nothing to write,\n * but a destination held across fields would otherwise still hold the previous\n * array's elements, and its length is the only place this array's emptiness\n * could show.\n *\n * `kind` is the element kind and it decides which destination is legal\n * ({@link IntegerArrayTarget} for `Unsigned` / `Signed`,\n * {@link FloatArrayTarget} for `Fp32` / `Fp64`); a destination that contradicts\n * it, or that is shorter than `count`, is a caller mistake and is refused with\n * {@link SofabErrorCode.Argument} before any element is written. Declining on\n * a kind this visitor did not expect is always available — and is the right\n * answer, since `null` costs nothing but the call.\n *\n * See {@link ArrayTarget} for what the decoder then guarantees: ascending\n * writes, the element bound enforced here and only here, the destination held\n * until `arrayEnd` across as many `feed` calls as the chunking takes, and a\n * partially filled destination if an element is refused.\n */\n arrayBulk?(id: number, kind: ArrayKind, count: number): ArrayTarget | null;\n /** End of an array. */\n arrayEnd?(id: number): void;\n /**\n * Start of a nested sequence — a fresh id scope (§4.9) — opened by field `id`\n * at `depth` (1 at the root).\n *\n * Return **`false`** to decline the whole subtree: no callback of any kind fires\n * inside it, nesting included, its own {@link sequenceEnd} included, and a scope\n * opened within it is never offered either. Return anything else (or nothing) to\n * descend, and the nested fields arrive on this same visitor with their own ids\n * and `depth + 1`.\n *\n * A declined subtree is still *parsed* — a sequence is framed by markers, not by\n * a length, so its end has to be found — but nothing in it is decoded into\n * existence: no piece is reported and no value is built. No receiver cap fires\n * inside one either (§6.2.1's \"a skipped field is never capped\"), and that falls\n * out of the structure rather than needing a rule: a cap is compared by the\n * handler this stream would have called, and a declined scope calls none. Format\n * ceilings (`ARRAY_MAX`, `FIXLEN_MAX`, `MAX_DEPTH`, the varint bound) still apply\n * everywhere: they bound what the wire may express.\n */\n sequenceBegin?(id: number, depth: number): boolean | void;\n /** End of the nested sequence opened by field `id` at `depth`. */\n sequenceEnd?(id: number, depth: number): void;\n}\n\n/**\n * Push parser for the SofaBuffers wire format, and the library's only decode\n * surface (§5.3.1).\n *\n * Bind a {@link Visitor} at construction, then feed bytes in chunks of any size\n * with {@link feed}: it calls one visitor method per decoded field and resumes\n * cleanly across chunk boundaries. Every `feed` returns the decode outcome for the\n * bytes so far, so no end / finalize call is needed — and there is nothing else to\n * ask: `feed` is the only way to learn where a stream stands, by what it returns\n * or by what it throws.\n *\n * **No receiver limit is configured here, because this codec holds none**\n * (§6.2.1). A `max_dyn_*` cap is the receiving *application's* number, stated by\n * generated code, which knows the schema and the target; it is compared inside the\n * visitor's own `arrayBegin` / `fixlenBegin` — raised by this stream at the count\n * or length header, before any payload is delivered and only for a field the\n * visitor reads — and, for a wrapper array's `string` / `blob` elements, inside\n * the `StringSeq` / `BlobSeq` collector those bounds were passed to.\n * This class used to take a `DecodeLimits` and default every absent cap to the\n * format ceiling, which §6.2.1 forbids twice over: a codec must not supply a\n * default for a limit it was not given, and a format ceiling reached because no\n * cap was stated is the format's bound and must not be presented as a receiver\n * cap.\n *\n * Constructing one is the only allocating step (§6.6): `feed` itself allocates\n * nothing at all. The one-shot {@link decode} is exactly this class fed once.\n */\nexport class IStream {\n private readonly state: DecoderState;\n\n /**\n * @param visitor The field handler this stream drives, for its whole life — and\n * the layer that holds the receiver caps, if any (§6.2.1; see the class doc).\n */\n constructor(visitor: Visitor) {\n this.state = new DecoderState(visitor);\n }\n\n /**\n * Feed a chunk of bytes, dispatching decoded fields to the bound visitor, and\n * **return** where the decode stands after them (§5.2.1):\n * {@link DecodeStatus.Complete} when they end exactly at a field boundary,\n * {@link DecodeStatus.Incomplete} when they end *inside* a field (a partial\n * varint, an unfinished payload / array, or a still-open nested sequence).\n * Running out of bytes mid-field is not an error — the decode merely suspends\n * until the next chunk, and the caller owns end-of-input.\n *\n * **This call is the only place the answer is.** There is no finish / finalize\n * step (§5.2.4) and no status accessor: what this returns, or throws, is the\n * whole of what the stream has to say, so a caller is never one question short\n * after it and never has two answers to reconcile. Feeding an empty chunk\n * re-reads the same value without consuming anything, for a caller that wants\n * the outcome again without holding on to it.\n *\n * The chunk is borrowed **only for the duration of this call** (§6.0): once it\n * returns, the caller may reuse, overwrite or free that memory, and the decoded\n * message is unaffected — the decoder retains nothing that points into it.\n *\n * `INVALID` travels on the error channel — this port's idiomatic surfacing of\n * it: *malformed* bytes throw {@link SofabError} (`INVALID_MSG`) instead of\n * returning a status, which is why the return type names only the other two.\n * That verdict is **terminal** (§5.2.1): the stream latches it, so a caller that\n * catches the throw and feeds on gets the same error again from every later\n * call — no further byte is consumed and no visitor method is invoked. A caller\n * that caught it already holds the verdict, in the code on the error it caught.\n *\n * A receiver-limit rejection (`LIMIT_EXCEEDED`, §6.2.1) travels the same\n * channel — thrown out of the visitor callback that compared the cap — but it\n * is **not** the `INVALID` outcome and never becomes one: the bytes are\n * well-formed and the same message decodes under a looser cap, so it is a\n * policy rejection (§6.2.1, §6.3). The two stay distinguishable by their code,\n * which is what §6.3 requires; §6.3 leaves the surfacing open between \"a fourth\n * decode outcome\" and \"a terminal failure carrying the `LimitExceeded` code on\n * the error channel\", and this port takes the second. **Terminal** is the other\n * half of that sentence and holds exactly as it does for `INVALID`: the stream\n * latches the rejection, so every later call re-throws it under the same code,\n * consumes no byte and drives no visitor method. It is *only* on the error\n * channel — the three-valued outcome has no value for \"valid, but more than I am\n * configured to accept\", so there is nothing about it to read back as a status,\n * and nothing that has to be kept in step with the throw.\n */\n feed(chunk: Uint8Array): FeedStatus {\n this.state.push(chunk);\n return this.state.outcome();\n }\n}\n\n/**\n * Decode a complete message held in one contiguous buffer, in a single call.\n *\n * The non-streaming convenience, and **not** a second decoder: it is one\n * {@link IStream.feed} of the whole buffer, so it runs the same code, applies the\n * same rules and has the same memory behaviour as a chunked decode — §6.7.1\n * forbids the one-shot path from differing, right down to holding no view into\n * the buffer it was handed. Feeding a whole message is also the case the decoder's\n * fast lane is built for, so nothing is given up by having one implementation.\n *\n * The whole buffer *is* the end of input, so the two failure outcomes both throw a\n * {@link SofabError} the caller tells apart by `code` (MESSAGE_SPEC §7): malformed\n * input throws `INVALID_MSG`, while input that ends inside a field — truncation or\n * an unclosed sequence — throws `INCOMPLETE`. A complete message returns normally.\n *\n * The receiver caps of §6.2.1 are the `visitor`'s, not this function's: it takes\n * no limits argument because this codec holds none. See {@link IStream}.\n */\nexport function decode(bytes: Uint8Array, visitor: Visitor): void {\n // One machine, re-bound per call. Constructing a decoder is the only allocating\n // step there is (§6.6) — and on a small message it is most of the cost — so the\n // one-shot path keeps one and rebinds it. A decode started *inside* a visitor\n // callback finds the pool empty and builds its own, so nesting stays safe, and\n // the machine goes back to the pool even when the decode throws.\n const state = pooled ?? new DecoderState();\n pooled = null;\n try {\n state.begin(visitor);\n state.push(bytes);\n // A malformed message has already thrown `INVALID_MSG`; what is left to report\n // is truncation, which streaming leaves to the caller's framing (§5.2.4) and\n // which a one-shot caller has, by construction, already decided is an error —\n // the whole buffer *is* the end of input.\n if (state.outcome() !== DecodeStatus.Complete) {\n throw incompleteError(\"truncated message: input ends inside a field\");\n }\n } finally {\n state.release(); // keep nothing of the caller's alive in the pool\n pooled = state;\n }\n}\n\n/** The machine {@link decode} reuses; `null` while a decode is running on it. */\nlet pooled: DecoderState | null = null;\n","/**\n * Decode-side text helper — the read-path twin of {@link \"../encode/fixlen\"}.\n *\n * Two things make a short string expensive to decode, and this avoids both.\n *\n * `TextDecoder.decode` needs a `Uint8Array` covering exactly the payload, so the\n * decoder has to build a `subarray` per string; on Node 24 that view alone costs\n * about a third of the whole read (~500 Ir/op for a 13-byte field). And the\n * decode itself is a WHATWG entry point whose per-call setup dwarfs the payload\n * at these sizes.\n *\n * The obvious fix — walk the bytes in JS and append with `+=`, the way\n * protobufjs does — trades one problem for another: the repeated concatenation\n * builds a **rope**, and the rope is flattened later, by the first consumer that\n * walks it. In a decode-then-encode round trip that consumer is the encoder's own\n * `utf8Length` / `utf8Write` pass, so the cost does not disappear, it moves out\n * of the decode where it is easy to miss. Measured on a 13-byte ASCII field\n * (decode plus one charCodeAt walk): TextDecoder 2006 Ir/op, rope 2095 — the\n * rope form looks 40 percent cheaper if only the decode is measured, and is\n * *worse* once the string is used.\n *\n * So an all-ASCII payload short enough to name its length is built with a\n * SINGLE `String.fromCharCode` call, which returns a flat string with no rope to\n * pay for afterwards: 858 Ir/op on the same measurement, less than half of\n * either alternative. Everything else — non-ASCII, or longer than\n * {@link FLAT_MAX} — goes to the fatal {@link TextDecoder} exactly as before.\n *\n * This stays **strict** (MESSAGE_SPEC section 8): the fast path is gated on every\n * byte being below 0x80, and each such byte is a well-formed single-byte UTF-8\n * sequence, so an all-ASCII run has nothing to reject. Any payload with a high\n * bit set is handed to the platform decoder whole and gets exactly the\n * validation it always got — the fast path can never accept bytes the platform\n * would refuse.\n *\n * {@link decodeUtf8} is **public** because the code that needs it is not in this\n * library. The decoder reports raw, unvalidated payload pieces (§6.4.5 puts the\n * UTF-8 check where a string is *materialized*, and a piece may end mid-code-point),\n * so materialization — and therefore the check — belongs to whoever wants the\n * value. Generated code is that whoever, and without an exported entry point every\n * generated package builds a plain fatal `TextDecoder` of its own and pays the full\n * 2006 Ir/op per short string instead of 858.\n *\n * It is **static helper layer**, not codec (§6.6.1): it allocates the string it\n * returns, and no codec path calls it.\n */\n\nimport { invalidMsgError } from \"../errors.js\";\n\nconst _utf8 = new TextDecoder(\"utf-8\", { fatal: true });\n\n/**\n * Longest payload the flat fast path covers. Past this the per-call argument\n * list stops paying for itself against the platform decoder's vectorised scan,\n * and a chunked build would reintroduce the rope the fast path exists to avoid.\n */\nconst FLAT_MAX = 16;\n\n/**\n * Decode `buf[start..end)` as strict UTF-8 — the whole of `buf` when the range\n * is omitted, which is the shape a reassembled payload (see {@link PayloadAcc})\n * arrives in.\n *\n * Malformed bytes throw a {@link SofabError} (`INVALID_MSG`), never the fatal\n * {@link TextDecoder}'s bare `TypeError`. The mapping belongs here rather than at\n * each call site: invalid UTF-8 is an invalid *message* (MESSAGE_SPEC §8,\n * CORELIB_PLAN §6.4), so it has to reach a caller as the same `INVALID` verdict\n * as every other malformation — through the one `catch (e) { if (e instanceof\n * SofabError) … }` a consumer writes — and a platform exception escaping that\n * clause is precisely the bug this closes.\n *\n * A zero-length payload is the empty string, decoded without touching the\n * platform decoder.\n */\nexport function decodeUtf8(buf: Uint8Array, start = 0, end = buf.length): string {\n const n = end - start;\n if (n <= 0) return \"\";\n if (n <= FLAT_MAX) {\n // ASCII gate: one pass, no allocation, and it settles validity for the whole\n // payload before a single character is built.\n let ascii = true;\n for (let k = start; k < end; k++) {\n if (buf[k]! & 0x80) {\n ascii = false;\n break;\n }\n }\n if (ascii) {\n switch (n) {\n case 1: return String.fromCharCode(buf[start]!);\n case 2: return String.fromCharCode(buf[start]!, buf[start + 1]!);\n case 3: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!);\n case 4: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!);\n case 5: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!);\n case 6: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!);\n case 7: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!);\n case 8: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!);\n case 9: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!);\n case 10: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!);\n case 11: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!);\n case 12: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!, buf[start + 11]!);\n case 13: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!, buf[start + 11]!, buf[start + 12]!);\n case 14: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!, buf[start + 11]!, buf[start + 12]!, buf[start + 13]!);\n case 15: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!, buf[start + 11]!, buf[start + 12]!, buf[start + 13]!, buf[start + 14]!);\n case 16: return String.fromCharCode(buf[start]!, buf[start + 1]!, buf[start + 2]!, buf[start + 3]!, buf[start + 4]!, buf[start + 5]!, buf[start + 6]!, buf[start + 7]!, buf[start + 8]!, buf[start + 9]!, buf[start + 10]!, buf[start + 11]!, buf[start + 12]!, buf[start + 13]!, buf[start + 14]!, buf[start + 15]!);\n }\n }\n }\n try {\n return _utf8.decode(buf.subarray(start, end));\n } catch {\n throw invalidMsgError(\"invalid UTF-8 in string\");\n }\n}\n","/**\n * Generated-layer support: reassembling a `string` / `blob` payload that the\n * decoder reported in pieces.\n *\n * This is the **static helper layer** of CORELIB_PLAN §6.6.1, not part of the\n * codec: it allocates, on the generated layer's behalf, and the codec never calls\n * into it — the call graph runs generated code → helper → codec, never the other\n * way round. §6.6 binds the codec; this side of the boundary is where a value gets\n * built.\n *\n * {@link IStream} reports a payload to {@link Visitor.string} /\n * {@link Visitor.blob} as one or more pieces, each a range of the caller's own fed\n * chunk tagged with the field's `total` byte length and the `offset` of the piece\n * within it. That memory is borrowed only for the duration of the call (§6.0), so\n * a consumer that wants the *value* has to copy out — and generated code always\n * wants the value: a schema field is a `string`, not a sequence of pieces.\n *\n * That join has the same shape for every schema — it is decided entirely by\n * `total` and `offset`, both runtime values — so it lives here rather than in\n * every generated package (ARCHITECTURE §8). It is also the piece that is easiest\n * to get subtly wrong and hardest to catch: two implementations can disagree about\n * where a payload was split and still produce byte-identical output on every\n * shared vector, because the split is a property of how the caller fed the bytes,\n * not of the bytes. {@link PayloadAcc} is pinned instead by a unit test that\n * splits one payload at *every* offset and requires one answer.\n */\n\n/**\n * Joins a `string` / `blob` payload that arrived across several fed pieces.\n *\n * **One per decoder, shared by every field.** Exactly one payload is in flight at\n * a time across a whole decode, however deep the nesting — a fixlen payload is\n * atomic on the wire, so nothing can begin inside it — so one accumulator is\n * enough.\n *\n * **What it returns is owned by the caller** and aliases nothing: the bytes are\n * copied into storage this accumulator allocated, on the whole-payload path\n * exactly as on the split one (§6.7 — \"there is no mode in which the destination\n * aliases the input\"). A consumer may keep the result, and a payload that arrived\n * whole is not a special case with a different lifetime.\n *\n * Sizing follows the declared `total`, so a hostile length word is bounded by\n * whatever bound the caller already applied to it — the schema `maxlen` its\n * generated guard checks, or the receiver caps of §6.2.1, both of which\n * are enforced at the length word before a piece is ever delivered. This class\n * enforces neither: it is handed a payload the caller has already accepted.\n */\nexport class PayloadAcc {\n private buf: Uint8Array | null = null;\n private len = 0;\n\n /**\n * Contribute one piece — the bytes `src[start..end)` at `offset` of a\n * `total`-byte payload — and return the **whole** payload once it is complete,\n * or `null` while bytes are still outstanding.\n *\n * `offset === 0` starts a payload — and *resets* the accumulator, so a decode\n * that was abandoned mid-payload (an `INVALID` field, a declined subtree) leaves\n * nothing behind to corrupt the next one.\n *\n * A late piece with no payload in progress returns `null` rather than writing\n * anywhere: the accumulator has no buffer to append to, and inventing one would\n * fabricate a payload out of a fragment.\n */\n take(\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n ): Uint8Array | null {\n if (offset === 0) {\n this.buf = new Uint8Array(total);\n this.len = 0;\n }\n const b = this.buf;\n if (b === null) return null;\n // Clamped to the room that is left. Unreachable from this library's decoder —\n // a piece never runs past the payload it belongs to — and cheap: an over-long\n // piece would otherwise leave the corelib as a platform `RangeError` from\n // `set`, which is not one of the outcomes a caller's\n // `catch (e) { if (e instanceof SofabError) … }` handles.\n let n = end - start;\n const room = total - this.len;\n if (n > room) n = room;\n if (n > 0) {\n b.set(src.subarray(start, start + n), this.len);\n this.len += n;\n }\n if (this.len < total) return null;\n this.buf = null;\n return b;\n }\n}\n","/**\n * Generated-layer support: the element collectors for a **wrapper-sequence array**\n * (MESSAGE_SPEC §5.1) — {@link ElementSeq} and {@link FramedSeq} for the index\n * rules of any element kind, {@link StringSeq} / {@link BlobSeq} for the two leaf\n * kinds whose payload arrives here as well.\n *\n * Static helper layer, not codec (CORELIB_PLAN §6.6.1): these allocate — that is\n * their job — and no codec path reaches them. Generated code drives them from\n * inside its own flat {@link Visitor}, which is what knows, from the schema, that\n * the scope it is currently in *is* the wrapper array.\n *\n * A wrapper array is an ordinary sequence whose child fields *are* the elements,\n * and whose field id *is* the array index. So a collector is fed the two events a\n * `string` / `blob` element produces — {@link StringSeq.begin} at the length word\n * and {@link StringSeq.element} per payload piece — and places each value at\n * `out[id]`.\n *\n * Every part of that is schema-independent. Both bounds on the index (the schema\n * `count`, the receiver cap) and both on the element's byte length (the element\n * `maxlen`, the receiver cap) arrive as constructor arguments — runtime values —\n * and the field name is carried along only so a rejection can say which field it\n * was about. So the collectors belong here rather than being re-emitted, textually\n * identical, into every generated package (ARCHITECTURE §8).\n *\n * Four rules are implemented here and are worth stating once, since nothing in the\n * shared vectors can distinguish an implementation that gets them wrong from one\n * that does not — they are properties of the *decoded value*, not of the bytes\n * (which is exactly why CORELIB_PLAN §7.2 item 8 asks for them separately):\n *\n * - **Gaps are legal.** An interior element equal to its default is not written at\n * all, so ids `0, 2, 3` are well-formed. The missing index is filled with the\n * element default, never skipped over: everything after a gap keeps its index.\n * - **Length is highest present id + 1.** The wrapper carries no length, and the\n * last element is never elided, so growing to `id + 1` on each element is\n * exactly right and no trailing fill is ever needed.\n * - **A repeated element id replaces.** Last occurrence wins per id (§7.4);\n * placing at `out[id]` does that by construction, with no bookkeeping.\n * - **A rejected id extends nothing.** Every bound is checked before the\n * destination grows, so a rejection leaves the array exactly as it was and a\n * lower id delivered afterwards still lands correctly.\n *\n * **Two bounds, never both** (§6.2.1). Index and element length each carry a\n * schema bound and a receiver cap, and exactly one of the pair applies: where the\n * schema declared a bound its violation is `INVALID` — a statement about validity\n * — and where it declared none the receiver's cap governs and its violation is\n * `LIMIT_EXCEEDED`, a policy rejection on well-formed bytes. \"They **MUST NOT** be\n * applied to a field the schema already bounds\", so the caps are exclusive with\n * the bounds and never additive.\n *\n * **Every bound is a required argument, and none of them has a default** (§6.2.1).\n * The comparison runs here; the *number* never originates here. A corelib \"**MUST\n * NOT** hold a limit of its own, **MUST NOT** supply a default for one it was not\n * given, **MUST NOT** read an omitted argument as *unlimited*, and **MUST NOT**\n * clamp to one\", and a format ceiling (§6.2) reached because no cap was stated \"is\n * the **format's** bound, not a receiver cap, and a port **MUST NOT** present it as\n * one\". These constructors used to default `receiverCap` to `ARRAY_MAX` and\n * `receiverElemMax` to `FIXLEN_MAX`, which did exactly that: they reported\n * `LIMIT_EXCEEDED` against a ceiling nobody configured. The defaults are gone and\n * the arguments are required — §6.2.1's \"strictest form, and the recommended one\".\n * The *schema* bounds beside them (`cap`, `elemMax`) are required too, with\n * {@link UNBOUNDED} as the explicit \"the schema declared none\" spelling: an absent\n * schema bound is a fact about the schema, which only the caller knows.\n *\n * **And an argument that states no cap is a caller mistake, not a policy\n * rejection.** A required argument can still arrive as `-1`, `undefined` or\n * `Infinity` from an untyped caller, and the same reasoning applies one level in:\n * no receiver policy was set, so there is no `LIMIT_EXCEEDED` to report and no\n * unlimited mode to fall back to. Such a bound is refused at construction with\n * `Argument` (§6.3's third row: \"every remaining caller mistake is\n * `InvalidArgument`\") — see {@link requireReceiverBound}.\n */\n\nimport { FixlenSubtype } from \"../constants.js\";\nimport { argumentError, invalidMsgError, limitExceededError } from \"../errors.js\";\nimport type { PayloadAcc } from \"./acc.js\";\nimport { decodeUtf8 } from \"./text.js\";\n\n/** Shared placeholder for a gap in a {@link BlobSeq}; zero-length, so sharing one is safe. */\nconst NO_BYTES = new Uint8Array(0);\n\n/**\n * No *schema* bound — what `cap` / `elemMax` take for an array or element the\n * schema left open (§7.2), so the receiver cap beside them governs instead.\n *\n * Exported because the schema bounds are required arguments with no default: an\n * absent one is a fact about the **schema**, which only generated code knows, and\n * §6.2.1's ban on a codec defaulting a bound is easiest to keep honest when every\n * bound has to be spelled. This is the spelling for \"there is none\".\n */\nexport const UNBOUNDED = -1;\n\n/**\n * Reject a receiver bound that is not a bound, **before** it is ever compared\n * against (CORELIB_PLAN §6.2.1, §6.3).\n *\n * §6.2.1 lets this library perform the comparison but never own the number: a\n * codec \"**MUST NOT** hold a limit of its own, **MUST NOT** supply a default for\n * one it was not given, **MUST NOT** read an omitted argument as *unlimited*, and\n * **MUST NOT** clamp to one\". A caller that hands over `-1`, `undefined`/`NaN` or\n * `Infinity` for a bound that is about to **govern** has stated no cap at all, and\n * there are only two things this class could do about it — and both were wrong:\n *\n * - it used to **fail closed with `LIMIT_EXCEEDED`** for a negative bound, naming\n * a receiver policy the deployment never set. `LimitExceeded` means \"raise my\n * limit or the sender must send less\" (§6.3); there is no limit to raise;\n * - and it **failed open** for `undefined`/`NaN` — every comparison against `NaN`\n * is `false`, so `id >= receiverCap` never fired and the array decoded\n * uncapped. That is §6.2.1's \"read an omitted argument as *unlimited*\",\n * verbatim.\n *\n * Neither is a property of the message or of the deployment: it is a mistake in\n * the **call**, which §6.3's third row makes `InvalidArgument` — \"every remaining\n * caller mistake is `InvalidArgument`\". Reported at construction, so it is still\n * fail-closed (no element is ever accepted) and the per-element comparison below\n * stays a single `>=` on a number already known to be finite and non-negative.\n *\n * Checked only where the receiver bound actually applies. §6.2.1: the caps \"**MUST\n * NOT** be applied to a field the schema already bounds\" — where `schemaBound` is\n * stated it governs alone, the receiver bound beside it is inert, and a number\n * that is forbidden to be applied cannot be required to be stated.\n */\nfunction requireReceiverBound(\n schemaBound: number,\n receiver: number,\n what: string,\n name: string,\n): void {\n if (schemaBound >= 0) return; // the schema bound governs; the cap never runs\n if (Number.isFinite(receiver) && receiver >= 0) return;\n throw argumentError(\n `${name}: ${what} is ${receiver}, which states no cap — the schema left this ` +\n `field unbounded, and §6.2.1 admits no unset state and no unlimited mode. ` +\n `The number is generated code's to supply.`,\n );\n}\n\n/**\n * **The** element-index rule, in one place — split into the number it compares\n * against and the verdict a breach of it gets.\n *\n * Never both (CORELIB_PLAN §6.2.1): where the schema declared a `count` its\n * violation is `INVALID`, a statement about the message, and the receiver cap\n * beside it is inert; where it declared none the cap governs alone and its\n * violation is `LIMIT_EXCEEDED`, a policy rejection of well-formed bytes.\n *\n * \"Never both\" means exactly one of the pair is ever compared against, so there\n * is exactly one number in force and it is known at construction. This picks it\n * once per collector and every check below is then the single `id >= this.bound`\n * that remains — the whole §6.2.1 choice, made once rather than re-made per\n * element. That matters beyond tidiness: the `ts` bench rows measure the V8\n * **baseline** tier, where nothing is inlined and a call is the expensive thing,\n * so a per-element call into a shared checker is a cost the shared checker does\n * not have to pay in order to stay shared.\n *\n * @param cap The schema `count` as an index capacity, or {@link UNBOUNDED} (`-1`).\n * @param receiverCap The receiver index cap, in force only when `cap` is\n * {@link UNBOUNDED}; already known to be finite and non-negative, because\n * {@link requireReceiverBound} refused anything else at construction — so the\n * bound this returns is always a finite non-negative number and the comparison\n * against it is exact, with no NaN to fall through.\n */\nfunction indexBound(cap: number, receiverCap: number): number {\n return cap >= 0 ? cap : receiverCap;\n}\n\n/**\n * Which verdict an index that has already failed `indexBound` gets: the\n * schema `count` is validity, the receiver cap is policy (CORELIB_PLAN §6.2.1).\n *\n * Written once and shared by every collector in this file, because §6.2.1 is a\n * rule about *which* verdict a caller gets and a second copy is a second chance\n * to get it wrong. It always throws — the caller has already established that the\n * bound is breached — and it never touches a container, which is what lets a\n * caller run its check before allocating anything (§7.2 item 8).\n *\n * @param id The element index, which for a wrapper array is the child field's id.\n * @param cap The schema `count` as an index capacity, or {@link UNBOUNDED} (`-1`).\n * `cap >= 0` is what makes the breach `INVALID` rather than `LIMIT_EXCEEDED`.\n * @param receiverCap The receiver index cap, named in the rejection message when\n * it is the bound that was breached.\n * @param name The schema field name, used only in the rejection message.\n */\nfunction rejectIndex(id: number, cap: number, receiverCap: number, name: string): never {\n if (cap >= 0) {\n throw invalidMsgError(`${name}: array index above schema capacity ${cap}`);\n }\n throw limitExceededError(`${name}: array index ${id} exceeds the receiver cap ${receiverCap}`);\n}\n\n/**\n * The slots of a wrapper-sequence array: the index rules of MESSAGE_SPEC §5.1 and\n * the two bounds of CORELIB_PLAN §6.2.1, once, for any element type.\n *\n * {@link StringSeq} and {@link BlobSeq} place leaf elements through it, and\n * generated code places a **framed** element — a `struct` / `union` / nested row —\n * through it directly: {@link reserve} at the element's `sequenceBegin`, then build\n * the child into `out[id]`. The element kind changes which path arrives here and\n * nothing else, which is the point — the bound is the index (§7.2 item 8).\n *\n * @param out The destination array; grown to `id + 1` as elements arrive.\n * @param def The element default, written into a gap and into a reserved slot.\n * @param cap The schema `count` as an index capacity: `id >= cap` is `INVALID`\n * (§7.1) — a statement about validity. Pass {@link UNBOUNDED} (`-1`) for an array\n * the schema left open, where `receiverCap` governs instead.\n * @param name The schema field name, used only in a rejection message.\n * @param receiverCap The receiver-side index cap for a schema-unbounded array\n * (§6.2.1): `id >= receiverCap` is `LIMIT_EXCEEDED`, a policy rejection. There is\n * no unlimited setting — a wrapper array announces no count, so the index is the\n * only place a receiver can bound it. **Required, with no default**: the number is\n * generated code's, and falling back to `ARRAY_MAX` would report a policy\n * rejection against a format ceiling nobody configured (§6.2.1). A value that\n * states no cap at all — negative, `NaN`, `Infinity` — is `Argument` at\n * construction, never `LIMIT_EXCEEDED` ({@link requireReceiverBound}).\n */\nexport class ElementSeq<T> {\n /**\n * The one index bound in force, picked once by `indexBound`: the schema\n * `count` where the schema stated one, the receiver cap where it did not. Which\n * of the two it is decides the verdict, which is `rejectIndex`'s job.\n */\n private readonly bound: number;\n\n constructor(\n readonly out: T[],\n readonly def: T,\n readonly cap: number,\n readonly name: string,\n readonly receiverCap: number,\n ) {\n // §6.2.1: where the schema stated a bound, the receiver cap beside it is inert\n // — so an unbounded array is the only one that HAS a receiver cap to validate.\n if (cap < 0) requireReceiverBound(cap, receiverCap, \"the receiver array-index cap\", name);\n this.bound = indexBound(cap, receiverCap);\n }\n\n /**\n * Bound-check `id` and grow `out` to `id + 1`, filling any gap — and the slot\n * itself — with the element default.\n *\n * The check runs **before** the growth, which is the whole of §7.2 item 8's\n * \"after a rejected id the container is not left partially extended\": a\n * rejection leaves `out` exactly as it was, so a lower id delivered afterwards\n * still lands at its own index.\n */\n reserve(id: number): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n // Grow to at least id + 1 (ARCHITECTURE §9.5 shape B): `push` leaves the\n // geometry to the engine's own amortised doubling, so a sparse array does not\n // cost O(n²) copies.\n while (this.out.length <= id) this.out.push(this.def);\n }\n\n /**\n * The two index bounds, without growing: the schema `count` as validity\n * (`INVALID`) or, where the schema left the array open, the receiver cap as\n * capacity (`LIMIT_EXCEEDED`). Never both — §6.2.1 keeps a cap off a field the\n * schema already bounds, which is why one `bound` can stand for both.\n *\n * Split out from {@link reserve} because a leaf element is bound-checked at its\n * length word, before its payload has arrived and so before there is anything to\n * place ({@link StringSeq.begin}).\n */\n checkIndex(id: number): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n }\n\n /**\n * What {@link reserve} does, then `value` written into the slot. A repeat\n * replaces (§7.4).\n *\n * Written out rather than delegating to {@link reserve}: on the baseline tier a\n * call is not free, and this is the per-element path. The check still precedes\n * the growth, which is the property §7.2 item 8 asks for.\n */\n place(id: number, value: T): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n while (this.out.length <= id) this.out.push(this.def);\n this.out[id] = value;\n }\n}\n\n/**\n * The slots of a wrapper-sequence array whose element default is a **fresh\n * object**: a framed element (`struct` / `union`) or a nested row.\n *\n * {@link ElementSeq}'s twin, and it differs in exactly one thing — the gap value\n * comes from a **factory** instead of being shared. That single axis is why it is\n * a second class rather than a second argument: a framed element's default is\n * `new Elem()` and a row's is `[]`, both mutable and both reachable by the\n * caller, so one shared instance would alias every gap of the array onto it and —\n * since an arriving element decodes into the slot the reservation placed — would\n * alias every *element* onto it too, which is not a near miss but a flatly wrong\n * decode. {@link ElementSeq}'s `\"\"` and zero-length `Uint8Array` have no state to\n * share, which is what makes sharing right there and wrong here.\n *\n * Everything else is {@link ElementSeq}, deliberately: the same argument order\n * with `make` in `def`'s slot, the same two exclusive index bounds through the\n * same `indexBound` / `rejectIndex` pair, the same growth geometry, the same\n * construction-time refusal of a receiver cap that states no cap.\n *\n * Generated code calls {@link reserve} at the element's own `sequenceBegin` and\n * then keeps routing the child's fields into `out[id]` itself. This class owns\n * the bound and the growth; it never owns the routing, which is the part that has\n * a different shape for every schema (ARCHITECTURE §8).\n *\n * @param out The destination array; grown to `id + 1` as elements arrive.\n * @param make Builds one element default. Called once per gap slot, and once for\n * the reserved slot itself in {@link reserve} — never for a slot already present,\n * so a re-opened element keeps the object earlier fields decoded into.\n * @param cap The schema `count` as an index capacity: `id >= cap` is `INVALID`\n * (§7.1) — a statement about validity. Pass {@link UNBOUNDED} (`-1`) for an array\n * the schema left open, where `receiverCap` governs instead.\n * @param name The schema field name, used only in a rejection message.\n * @param receiverCap The receiver-side index cap for a schema-unbounded array\n * (§6.2.1): `id >= receiverCap` is `LIMIT_EXCEEDED`, a policy rejection, never\n * `INVALID`, and never applied beside a `cap` the schema stated. **Required, with\n * no default**; a value that states no cap at all is `Argument` at construction\n * ({@link requireReceiverBound}).\n */\nexport class FramedSeq<T> {\n /** The one index bound in force, picked once by `indexBound` — see {@link ElementSeq}. */\n private readonly bound: number;\n\n constructor(\n readonly out: T[],\n readonly make: () => T,\n readonly cap: number,\n readonly name: string,\n readonly receiverCap: number,\n ) {\n if (cap < 0) requireReceiverBound(cap, receiverCap, \"the receiver array-index cap\", name);\n this.bound = indexBound(cap, receiverCap);\n }\n\n /**\n * The two index bounds, without growing — see {@link ElementSeq.checkIndex}.\n *\n * Split out for the same reason it is there: a caller may have a second bound\n * to take before anything is allocated. A native matrix row is that case in this\n * port — its element `count` is rejected at the array header, and §7.2 item 8\n * wants that rejection to leave the row container exactly as it was.\n */\n checkIndex(id: number): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n }\n\n /**\n * Bound-check `id`, **then** grow `out` to `id + 1`, each new slot its own\n * `make()`.\n *\n * The order is §7.2 item 8's \"after a rejected id the container is not left\n * partially extended\": a rejection leaves `out` exactly as it was, so a lower id\n * delivered afterwards still lands at its own index. A slot already present is\n * left alone — a re-opened `struct` / `union` element merges into the object it\n * already built, which is what §7.4's last-occurrence-wins means for a scope\n * whose value *is* the scope.\n */\n reserve(id: number): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n // Grow to at least id + 1 (ARCHITECTURE §9.5 shape B): `push` leaves the\n // geometry to the engine's own amortised doubling, so a sparse array does not\n // cost O(n²) copies.\n while (this.out.length <= id) this.out.push(this.make());\n }\n\n /**\n * Bound-check `id`, fill the gap below it, then write `value` into the slot —\n * what a nested **row** needs, an array wrapper *replacing* whatever an earlier\n * opening built at that index (§7.4) rather than merging into it.\n *\n * The gap fill stops one short of `id` on purpose: the slot is about to be\n * overwritten, so calling `make()` for it would allocate an element default\n * nobody ever reads. Assigning at `out.length` extends the array by exactly one,\n * which is the same array a {@link reserve} would have left.\n */\n place(id: number, value: T): void {\n if (id >= this.bound) rejectIndex(id, this.cap, this.receiverCap, this.name);\n while (this.out.length < id) this.out.push(this.make());\n this.out[id] = value;\n }\n}\n\n/**\n * Collects the elements of a `string` wrapper-sequence array into `out`.\n *\n * @param out The destination, placed at `out[id]`; grown as elements arrive, with\n * gaps filled by the element default `\"\"`.\n * @param acc The decoder's shared {@link PayloadAcc} — one per decode, since only\n * one payload is ever in flight.\n * @param cap The schema `count`, an index **capacity**: an element id at or above\n * it is `INVALID` (§7.1/§5.1) — a statement about validity. Pass\n * {@link UNBOUNDED} (`-1`) for an array the schema left unbounded, where\n * `receiverCap` governs instead.\n * @param elemMax The element `maxlen` in bytes, or {@link UNBOUNDED} (`-1`) for an\n * element the schema left open, where `receiverElemMax` governs instead.\n * @param name The schema field name, used only in the rejection message.\n * @param receiverCap The receiver-side index cap that applies **only** when the\n * schema left the array unbounded (§6.2.1): exceeding it is `LIMIT_EXCEEDED`, a\n * policy rejection, not `INVALID`. There is no unlimited setting — a wrapper array\n * announces no count, so the index is the only place a receiver can bound it.\n * **Required, with no default** (§6.2.1).\n * @param receiverElemMax The receiver-side `max_dyn_string_len` for an element the\n * schema left unbounded (§6.2.1), checked at the length word and answered with\n * `LIMIT_EXCEEDED`. A wrapper array's `string` elements never reach the generated\n * visitor — their length words come here — so this is where that cap belongs, and\n * it is why the decoder needs no module-wide limit object at all. **Required, with\n * no default**: `FIXLEN_MAX` is the format's bound, not a receiver cap, and §6.2.1\n * forbids presenting it as one.\n */\nexport class StringSeq {\n /** The index rules and both index bounds, shared with every other element kind. */\n private readonly slots: ElementSeq<string>;\n\n constructor(\n readonly out: string[],\n readonly acc: PayloadAcc,\n readonly cap: number,\n readonly elemMax: number,\n readonly name: string,\n readonly receiverCap: number,\n readonly receiverElemMax: number,\n ) {\n // The index bound is validated by `ElementSeq`; this is the length bound's half.\n requireReceiverBound(elemMax, receiverElemMax, \"the receiver element-length cap\", name);\n this.slots = new ElementSeq(out, \"\", cap, name, receiverCap);\n }\n\n /**\n * The element's fixlen length word ({@link Visitor.fixlenBegin}).\n *\n * The bounds are decided by this word, so they are checked here — before any\n * payload byte — and again in {@link element} below.\n *\n * That is not redundancy for its own sake: a message that ends *inside* an\n * over-long element must still be `INVALID`, and only this event runs early\n * enough to say so. Without it the verdict would degrade to `INCOMPLETE`, which\n * §5.2.3 forbids for input already known to be malformed and which §6.4 forbids\n * a chunk boundary from changing.\n *\n * An element of the wrong fixlen subtype is left alone: §7.3 requires it to be\n * *skipped*, not rejected, and it is skipped by this class simply ignoring it.\n */\n begin(id: number, subtype: FixlenSubtype, total: number): void {\n if (subtype !== FixlenSubtype.String) return;\n this.check(id, total);\n }\n\n /** One payload piece of element `id` ({@link Visitor.string}). */\n element(\n id: number,\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n ): void {\n this.check(id, total);\n // A payload that arrived whole is decoded straight out of the caller's chunk:\n // `decodeUtf8` produces a new string, so nothing aliases the input and the\n // accumulator's copy is not needed at all.\n const text =\n offset === 0 && end - start === total\n ? decodeUtf8(src, start, end)\n : decodeStringPiece(this.acc, total, offset, src, start, end);\n if (text === null) return;\n this.slots.place(id, text);\n }\n\n /** Every bound for one element. Rejects **before** the destination grows. */\n private check(id: number, total: number): void {\n this.slots.checkIndex(id);\n if (this.elemMax >= 0) {\n if (total > this.elemMax) {\n throw invalidMsgError(\n `${this.name} element: string byte length above schema maxlen ${this.elemMax}`,\n );\n }\n } else if (total > this.receiverElemMax) {\n throw limitExceededError(\n `${this.name} element: string byte length ${total} exceeds the receiver cap ` +\n `${this.receiverElemMax}`,\n );\n }\n }\n}\n\n/**\n * Collects the elements of a `blob` wrapper-sequence array into `out`. The\n * `string` twin above, with two differences: the payload is stored as bytes rather\n * than decoded, and gaps are filled with an empty {@link Uint8Array}.\n *\n * Each element is storage of its own — what {@link PayloadAcc} returns is a buffer\n * it allocated and handed over, never a view into the fed chunk (§6.7) — so a\n * stored element cannot rot when the caller reuses its input.\n *\n * @param out The destination, placed at `out[id]`.\n * @param acc The decoder's shared {@link PayloadAcc}.\n * @param cap The schema `count` as an index capacity, or {@link UNBOUNDED} (`-1`)\n * for unbounded.\n * @param elemMax The element `maxlen` in bytes, or {@link UNBOUNDED} (`-1`) for an\n * element the schema left open, where `receiverElemMax` governs instead.\n * @param name The schema field name, used only in the rejection message.\n * @param receiverCap The receiver-side index cap for a schema-unbounded array\n * (§6.2.1) — see {@link StringSeq}. Required, with no default.\n * @param receiverElemMax The receiver-side `max_dyn_blob_len` for a schema-unbounded\n * element (§6.2.1) — see {@link StringSeq}. Required, with no default.\n */\nexport class BlobSeq {\n /** The index rules and both index bounds, shared with every other element kind. */\n private readonly slots: ElementSeq<Uint8Array>;\n\n constructor(\n readonly out: Uint8Array[],\n readonly acc: PayloadAcc,\n readonly cap: number,\n readonly elemMax: number,\n readonly name: string,\n readonly receiverCap: number,\n readonly receiverElemMax: number,\n ) {\n // The index bound is validated by `ElementSeq`; this is the length bound's half.\n requireReceiverBound(elemMax, receiverElemMax, \"the receiver element-length cap\", name);\n this.slots = new ElementSeq(out, NO_BYTES, cap, name, receiverCap);\n }\n\n /** See {@link StringSeq.begin} — the early bound check, for subtype `blob`. */\n begin(id: number, subtype: FixlenSubtype, total: number): void {\n if (subtype !== FixlenSubtype.Blob) return;\n this.check(id, total);\n }\n\n /** One payload piece of element `id` ({@link Visitor.blob}). */\n element(\n id: number,\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n ): void {\n this.check(id, total);\n const payload = this.acc.take(total, offset, src, start, end);\n if (payload === null) return;\n this.slots.place(id, payload);\n }\n\n /** Every bound for one element. Rejects **before** the destination grows. */\n private check(id: number, total: number): void {\n this.slots.checkIndex(id);\n if (this.elemMax >= 0) {\n if (total > this.elemMax) {\n throw invalidMsgError(\n `${this.name} element: blob byte length above schema maxlen ${this.elemMax}`,\n );\n }\n } else if (total > this.receiverElemMax) {\n throw limitExceededError(\n `${this.name} element: blob byte length ${total} exceeds the receiver cap ` +\n `${this.receiverElemMax}`,\n );\n }\n }\n}\n\n/** A split payload, joined and decoded once its last piece arrives; `null` before that. */\nfunction decodeStringPiece(\n acc: PayloadAcc,\n total: number,\n offset: number,\n src: Uint8Array,\n start: number,\n end: number,\n): string | null {\n const payload = acc.take(total, offset, src, start, end);\n return payload === null ? null : decodeUtf8(payload);\n}\n","/**\n * Generated-layer support: the array half of the ≠-default test that decides\n * whether a field is written at all (MESSAGE_SPEC §2).\n *\n * SofaBuffers omits a field whose value equals its schema default, so every\n * generated `serialize` compares before it writes. For a scalar that is `!==`;\n * for an array it is element-wise, because two distinct `Uint8Array` /\n * `number[]` instances holding the same values are the same *value* and must\n * encode the same way — `a !== b` would emit the field whenever the destination\n * happened to be a fresh object, and the wire is supposed to be canonical.\n *\n * The comparison has no schema in it: the declared type only decides which\n * arrays are handed over. So it is written once here instead of being emitted\n * into every generated package (ARCHITECTURE §8).\n */\n\nimport type { Long } from \"../long.js\";\n\n/**\n * Element-wise equality for two array-likes: same length, and `===` at every\n * index. Covers what a leaf array field can hold — `Uint8Array` (blob), and\n * `number[]` / `bigint[]` / `boolean[]` / `string[]` — including a mixed pair\n * such as a `Uint8Array` value against a plain-array default from the schema.\n *\n * Deliberately **not** deep: a nested (wrapper) array of messages is compared by\n * the generated `isDefault()` of its element type, which is the only code that\n * knows what a default element is. Equally deliberately `===`, which makes `NaN`\n * unequal to itself — matching the scalar `!==` test, the IEEE-754 rule the rest\n * of the encoder follows, and the only reading under which an `fp32`/`fp64`\n * `NaN` element survives the round trip rather than being omitted as \"default\".\n * There is no identity short-circuit for the same reason: `elementsEqual(x, x)`\n * has to give the same answer as `elementsEqual(x, x.slice())`.\n */\nexport function elementsEqual(a: ArrayLike<unknown>, b: ArrayLike<unknown>): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n return true;\n}\n\n/**\n * The {@link Long} flavour of {@link elementsEqual}: same length, and the same\n * 64-bit value at every index.\n *\n * A separate function rather than an argument to the one above, because the\n * comparison itself is different. A `Long` is an *object identity* — two\n * instances holding the same 64 bits are `!==` — so `elementsEqual`'s `===` would\n * report every `Long`-backed array as unequal to its schema default and the\n * ≠-default test (MESSAGE_SPEC §2) would emit a field that should have been\n * omitted. Comparing the `(low, high)` halves is what \"same value\" means for this\n * representation, and it is the only 64-bit representation that needs it:\n * `bigint` and `number` elements are values already and go through\n * {@link elementsEqual}.\n *\n * Which arrays are handed over is the declared type's business, so there is no\n * schema in here either (ARCHITECTURE §8).\n */\nexport function longElementsEqual(a: ArrayLike<Long>, b: ArrayLike<Long>): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i]!.low !== b[i]!.low || a[i]!.high !== b[i]!.high) return false;\n }\n return true;\n}\n"]}
|