Drop the payload in progress, if there is one: what a decode that ended mid-payload left behind.
An accumulator that outlives one decode — a generated tryDecode keeps one
per destination (VisitorCache) — otherwise holds that partial
payload's buffer until some later decode starts a payload, and that buffer is
sized by a total the sender declared. Nothing READS it: a payload's first
piece always arrives at offset === 0, which resets whatever was there, and a
one-shot decode never continues a payload across calls. So this is liveness,
not correctness — the same thing DecoderState.release does for the
decoder's own references (CORELIB_PLAN §6.6/§6.7, "keep nothing of the
caller's alive").
Call it where the decode ends. Calling it mid-payload abandons that payload: the pieces already copied stay where they were written — in the caller's buffer under takeInto, in a buffer nobody else holds under take — and the continuation is dropped as a late piece.
Contribute one piece — the bytes src[start..end) at offset of a
total-byte payload — and return the whole payload once it is complete,
or null while bytes are still outstanding.
offset === 0 starts a payload — and resets the accumulator, so a decode
that was abandoned mid-payload (an INVALID field, a declined subtree) leaves
nothing behind to corrupt the next one.
A late piece with no payload in progress returns null rather than writing
anywhere: the accumulator has no buffer to append to, and inventing one would
fabricate a payload out of a fragment.
take, into a buffer you already hold: the same join, writing into
dst instead of into storage this accumulator allocates.
What it is for: a decode into a reused destination (ARCHITECTURE §8). A
generated message decoded a second time into the same object already holds a
Uint8Array for its blob field, and where the new payload is the same
length that buffer is the right place to put it — so the receive loop stops
allocating one payload-sized buffer per decode and per element. The choice is
the caller's and it is dst.length === total; this method is the copy.
The chunked path too, which is the half a caller cannot write for itself
without re-implementing the join: dst is adopted at offset === 0 and the
pieces land in it as they arrive, so a payload split across feed calls costs
no more than one that arrived whole. The pieces of one payload must all be
offered the same dst, and a continuation piece offered a buffer the payload
in progress did not start in is ignored — null, like any other late
fragment with nothing to append to. That is what keeps the copy below exact:
the buffer being filled is always this dst, so the room left in it is
total - len and a piece can never run past its end as a platform
RangeError.
A destination of the wrong size is a caller mistake, not a verdict about
the message: Argument (CORELIB_PLAN §6.3's third row, §6.6.3 — "a
destination too short for the value is InvalidArgument"), refused before a
byte is copied. It is !== rather than < because the payload's length is
part of the value: a longer buffer returned whole would overstate the payload,
and returning a subarray of it would alias storage the caller still owns.
Everything else is take: null until the last piece lands, offset === 0 resets whatever an abandoned payload left behind, and a late piece with
no payload in progress returns null without writing anywhere.
It allocates nothing, which does not make it a codec primitive: it is still the static helper layer (§6.6.1), reached from generated code only.
Joins a
string/blobpayload that arrived across several fed pieces.One per decoder, shared by every field. Exactly one payload is in flight at a time across a whole decode, however deep the nesting — a fixlen payload is atomic on the wire, so nothing can begin inside it — so one accumulator is enough.
What it returns is owned by the caller and aliases nothing: the bytes are copied into storage this accumulator allocated — or, with PayloadAcc.takeInto, into storage the caller handed over and already owns — on the whole-payload path exactly as on the split one (§6.7 — "there is no mode in which the destination aliases the input"). A consumer may keep the result, and a payload that arrived whole is not a special case with a different lifetime.
The join is written out twice, once in each entry point, rather than shared through a private method both call. Measured on a 16-element
blobwrapper array decoded with a fresh collector (Callgrind rep-subtraction, 2000 → 22000 reps): sharing it cost +1.8 % on the V8 baseline tier — 179,070 against 175,929 Ir/op — and nothing at all on the optimizing tier, which inlines the call. The baseline tier is the one thetsbench rows measure, and this is the path every caller that never asked for reuse already takes. The two bodies are a dozen lines and differ in one of them, and the every-offset split test pins both to the same answer, which is the guard that makes the duplication safe.Sizing follows the declared
total, so a hostile length word is bounded by whatever bound the caller already applied to it — the schemamaxlenits generated guard checks, or the receiver caps of §6.2.1, both of which are enforced at the length word before a piece is ever delivered. This class enforces neither: it is handed a payload the caller has already accepted.