SofaBuffers TypeScript - v0.12.0
    Preparing search index...

    Function tryDecode

    • decode, reporting truncation as a value instead of a throw: the outcome of one IStream.feed of the whole buffer, on decode's pooled machine.

      It is for a generated tryDecode (CORELIB_PLAN §6.1.1's fallible twin of decode), which a receive loop calls once per message. IStream returns the same outcome, but constructing one builds a decoder, which is the allocation decode pools away; and catching decode's INCOMPLETE to turn it back into a status would build an Error — a stack capture — per truncated message, in a block that is the same for every schema and so belongs here rather than in generated code.

      The channels are IStream.feed's, unchanged — one fact, one channel: Complete and Incomplete are returned, and every refusal is thrown as a SofabError whose code names it — INVALID_MSG for malformed input, LIMIT_EXCEEDED from a visitor enforcing a receiver cap, ARGUMENT for a caller mistake. The return type is FeedStatus for that reason: a caller switching on it has no Invalid arm to write.

      An Incomplete is an abandoned decode, not a decode that did nothing. Every field the bytes did reach has already been reported, and a visitor decoding into a reused destination (BlobSeq.reuse, PayloadAcc.takeReusing) has already written into it: the element a truncated payload was landing in is left holding the new payload's leading bytes over the old one's tail — not the value that was there, and not a value that was ever on the wire. decode delivered that case as a throw, which is hard to mistake for "nothing happened"; a returned status is easy to, so it is said here. A caller that falls back to its last good message on an Incomplete must treat the destination exactly as it treats one after a refusal — the element a truncated decode had already started is not recoverable from the destination, which is BlobSeq.reuse's own terms and the allocation that mode exists to remove.

      Parameters

      • bytes: Uint8Array
      • visitor: Visitor

      Returns FeedStatus