SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
Loading...
Searching...
No Matches
sofab::IStreamImpl Class Reference

Base of the input streams: decodes fields from fed bytes. More...

#include <sofab.hpp>

Inheritance diagram for sofab::IStreamImpl:
[legend]

Classes

struct  FieldCb
 Decode fields at the current nesting level, firing cb for each. More...
 
class  Result
 Three-valued outcome of a feed call (spec §7). More...
 

Public Member Functions

 IStreamImpl (const IStreamImpl &)=delete
 
IStreamImpl & operator= (const IStreamImpl &)=delete
 
 IStreamImpl (IStreamImpl &&) noexcept=default
 
IStreamImpl & operator= (IStreamImpl &&) noexcept=default
 
virtual ~IStreamImpl ()=default
 
Result feed (const uint8_t *buffer, size_t buflen) noexcept
 Feed bytes into the decoder, delivering every complete top-level field.
 
virtual void reset () noexcept
 Drop every byte of decoder state, so the next feed starts a brand-new message.
 
void invalidate () noexcept
 Mark the running decode INVALID from inside a deliver callback.
 
void exceedLimit () noexcept
 Report a receiver-side decode-limit violation from inside a deliver callback.
 
void rejectDestination () noexcept
 Refuse the current field because the caller's destination is too short for it (§6.3's third refusal tier, §6.6.3).
 
void rejectUnbounded () noexcept
 Refuse the current field because the call stated no bound for it at all (§6.3's InvalidArgument).
 
void rejectElementIndex (sofab::id bad) noexcept
 Refuse a wrapper-array element whose index is at or past a bound, in the category §6.3 gives that bound.
 
size_t skipped () const noexcept
 Number of fields skipped this stream because their wire tag contradicted the type the callback asked for (MESSAGE_SPEC §7.3).
 
template<typename T >
bool read (T &value) noexcept
 Read the current field's value, dispatching on value's type.
 
template<typename S , typename Sizer = detail::NoSizer>
bool readString (S &value, long bound, Sizer sizer={}) noexcept
 Read the current field as a string, or skip it (§7.3).
 
template<typename S , typename Sizer = detail::NoSizer>
bool readStringCapped (S &value, long dynCap, Sizer sizer={}) noexcept
 Read the current field as a schema-**unbounded** string under the receiver's max_dyn_string_len (§6.2.1).
 
template<typename B , typename Sizer = detail::NoSizer>
bool readBlob (B &value, long bound, Sizer sizer={}) noexcept
 Read the current field as a blob, or skip it (§7.3).
 
template<typename B , typename Sizer = detail::NoSizer>
bool readBlobCapped (B &value, long dynCap, Sizer sizer={}) noexcept
 Read the current field as a schema-**unbounded** blob under the receiver's max_dyn_blob_len (§6.2.1).
 
template<typename T , typename Sizer = detail::NoSizer>
bool readArray (T &dst, long schemaCount, ElemBound elem={}, Sizer sizer={}) noexcept
 Read a count-prefixed native array, applying every receiver-side decision at the one word that decides it.
 
template<typename T , typename Sizer = detail::NoSizer>
bool readArrayCapped (T &dst, long dynCap, ElemBound elem={}, Sizer sizer={}) noexcept
 Read a schema-**unbounded** count-prefixed array under the receiver's max_dyn_array_count (§6.2.1).
 
size_t read (void *dst, size_t maxlen) noexcept
 Read the current blob field into a caller buffer.
 
bool consumed () const noexcept
 
Wire wire () const noexcept
 Wire type of the field currently being delivered.
 
Fix fixType () const noexcept
 Fixlen sub-type of the field currently being delivered.
 
size_t announcedSize () const noexcept
 The payload length the current field's header announces — a string/blob byte count, or a fixlen array's element width.
 
size_t announcedCount () const noexcept
 The element count the current array field's header announces.
 
size_t available () const noexcept
 Bytes of this field readable right now, in the chunk being parsed.
 
size_t progress () const noexcept
 How much of the current field earlier chunks already delivered — payload bytes written, or array elements decoded.
 
bool resumed () const noexcept
 true when this delivery re-enters a sequence an earlier feed left open, rather than announcing a new field.
 
bool acceptsString (long bound) noexcept
 The §7.3 and §7.1 decisions readString makes, taken before a destination exists.
 
bool acceptsStringCapped (long dynCap) noexcept
 acceptsString for a schema-unbounded element, under the receiver's max_dyn_string_len (§6.2.1).
 
bool acceptsBlob (long bound) noexcept
 The §7.3 and §7.1 decisions readString makes, taken before a destination exists.
 
bool acceptsBlobCapped (long dynCap) noexcept
 acceptsString for a schema-unbounded element, under the receiver's max_dyn_string_len (§6.2.1).
 

Protected Types

enum class  Entry : uint8_t { Fresh , Descend , Resume }
 How a level is being entered (see levelEntry). More...
 
enum class  Field : uint8_t { Ready , SkipElem , Stop }
 What beginField found at this level's next field. More...
 

Protected Member Functions

 IStreamImpl (Limits limits) noexcept
 Construct with the receiver's Limits; a derived class installs topCallback_.
 
bool tagMatches (Wire wantWire) noexcept
 The §7.3 seam: does the delivered field's wire tag match the one the caller's read declares?
 
bool tagMatches (Wire wantWire, Fix wantFix) noexcept
 
bool tagMatches (Wire wantWire, Fix wantFix, Fix wantFix2) noexcept
 
template<typename D >
bool readPayload (D &value, bool validateUtf8) noexcept
 Deliver the current fixlen payload into the destination the caller handed over (§6.6.3, second shape).
 
template<typename D >
bool roomFor (D &value, size_t need) noexcept
 Is there room for need bytes in the destination the caller handed over (§6.6.3)?
 
template<typename D >
bool readPayloadPiece (D &value, bool validateUtf8, size_t avail) noexcept
 The chunk-straddling half of readPayload — deliver the piece that has arrived and remember how far the value got.
 
bool capCannotFire (size_t n) const noexcept
 Hoisted form of exceedsBuffer for a whole window of n bytes: true when no field of it can cross the budget.
 
bool exceedsBuffer (size_t consumed, uint64_t need) const noexcept
 Would buffering this field cross maxBufferedField_?
 
Entry levelEntry () noexcept
 Decide how this level is being entered, and clear the replay state once the suspended level is reached.
 
template<typename Cb >
void dispatchLevel (Cb &&cb, bool stopAtEnd) noexcept
 
Field beginField (bool stopAtEnd) noexcept
 Parse the next field's header and metadata at a nested level, and apply every rule that is decided before the value.
 
bool finishField (const uint8_t *fieldStart, const uint8_t *payload, sofab::id fieldId) noexcept
 Settle a field the callback has been offered: skip it if the callback did not want it, suspend it if its bytes ran out.
 
void closeLevel (bool stopAtEnd) noexcept
 The bytes ran out with this sequence still open — INCOMPLETE, not malformed (§7).
 
bool reenterLevel (FieldCb cb, Entry entry) noexcept
 Take the Entry::Descend or Entry::Resume path.
 
void suspendHere (sofab::id fieldId, bool declined) noexcept
 Record that this level's current field is the suspension point.
 
void suspendAtBoundary () noexcept
 Claim the suspension for this level at a field boundary — nothing half-delivered, only a header cut in two or a sequence still open.
 
void restorePending () noexcept
 Put the suspended field's header back before continuing it.
 
bool deliverPending (FieldCb cb, bool declined) noexcept
 Re-deliver the half-delivered field at this level.
 
bool descendResume (FieldCb cb) noexcept
 Re-descend one recorded level of pathId_ towards suspendDepth_.
 
void skipPayload () noexcept
 Step over the payload of the current field, resumably.
 
void skipSequence () noexcept
 Walk a sub-sequence nobody asked for, delivering nothing.
 
size_t spanned () const noexcept
 The bytes of the current top-level field seen so far, across every chunk it spans (#26, Limits::max_buffered_field).
 
size_t spannedLive () const noexcept
 spanned less what this field spent on skipped subtrees — the number the field-span cap is measured against (§6.2.1).
 
void discountSkipped (const uint8_t *from) noexcept
 Discount a skipped field's bytes from the live span (§6.2.1).
 
Result latchTerminal () noexcept
 Latch the refusal this feed produced, in §6.3's order of tiers.
 
void stash (const uint8_t *p, size_t n) noexcept
 Hold the ≤ CARRY_CAP bytes of a cut item until the next feed.
 
size_t parseWindow (const uint8_t *p, size_t n) noexcept
 Parse one window of bytes, resuming whatever the last one left open, and report how much of it was consumed.
 
void parseTopLevel () noexcept
 Deliver every complete top-level field in the current window, leaving p_ at the first byte not consumed.
 
bool parseFieldTag () noexcept
 Parse a field header word into fieldId_ and type_ (§4.3).
 
bool parseFieldMeta () noexcept
 Parse the word(s) between a field header and its payload — the fixlen word (§4.6), the array count (§4.7) or both (§4.8).
 
bool parseFieldHeader () noexcept
 Parse one top-level field header plus the metadata that precedes its payload, into the current-field members.
 
bool exceedsBufferAtHeader () noexcept
 Would this field cross maxBufferedField_, judged from its header alone (#26)?
 
template<bool Bounded, typename Elem >
bool readIntElements (std::span< Elem > sp, ElemBound b={}) noexcept
 Decode the current integer-array payload: count_ varint elements, the first sp.size() of them into sp.
 
template<typename S , typename Sizer >
bool readStringGated (S &value, long bound, long dynCap, Sizer sizer) noexcept
 The body both string reads share, so the two cannot answer differently.
 
template<typename B , typename Sizer >
bool readBlobGated (B &value, long bound, long dynCap, Sizer sizer) noexcept
 The body both blob reads share.
 
template<typename T , typename Sizer >
bool readArrayGated (T &dst, long schemaCount, long dynCap, ElemBound elem, Sizer sizer) noexcept
 The body both array reads share.
 
bool acceptsStringGated (long bound, long dynCap) noexcept
 The body both string accepts share.
 
bool acceptsBlobGated (long bound, long dynCap) noexcept
 The body both blob accepts share.
 

Static Protected Member Functions

static bool getVarintWindowed (const uint8_t *&p, uint64_t &out, bool *overflow) noexcept
 Read one varint, given that a full varint window is in the buffer.
 
static bool skipVarintWindowed (const uint8_t *&p, bool *overflow) noexcept
 getVarintWindowed without building the value — see skipVarint.
 
static bool getVarint (const uint8_t *&p, const uint8_t *end, uint64_t &out, bool *overflow=nullptr) noexcept
 Read one base-128 varint, advancing the cursor (bounds-checked).
 
static bool skipVarint (const uint8_t *&p, const uint8_t *end, bool *overflow=nullptr) noexcept
 Advance the cursor past one varint without decoding it (bounds-checked).
 
static bool fixlenWordValid (uint64_t word) noexcept
 Validate a single Fixlen field's length-and-subtype word (§4.6, §6.2).
 
static bool arrayFixlenWordValid (uint64_t word) noexcept
 Validate a ArrayFixlen element word (§4.8, §6.2).
 
template<std::floating_point F>
static F loadFloat (const uint8_t *p) noexcept
 Load a little-endian float or double from raw bytes.
 
template<typename Cb >
static FieldCb wrapCb (Cb &cb) noexcept
 Wrap a level's callback as a FieldCb.
 
static constexpr bool schemaBoundsHeader (Wire w) noexcept
 Does this wire type's header state a size the schema can bound?
 

Protected Attributes

uint8_t carry_ [CARRY_CAP]
 The prefix of one cut item, carried to the next feed.
 
size_t carryLen_ = 0
 Live bytes of carry_.
 
int suspendDepth_ = -1
 Depth at which the parse is suspended, or -1 when nothing is.
 
bool replay_ = false
 Re-descending pathId_ to reach suspendDepth_.
 
sofab::id pathId_ [MAX_DEPTH+1]
 Id of the sequence field entered at each open level (§4.9).
 
bool pathSkip_ [MAX_DEPTH+1]
 That level was entered by skipPayload, not by a handler.
 
bool pend_ = false
 A field at suspendDepth_ is half-delivered.
 
sofab::id pendId_ = 0
 That field's header, kept apart from the live type_ / fixLen_ / count_.
 
Wire pendType_ {}
 That field's header, kept apart from the live type_ / fixLen_ / count_.
 
Fix pendFix_ {}
 That field's header, kept apart from the live type_ / fixLen_ / count_.
 
size_t pendLen_ = 0
 That field's header, kept apart from the live type_ / fixLen_ / count_.
 
size_t pendCount_ = 0
 That field's header, kept apart from the live type_ / fixLen_ / count_.
 
bool pendSkip_ = false
 ...and it was declined, so skipPayload resumes it rather than the handler.
 
size_t pendDone_ = 0
 Progress through the pending field: payload bytes already written into the caller's destination, or array elements already decoded.
 
uint32_t utf8State_ = 0
 Incremental UTF-8 DFA state for the string payload in progress (§6.4.4).
 
size_t spanCarry_ = 0
 Bytes of the current top-level field consumed in earlier chunks (#26).
 
const uint8_t * spanBase_ = nullptr
 Where that field's span continues in the window being parsed (#26).
 
bool spanSkip_ = false
 Is the parse currently inside a skipped sequence subtree (§6.2.1, #129)?
 
bool capInert_ = false
 Can the field-span cap provably not fire anywhere in the window being parsed (§6.2.1, #26)? Set once per parseWindow.
 
size_t spanSkipped_ = 0
 Bytes of the current top-level field spent on SKIPPED subtrees (§6.2.1, #129 one level down).
 
const uint8_t * p_ = nullptr
 Read cursor.
 
const uint8_t * end_ = nullptr
 One past the last readable byte.
 
Wire type_ {}
 Wire type of the field being delivered.
 
Fix fixType_ {}
 Sub-type of the current fixlen field.
 
size_t fixLen_ = 0
 Payload length (fixlen) or element size (fixlen array), in bytes.
 
size_t count_ = 0
 Element count of the current array field.
 
bool consumed_ = false
 Set once the callback has read the current field's value.
 
bool error_ = false
 Sticky "this feed was refused" flag, and the only one the parse loops test.
 
bool limitExceeded_ = false
 Category: a receiver-side limit was crossed (§6.2.1).
 
bool argError_ = false
 Category: a well-formed value did not fit the destination the caller handed over (§6.3's third refusal tier, §6.6.3).
 
Error terminal_ = Error::None
 The stream's latched terminal verdict, or Error::None while the stream is still usable (§5.2, §6.3).
 
int seqDepth_ = 0
 Current nested-sequence depth during dispatch (§4.9 MAX_DEPTH).
 
size_t skipped_ = 0
 §7.3 type-mismatch skips seen so far (skipped).
 
bool incomplete_ = false
 The field being delivered needs more bytes (§7 INCOMPLETE, not malformed).
 
long elemBound_ = -1
 The tightest armed element-index bound of the wrapper sequence being read (§5.1); -1 = none.
 
long elemSchema_ = -1
 Schema count N: an id at or past it is InvalidMessage (§7.1).
 
long elemDyn_ = -1
 Configured max_dyn_array_count: LimitExceeded (§6.2.1).
 
long elemDest_ = -1
 The destination container's own capacity: InvalidArgument (§6.6.3).
 
int elemWire_ = -1
 §7.3 wire type its elements must carry (a Wire as int); -1 = the collector decides the bound itself.
 
int elemFix_ = -1
 §7.3 fixlen subtype for that element type (a Fix as int); -1 = the element type has none.
 
sofab::id fieldId_ = 0
 Id of the field being delivered.
 
size_t maxBufferedField_
 The receiver's byte budget for one top-level field (Limits::max_buffered_field), as this decode was told it.
 
std::function< void(sofab::id, size_t, size_t)> topCallback_
 Delivers each top-level field.
 

Static Protected Attributes

static constexpr size_t CARRY_CAP = 3 * detail::VARINT_MAX_BYTES
 Widest prefix of a wire item that can outlive a chunk boundary, derived from this format's own constants (§6.6).
 
static constexpr uint64_t CAP_NEED_MAX
 Upper bound of any header-declared need (§6.2 ceilings).
 

Detailed Description

Base of the input streams: decodes fields from fed bytes.

Bytes are supplied through feed, which may be called repeatedly with chunks. A whole message handed in at once is parsed in place with no copy; an incomplete trailing field is buffered and resumed on the next feed. Each complete top-level field is delivered to a callback, inside which read pulls the field's value out at the matching type.

Definition at line 2918 of file sofab.hpp.

Member Enumeration Documentation

◆ Entry

enum class sofab::IStreamImpl::Entry : uint8_t
strongprotected

How a level is being entered (see levelEntry).

Enumerator
Fresh 

Nothing open here: parse the next field.

Descend 

The suspended level is deeper: replay one more id.

Resume 

This level is it: continue its half-delivered field.

Definition at line 3755 of file sofab.hpp.

◆ Field

enum class sofab::IStreamImpl::Field : uint8_t
strongprotected

What beginField found at this level's next field.

Enumerator
Ready 

Deliver it.

SkipElem 

§7.3 says it is not this array's element: skip, do not deliver.

Stop 

The level is finished, suspended or refused.

Definition at line 3815 of file sofab.hpp.

Constructor & Destructor Documentation

◆ IStreamImpl() [1/3]

sofab::IStreamImpl::IStreamImpl ( Limits  limits)
inlineexplicitprotectednoexcept

Construct with the receiver's Limits; a derived class installs topCallback_.

There is no default constructor. §6.2.1 leaves this codec no number to invent, so a stream that was told none cannot be built: the omission is a compile error rather than a decode that turns out to have been bounded by nothing.

Definition at line 3234 of file sofab.hpp.

◆ IStreamImpl() [2/3]

sofab::IStreamImpl::IStreamImpl ( const IStreamImpl &  )
delete

◆ IStreamImpl() [3/3]

sofab::IStreamImpl::IStreamImpl ( IStreamImpl &&  )
defaultnoexcept

◆ ~IStreamImpl()

virtual sofab::IStreamImpl::~IStreamImpl ( )
virtualdefault

Member Function Documentation

◆ acceptsBlob()

bool sofab::IStreamImpl::acceptsBlob ( long  bound)
inlinenoexcept

The §7.3 and §7.1 decisions readString makes, taken before a destination exists.

For a caller that has to place an element before it can offer a destination — StringSeq puts an element at its index, and growing the container for a field that turns out not to be an element would change the array's length (§5.1/§7.4). It answers the same two questions readString answers first, in the same order and through the same seam, so the skip is counted exactly once: the tag (§7.3) and then the declared maxlen (§7.1).

It takes the §6.2.1 receiver cap on the same terms as readString — passed in, never held, and consulted only where bound is negative — so the two seams cannot answer differently.

It splits into a bounded and a capped form for the same reason readString does, and refuses a call that states neither the same way (rejectUnbounded).

Parameters
boundDeclared maxlen. Required and non-negative; acceptsStringCapped is the schema-unbounded form.
Returns
true when a destination may be placed and handed to readString.

Definition at line 6094 of file sofab.hpp.

◆ acceptsBlobCapped()

bool sofab::IStreamImpl::acceptsBlobCapped ( long  dynCap)
inlinenoexcept

acceptsString for a schema-unbounded element, under the receiver's max_dyn_string_len (§6.2.1).

Parameters
dynCapThe caller's cap. Required and non-negative.

Definition at line 6101 of file sofab.hpp.

◆ acceptsBlobGated()

bool sofab::IStreamImpl::acceptsBlobGated ( long  bound,
long  dynCap 
)
inlineprotectednoexcept

The body both blob accepts share.

Definition at line 6109 of file sofab.hpp.

◆ acceptsString()

bool sofab::IStreamImpl::acceptsString ( long  bound)
inlinenoexcept

The §7.3 and §7.1 decisions readString makes, taken before a destination exists.

For a caller that has to place an element before it can offer a destination — StringSeq puts an element at its index, and growing the container for a field that turns out not to be an element would change the array's length (§5.1/§7.4). It answers the same two questions readString answers first, in the same order and through the same seam, so the skip is counted exactly once: the tag (§7.3) and then the declared maxlen (§7.1).

It takes the §6.2.1 receiver cap on the same terms as readString — passed in, never held, and consulted only where bound is negative — so the two seams cannot answer differently.

It splits into a bounded and a capped form for the same reason readString does, and refuses a call that states neither the same way (rejectUnbounded).

Parameters
boundDeclared maxlen. Required and non-negative; acceptsStringCapped is the schema-unbounded form.
Returns
true when a destination may be placed and handed to readString.

Definition at line 6063 of file sofab.hpp.

◆ acceptsStringCapped()

bool sofab::IStreamImpl::acceptsStringCapped ( long  dynCap)
inlinenoexcept

acceptsString for a schema-unbounded element, under the receiver's max_dyn_string_len (§6.2.1).

Parameters
dynCapThe caller's cap. Required and non-negative.

Definition at line 6074 of file sofab.hpp.

◆ acceptsStringGated()

bool sofab::IStreamImpl::acceptsStringGated ( long  bound,
long  dynCap 
)
inlineprotectednoexcept

The body both string accepts share.

Definition at line 6082 of file sofab.hpp.

◆ announcedCount()

size_t sofab::IStreamImpl::announcedCount ( ) const
inlinenoexcept

The element count the current array field's header announces.

§6.6.3's "after being told the announced count": the number the caller sizes its destination from before handing it back. Identical to the size argument of the deliver callback, reachable from a helper that was not handed it (sofab::readString and friends).

Definition at line 5990 of file sofab.hpp.

◆ announcedSize()

size_t sofab::IStreamImpl::announcedSize ( ) const
inlinenoexcept

The payload length the current field's header announces — a string/blob byte count, or a fixlen array's element width.

§6.6.3's "after being told the announced count": the number the caller sizes its destination from before handing it back. Identical to the size argument of the deliver callback, reachable from a helper that was not handed it (sofab::readString and friends).

Definition at line 5984 of file sofab.hpp.

◆ arrayFixlenWordValid()

static bool sofab::IStreamImpl::arrayFixlenWordValid ( uint64_t  word)
inlinestaticprotectednoexcept

Validate a ArrayFixlen element word (§4.8, §6.2).

A fixlen array may only carry fixed-width elements — Fp32 (4 bytes) or Fp64 (8 bytes). Dynamic subtypes (String, Blob) and the reserved subtypes are not permitted as array elements (§4.8); such a word is INVALID.

Parameters
wordThe decoded per-element fixlen_word.
Returns
true if the subtype/element-size pair is legal for a fixlen array.

Definition at line 3463 of file sofab.hpp.

◆ available()

size_t sofab::IStreamImpl::available ( ) const
inlinenoexcept

Bytes of this field readable right now, in the chunk being parsed.

What lets a helper sizing a destination clamp an announced count to what the bytes in hand could ever fill, so a hostile count never decides an allocation — the same clamp readArray applies to its own refusal.

Definition at line 5999 of file sofab.hpp.

◆ beginField()

Field sofab::IStreamImpl::beginField ( bool  stopAtEnd)
inlineprotectednoexcept

Parse the next field's header and metadata at a nested level, and apply every rule that is decided before the value.

Split out of dispatchLevel so it is compiled once rather than once per callback type: the loop's callback is a template parameter so the delivery inlines, but everything around it is the same code in every instantiation, and a dozen copies of it are a dozen copies of the §7.3 and §5.1 rules for a reader to keep in step.

Parameters
stopAtEndWhether a Wire::SequenceEnd closes this level.
Returns
Field::Stop when dispatchLevel must return.

Definition at line 3835 of file sofab.hpp.

◆ capCannotFire()

bool sofab::IStreamImpl::capCannotFire ( size_t  n) const
inlineprotectednoexcept

Hoisted form of exceedsBuffer for a whole window of n bytes: true when no field of it can cross the budget.

Definition at line 3677 of file sofab.hpp.

◆ closeLevel()

void sofab::IStreamImpl::closeLevel ( bool  stopAtEnd)
inlineprotectednoexcept

The bytes ran out with this sequence still open — INCOMPLETE, not malformed (§7).

The level is re-entered along pathId_ once the remaining bytes arrive.

Definition at line 3975 of file sofab.hpp.

◆ consumed()

bool sofab::IStreamImpl::consumed ( ) const
inlinenoexcept
Returns
true when a read in this delivery consumed the field. false means the field was declined (skipped) or its payload has not arrived yet, in which case the field is delivered again with the next chunk and the read continues where it stopped.

Definition at line 5948 of file sofab.hpp.

◆ deliverPending()

bool sofab::IStreamImpl::deliverPending ( FieldCb  cb,
bool  declined 
)
inlineprotectednoexcept

Re-deliver the half-delivered field at this level.

Its metadata (type_, fixLen_, count_, fieldId_) is still the state the previous chunk left, and pendDone_ says how far it got, so the read (or the skip) continues where it stopped instead of starting over.

Returns
false when the level must return — the field suspended again, or the decode failed.

Definition at line 4061 of file sofab.hpp.

◆ descendResume()

bool sofab::IStreamImpl::descendResume ( FieldCb  cb)
inlineprotectednoexcept

Re-descend one recorded level of pathId_ towards suspendDepth_.

Replays the sequence field this level was inside when the chunk ran out: either by handing its id back to cb — whose deserialize dispatches on the id and calls read on the same member, re-establishing exactly the handler that was open — or, for a level that was being skipped, by re-entering the skip descent directly. Nothing is parsed here: the bytes of the sequence header were consumed by an earlier chunk and are gone.

Parameters
cbThis level's per-field callback.
Returns
false when the level must return.

Definition at line 4103 of file sofab.hpp.

◆ discountSkipped()

void sofab::IStreamImpl::discountSkipped ( const uint8_t *  from)
inlineprotectednoexcept

Discount a skipped field's bytes from the live span (§6.2.1).

Definition at line 4601 of file sofab.hpp.

◆ dispatchLevel()

template<typename Cb >
void sofab::IStreamImpl::dispatchLevel ( Cb &&  cb,
bool  stopAtEnd 
)
inlineprotectednoexcept

Definition at line 3779 of file sofab.hpp.

◆ exceedLimit()

void sofab::IStreamImpl::exceedLimit ( )
inlinenoexcept

Report a receiver-side decode-limit violation from inside a deliver callback.

Sets the sticky limit flag, so the surrounding feed stops dispatching further fields and returns Error::LimitExceeded. For callers enforcing policy caps the wire layer cannot know — e.g. a generated message rejecting an unbounded (schema-bound-less) array/string/blob whose claimed count/length exceeds a configured decode limit (generator#102). Deliberately distinct from invalidate: the bytes may be perfectly well-formed; rejecting them is receiver policy, not wire malformation (§7). Idempotent; a no-op outside a feed since every feed clears the flag on entry.

Definition at line 4486 of file sofab.hpp.

◆ exceedsBuffer()

bool sofab::IStreamImpl::exceedsBuffer ( size_t  consumed,
uint64_t  need 
) const
inlineprotectednoexcept

Would buffering this field cross maxBufferedField_?

Parameters
consumedBytes of the current top-level field already spanned.
needFurther bytes the field is now known to require (a declared payload length, array byte-span, or per-element lower bound).
Returns
true if consumed + need exceeds the cap. Overflow-safe: the addition is never formed, so a caller that stated SIZE_MAX as its budget gets a check that runs and never fires, rather than a check this library switched off.

Definition at line 3696 of file sofab.hpp.

◆ exceedsBufferAtHeader()

bool sofab::IStreamImpl::exceedsBufferAtHeader ( )
inlineprotectednoexcept

Would this field cross maxBufferedField_, judged from its header alone (#26)?

The header states the size exactly for a fixlen or fixlen-array payload; a varint array's count is a lower bound on its bytes. A sequence accrues instead, and is bounded field by field in dispatchLevel.

Returns
true when the field must be rejected before its payload is read.

Definition at line 4983 of file sofab.hpp.

◆ feed()

Result sofab::IStreamImpl::feed ( const uint8_t *  buffer,
size_t  buflen 
)
inlinenoexcept

Feed bytes into the decoder, delivering every complete top-level field.

May be called repeatedly with successive chunks; a field split across chunks is resumed on a later call — its pieces are written into the caller's destination as they arrive, and only what a chunk boundary can cut in half (a field header, the words before a payload, one varint element — at most CARRY_CAP bytes) is carried over. Every chunk is parsed in place; nothing is copied but the value itself.

Note
A field split across chunks is therefore delivered once per chunk that carries part of it, with the same id and header, and the typed read continues where it stopped (progress). The destination has to stay put until the field completes: a member of the message object does, a local in the callback does not.
Parameters
bufferBytes to decode.
buflenNumber of bytes in buffer.
Returns
A Result carrying the three-valued §7 outcome: Error::None (COMPLETE) when the fed bytes end exactly at a field boundary; Error::Incomplete (INCOMPLETE) when they end inside a field (partial varint, short fixlen/array payload) or with an open sequence — the decoder keeps its place for the next feed and this is not an error; or Error::InvalidMessage (INVALID) when the bytes are malformed regardless of what follows. Error::LimitExceeded is the fourth, receiver-policy outcome (§6.2.1) — well-formed bytes this receiver refuses to buffer.
Note
INVALID and LimitExceeded are terminal. §5.2 answers "can more bytes change it?" with "no — terminal" for INVALID, and §6.3 calls LimitExceeded "a terminal, receiver-local policy rejection". Once feed has returned either, the verdict is latched on the stream: every later call returns the same code without parsing a byte, no further field is delivered, and the input after the fault is neither buffered nor inspected. reset is the way back — it is the documented start of a new message anyway. This is what makes the outcome chunk-independent (§7.2 item 4): the same bytes fed whole, in odd-sized chunks or one at a time all end on the same verdict, and garbage prefixed to a valid message can never be reported as COMPLETE.
Warning
One message per destination. Successive feed calls continue the same message — a decoder cannot see a message boundary, because a message has no framing on the wire and a zero-byte message is legal (MESSAGE_SPEC §2). Decoding a second message therefore requires a destination reset: call reset (which for IStreamObject also re-initialises the wrapped message) or use a fresh stream. MESSAGE_SPEC §5.1 puts this duty on the decoding side — "supplying a cleanly initialised destination is the application's responsibility" — and §2 makes it load-bearing: an all-default field is absent from the bytes, so nothing runs for it and whatever the previous message left in that member survives.

Definition at line 4331 of file sofab.hpp.

◆ finishField()

bool sofab::IStreamImpl::finishField ( const uint8_t *  fieldStart,
const uint8_t *  payload,
sofab::id  fieldId 
)
inlineprotectednoexcept

Settle a field the callback has been offered: skip it if the callback did not want it, suspend it if its bytes ran out.

The callback did not want this field: rewind to the payload — which the declining read left the cursor at anyway — and skip it, resumably, so a long payload nobody asked for is stepped over as it arrives rather than buffered (§6.6.2).

§7: the bytes running out INSIDE the field is a different thing. It is unfinished, not declined, and the two must not be confused — hence the !incomplete_ in the test. Skipping a truncation would rewind into a payload the callback has already parsed into and re-read those bytes under the metadata of whatever innermost field the descent left behind, reporting INVALID for a truncation (Crucible F-0056, corelib-cpp#71).

§6.2.1: what the skip walks past is discounted from the field-span cap — from fieldStart, so the skipped child's own header goes with it. A skip that SUSPENDS discounts what this window walked and the resume (deliverPending) discounts the rest, which is what keeps the verdict independent of the caller's chunking (§7.2 item 4).

Parameters
fieldStartThe field's first header byte.
payloadThe field's first payload byte.
fieldIdIts id, for the path entry a suspension records.
Returns
false when the level must return.

Definition at line 3950 of file sofab.hpp.

◆ fixlenWordValid()

static bool sofab::IStreamImpl::fixlenWordValid ( uint64_t  word)
inlinestaticprotectednoexcept

Validate a single Fixlen field's length-and-subtype word (§4.6, §6.2).

A well-formed word carries a defined subtype (0–3) whose length is legal for that subtype: a Fp32 payload is exactly 4 bytes, Fp64 exactly 8, and String/Blob any length up to FIXLEN_MAX. Subtypes 0b100..0b111 are reserved. A violation is malformed regardless of what follows (spec §7 INVALID), so it must be rejected rather than mistaken for a truncated (INCOMPLETE) field.

Parameters
wordThe decoded fixlen_word ((length << 3) | subtype).
Returns
true if the subtype/length pair is legal for a scalar fixlen field.

Definition at line 3439 of file sofab.hpp.

◆ fixType()

Fix sofab::IStreamImpl::fixType ( ) const
inlinenoexcept

Fixlen sub-type of the field currently being delivered.

Only meaningful when wire is a fixlen kind. Introspection only, like wire: readString / readBlob state the declared subtype and the stream compares it. Reads no bytes and does not consume the field.

Returns
The delivered field's Fix.

Definition at line 5973 of file sofab.hpp.

◆ getVarint()

static bool sofab::IStreamImpl::getVarint ( const uint8_t *&  p,
const uint8_t *  end,
uint64_t &  out,
bool *  overflow = nullptr 
)
inlinestaticprotectednoexcept

Read one base-128 varint, advancing the cursor (bounds-checked).

Parameters
[in,out]pCursor; advanced past the varint on success.
endOne past the last readable byte.
[out]outDecoded value.
Returns
true on success, false if the buffer ends mid-varint or it overflows 64 bits. On overflow (a varint > 64 bits, §4.1) *overflow is set: that is INVALID regardless of what follows, and callers in callers must distinguish it from a merely-truncated tail.

Definition at line 3356 of file sofab.hpp.

◆ getVarintWindowed()

static bool sofab::IStreamImpl::getVarintWindowed ( const uint8_t *&  p,
uint64_t &  out,
bool *  overflow 
)
inlinestaticprotectednoexcept

Read one varint, given that a full varint window is in the buffer.

The caller must have established that at least detail::VARINT_MAX_BYTES bytes are readable at p. That single fact retires both per-byte checks the general path needs: the cursor cannot run past the end inside ten bytes, and the first nine bytes carry at most 63 payload bits, so only the tenth can be overlong (§4.1). With the checks gone the first eight bytes can be taken as one word and unpacked with detail::gather7, leaving only a ninth and tenth byte to guard.

Parameters
[in,out]pCursor; advanced past the varint, including on overflow.
[out]outDecoded value.
overflowSet when the varint is wider than 64 bits (INVALID, §6.3).
Returns
true on success, false on a > 64-bit varint.

Definition at line 3260 of file sofab.hpp.

◆ invalidate()

void sofab::IStreamImpl::invalidate ( )
inlinenoexcept

Mark the running decode INVALID from inside a deliver callback.

Sets the sticky decode-error flag, so the surrounding feed stops dispatching further fields and returns Error::InvalidMessage (INVALID). For callers that detect malformed content the wire layer cannot judge on its own — e.g. a generated message rejecting an array whose wire element count exceeds its schema count capacity, which is INVALID per spec §3/§7 (generator#100). Idempotent; a no-op outside a feed since every feed clears the flag on entry.

Definition at line 4470 of file sofab.hpp.

◆ latchTerminal()

Result sofab::IStreamImpl::latchTerminal ( )
inlineprotectednoexcept

Latch the refusal this feed produced, in §6.3's order of tiers.

Definition at line 4607 of file sofab.hpp.

◆ levelEntry()

Entry sofab::IStreamImpl::levelEntry ( )
inlineprotectednoexcept

Decide how this level is being entered, and clear the replay state once the suspended level is reached.

Non-template on purpose: every dispatchLevel instantiation asks the same question, and only the answer differs.

Definition at line 3769 of file sofab.hpp.

◆ loadFloat()

template<std::floating_point F>
static F sofab::IStreamImpl::loadFloat ( const uint8_t *  p)
inlinestaticprotectednoexcept

Load a little-endian float or double from raw bytes.

Template Parameters
FFloating-point type to read (float or double).
Parameters
pPointer to at least sizeof(F) readable bytes.
Returns
The decoded value.

Definition at line 3481 of file sofab.hpp.

◆ operator=() [1/2]

IStreamImpl & sofab::IStreamImpl::operator= ( const IStreamImpl &  )
delete

◆ operator=() [2/2]

IStreamImpl & sofab::IStreamImpl::operator= ( IStreamImpl &&  )
defaultnoexcept

◆ parseFieldHeader()

bool sofab::IStreamImpl::parseFieldHeader ( )
inlineprotectednoexcept

Parse one top-level field header plus the metadata that precedes its payload, into the current-field members.

parseFieldTag + parseFieldMeta, with the one rule that is the top level's own: a Wire::SequenceEnd here closes a sequence that was never opened, which is INVALID (§7). Inside a sequence the same marker is the close, which is why dispatchLevel puts its own test between the two calls.

Returns
true when the header is complete and well-formed. On false either error_ (malformed) or incomplete_ (more bytes needed) is set.

Definition at line 4943 of file sofab.hpp.

◆ parseFieldMeta()

bool sofab::IStreamImpl::parseFieldMeta ( )
inlineprotectednoexcept

Parse the word(s) between a field header and its payload — the fixlen word (§4.6), the array count (§4.7) or both (§4.8).

Shared by the two parse loops for the same reason as parseFieldTag: this is where §4.6's subtype/length pairing, §4.8's element-subtype rule and §6.2's ARRAY_MAX ceiling are enforced, and a second copy of it is a place for one of them to go missing — which is exactly how the nested path lost the ARRAY_MAX check on a fixlen array until #103. A varint or sequence header states no metadata, so it falls through.

Returns
true when the metadata is complete and well-formed, with fixLen_, count_ and fixType_ set. On false either error_ or incomplete_ is set.

Definition at line 4847 of file sofab.hpp.

◆ parseFieldTag()

bool sofab::IStreamImpl::parseFieldTag ( )
inlineprotectednoexcept

Parse a field header word into fieldId_ and type_ (§4.3).

The only place a (id << 3) | wire_type word is taken apart. Both parse loops — parseTopLevel through parseFieldHeader, and dispatchLevel inside a sequence — come through here, so the ID_MAX ceiling (§6.2) cannot be present in one and missing from the other.

Returns
true when a whole header word was read and its id is legal. On false either error_ (a > 64-bit varint, or an id past ID_MAX) or incomplete_ (the word is cut short) is set.

Definition at line 4813 of file sofab.hpp.

◆ parseTopLevel()

void sofab::IStreamImpl::parseTopLevel ( )
inlineprotectednoexcept

Deliver every complete top-level field in the current window, leaving p_ at the first byte not consumed.

The same shape as dispatchLevel, and for the same reasons: a level the previous window left open is re-entered rather than re-parsed, either by descending pathId_ to the suspended level or — when this level is it — by continuing the field pendDone_ describes.

Definition at line 4667 of file sofab.hpp.

◆ parseWindow()

size_t sofab::IStreamImpl::parseWindow ( const uint8_t *  p,
size_t  n 
)
inlineprotectednoexcept

Parse one window of bytes, resuming whatever the last one left open, and report how much of it was consumed.

Parameters
pWindow start.
nWindow length.
Returns
Bytes consumed. Whatever follows is a cut item, at most CARRY_CAP bytes of it.

Definition at line 4644 of file sofab.hpp.

◆ progress()

size_t sofab::IStreamImpl::progress ( ) const
inlinenoexcept

How much of the current field earlier chunks already delivered — payload bytes written, or array elements decoded.

Zero on a field's first delivery. A field split across feed calls is continued, not re-parsed (§6.6.2), so a helper sizing the destination has to add what is already in it to what has just arrived; sizing from this chunk alone would ask the codec to fit a value into less room than it has already used.

Definition at line 6014 of file sofab.hpp.

◆ read() [1/2]

template<typename T >
bool sofab::IStreamImpl::read ( T &  value)
inlinenoexcept

Read the current field's value, dispatching on value's type.

Call from inside a deliver callback. Handles integers (signed values are un-zig-zagged), bool, float, double, std::string, nested sofab::IStreamMessage objects, and writable contiguous ranges of integers, booleans or floats (excess wire elements past the span's capacity are read and discarded). A bool scalar or element reads every non-zero value as true and is bounded by no width (§4.4). On a malformed or truncated field the stream's error flag is set.

Every destination owns what it receives. There is deliberately no borrowing destination: a fed chunk is the caller's for the duration of feed only (CORELIB_PLAN §6), so a decoded value must survive the caller reusing, overwriting or freeing that memory the moment feed returns.

Template Parameters
TType to decode into.
Parameters
[out]valueDestination for the decoded value.

Definition at line 5193 of file sofab.hpp.

◆ read() [2/2]

size_t sofab::IStreamImpl::read ( void *  dst,
size_t  maxlen 
)
inlinenoexcept

Read the current blob field into a caller buffer.

Copies up to maxlen bytes; the field is consumed regardless of how much fit. Call from inside a deliver callback.

Declares a blob like readBlob, so it compares the whole tag first (§7.3): any other field — an integer, a sequence, an array, or another fixlen subtype — is left for the decoder to skip, with dst untouched. That check is what keeps the cursor sane, because fixLen_ only means "payload length" for a scalar fixlen field: it is 0 for a varint field and the per-ELEMENT width for a fixlen array, so consuming on those tags left the parser standing inside the payload and re-reading it as field headers (issue #80).

Parameters
dstDestination buffer.
maxlenCapacity of dst in bytes.
Returns
Number of bytes copied (min(maxlen, payload length)), or 0 when the field was not consumed. Zero is therefore ambiguous on its own — a zero-length blob also copies nothing, and so does a skipped mismatch — so a caller that needs to tell them apart consults consumed().

Definition at line 5911 of file sofab.hpp.

◆ readArray()

template<typename T , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readArray ( T &  dst,
long  schemaCount,
ElemBound  elem = {},
Sizer  sizer = {} 
)
inlinenoexcept

Read a count-prefixed native array, applying every receiver-side decision at the one word that decides it.

Folds what a caller previously had to spell out in four steps — check the wire tag, check the schema count, check a configured policy cap, reset the destination — into one call, in the only order that is correct:

  1. Tag (§7.3). A contradicting array kind is skipped like an unknown id; nothing else runs, so neither bound below can be applied to a field that is not this field's value.
  2. Schema count (§7.1/§5.2) → INVALID. Malformed input.
  3. Configured receiver cap (dynCap, §6.2.1) → LimitExceeded. Deliberately not INVALID: the bytes are fine and the same message decodes under a looser cap. 3b. The destination's own capacity, for a destination that publishes one → InvalidArgument (§6.3's third tier, §6.6.3): a count it cannot hold is refused instead of silently truncated into it (MESSAGE_SPEC §3), and by this point neither the schema nor the deployment has anything left to object to — only this caller's storage.
  4. Reset, then fill. The destination is resized (dynamic container) or value-initialized (fixed extent) only now, so an occurrence skipped at step 1 cannot wipe a valid earlier one (§7.4). A destination pre-sized to a declared count: N keeps the element default in the slots past the wire count M, which is the array's length — there is no fill-to-N and no trailing elision to undo (§3).
  5. Declared element width (elem, §7.1) → INVALID, per element as it is decoded. The sibling of the count bound at step 2: the same class of schema fact, arriving through the same call, and the reason it is applied here rather than by the caller — an element cannot be range-checked after the fact without a wide temporary copy of the whole array. Unarmed by default, so an omitted bound decodes exactly as before.
Parameters
[out]dstDestination range (fixed extent or resizable).
schemaCountDeclared count: N, or negative when unbounded. Split into two entry points on the same terms as readString: this one takes the declared count, readArrayCapped takes the receiver cap, and neither has a default.
elemDeclared element range (ElemBound), e.g. ElemBound::of<std::uint8_t>() for items: u8. Ignored for a float element type, which has no narrowing to reject: fp32/fp64 are carried at their own width on the wire. Ignored for a bool element too, which §4.4 bounds by no width at all: every non-zero element is true.
schemaCountDeclared count: N. Required and non-negative; a schema-unbounded array is read through readArrayCapped.
Returns
true when the array was read; false when it was skipped (§7.3) or rejected, with the outcome already recorded on the stream.

Definition at line 5719 of file sofab.hpp.

◆ readArrayCapped()

template<typename T , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readArrayCapped ( T &  dst,
long  dynCap,
ElemBound  elem = {},
Sizer  sizer = {} 
)
inlinenoexcept

Read a schema-**unbounded** count-prefixed array under the receiver's max_dyn_array_count (§6.2.1).

The counterpart of readArray for an array whose schema declares no count. Step 2 of the order above drops out and step 3 decides; the cap is the caller's, used for that one comparison and not retained.

Parameters
[out]dstDestination range (fixed extent or resizable).
dynCapThe caller's max_dyn_array_count. Required and non-negative; a negative value answers Error::InvalidArgument.
elemDeclared element range (ElemBound).
Returns
true when the array was read.

Definition at line 5741 of file sofab.hpp.

◆ readArrayGated()

template<typename T , typename Sizer >
bool sofab::IStreamImpl::readArrayGated ( T &  dst,
long  schemaCount,
long  dynCap,
ElemBound  elem,
Sizer  sizer 
)
inlineprotectednoexcept

The body both array reads share.

Exactly one of bound / dynCap is non-negative.

Not an entry point. It carries no check that a number was stated — that is the job of readString and readStringCapped, which is why this is not public: a (-1, -1) call is the fail-open shape §6.2.1 forbids, and there is deliberately no way to spell it.

Definition at line 5750 of file sofab.hpp.

◆ readBlob()

template<typename B , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readBlob ( B &  value,
long  bound,
Sizer  sizer = {} 
)
inlinenoexcept

Read the current field as a blob, or skip it (§7.3).

The Fix::Blob counterpart of readString; reads straight into the byte container, with no intermediate std::string. Takes a growable std::vector<uint8_t> or a heap-free FixedBytes, on the same FixedBytes::set_len test.

Refuses in the same three ways, in the same order, as readString — and takes its own §6.2.1 cap the same way. blob and string are separate limits, so the caller passes max_dyn_blob_len here.

Split into two entry points on the same terms as readString: this one takes the declared maxlen, readBlobCapped takes the receiver cap, and neither has a default.

Parameters
[out]valueDestination for the decoded bytes.
boundDeclared maxlen. Required and non-negative; a schema-unbounded field is read through readBlobCapped.
Returns
true when the value was read; false when the field was left for the decoder to skip.

Definition at line 5612 of file sofab.hpp.

◆ readBlobCapped()

template<typename B , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readBlobCapped ( B &  value,
long  dynCap,
Sizer  sizer = {} 
)
inlinenoexcept

Read the current field as a schema-**unbounded** blob under the receiver's max_dyn_blob_len (§6.2.1).

The blob counterpart of readStringCapped; see it for why the capped read is its own entry point. blob and string are separate limits, so the caller passes max_dyn_blob_len here.

Parameters
[out]valueDestination for the decoded bytes.
dynCapThe caller's max_dyn_blob_len. Required and non-negative; a negative value answers Error::InvalidArgument.
Returns
true when the value was read; false when the field was left for the decoder to skip.

Definition at line 5634 of file sofab.hpp.

◆ readBlobGated()

template<typename B , typename Sizer >
bool sofab::IStreamImpl::readBlobGated ( B &  value,
long  bound,
long  dynCap,
Sizer  sizer 
)
inlineprotectednoexcept

The body both blob reads share.

Exactly one of bound / dynCap is non-negative.

Not an entry point. It carries no check that a number was stated — that is the job of readString and readStringCapped, which is why this is not public: a (-1, -1) call is the fail-open shape §6.2.1 forbids, and there is deliberately no way to spell it.

Definition at line 5643 of file sofab.hpp.

◆ readIntElements()

template<bool Bounded, typename Elem >
bool sofab::IStreamImpl::readIntElements ( std::span< Elem >  sp,
ElemBound  b = {} 
)
inlineprotectednoexcept

Decode the current integer-array payload: count_ varint elements, the first sp.size() of them into sp.

The tag is already known to match (§7.3) and the cursor sits at the first element. On success the field is consumed_; on failure the stream's error_ / incomplete_ says which.

Template Parameters
BoundedApply b, the declared element type's value range (§7.1): an element outside it makes the decode INVALID — never masked down to Elem, never kept. false instantiates the plain decode, which is what read alone can do: it sees the destination's width, and a destination width is not a declared width. The two are separate instantiations, so an unbounded array carries no test for a bound it does not have.
Parameters
spDestination for the leading elements; the rest of count_ is still parsed, to stay framed.
bThe element range, when Bounded.

Definition at line 5018 of file sofab.hpp.

◆ readPayload()

template<typename D >
bool sofab::IStreamImpl::readPayload ( D &  value,
bool  validateUtf8 
)
inlineprotectednoexcept

Deliver the current fixlen payload into the destination the caller handed over (§6.6.3, second shape).

The one place a string / blob payload reaches a destination, so the §6.6 rule has one implementation and cannot hold in one read and be missing from another. In order:

  1. The destination's room (detail::destRoom) against the announced length. Too short is §6.3's third refusal tier — rejectDestination, InvalidArgument — because both bounds that can speak about the message have already spoken: the schema maxlen in the caller above, and any configured receiver cap. It is decided from the header alone, before a byte of payload is consulted, so where the chunk boundaries fall cannot change it.
  2. Availability. Fewer bytes than the declared length is INCOMPLETE, never an error (§5.2).
  3. UTF-8 (§6.4), for a string payload only, and never on skip (§6.4.5 — this function runs only where a value is materialized).
  4. The copy, then the length (sofab::detail::destSetLen). The destination is written exactly once, complete (§6.6.2).
Template Parameters
DDestination: sofab::FixedString / sofab::FixedBytes (static room) or a std::string / std::vector<uint8_t> the caller sized.
Parameters
valueDestination.
validateUtf8Whether the payload is a string (§6.4).
Returns
true when the payload was delivered and the field consumed.

Definition at line 3566 of file sofab.hpp.

◆ readPayloadPiece()

template<typename D >
bool sofab::IStreamImpl::readPayloadPiece ( D &  value,
bool  validateUtf8,
size_t  avail 
)
inlineprotectednoexcept

The chunk-straddling half of readPayload — deliver the piece that has arrived and remember how far the value got.

§6.6.2: "A payload split across fed chunks has to be joined somewhere. That somewhere is storage the caller supplied — the codec copies each piece into it as the piece arrives … A codec <strong>MUST NOT</strong> grow a private accumulator instead." So the piece goes straight where the value belongs and only the length is published, once, at the end — no caller ever sees a half-written value (§6.6.2's "written exactly once, complete").

Cold: it runs only for a field a chunk boundary fell inside.

Definition at line 3636 of file sofab.hpp.

◆ readString()

template<typename S , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readString ( S &  value,
long  bound,
Sizer  sizer = {} 
)
inlinenoexcept

Read the current field as a string, or skip it (§7.3).

fp32, fp64, string and blob all share Wire::Fixlen, so a plain read cannot tell which one the caller declared. This overload states it: the value is read only when the wire subtype is Fix::String, otherwise the field is left unconsumed — the decoder then skips it exactly like an unknown id, and skipped counts it.

The destination is either a growable one (std::string) or a heap-free FixedString, told apart by FixedString::set_len rather than by name, so a caller's own type works too. Both spell the call identically; only where the bytes land differs.

The three ways this refuses (§6.3), in the only correct order
  1. The wire subtype contradicts string → the field is skipped (§7.3), and neither bound below is applied to it: "a skipped field is never capped" (§6.2.1).
  2. bound is declared and the announced length exceeds it → InvalidMessage (MESSAGE_SPEC §7.1). The schema calls these bytes invalid.
  3. bound is negative — the schema declares none — and the announced length exceeds dynCap → Error::LimitExceeded (§6.2.1). The bytes are well-formed; this receiver declines to hold that much.

All three are decided at the length header, before the destination is sized (§6.2.1's enforcement point, §5.2.3): sofab::readString, the helper that sizes a growable destination, applies the identical gate before it grows anything.

Two entry points, so a number cannot be forgotten
This overload is the schema-bounded read and takes the declared maxlen only; readStringCapped is the schema-unbounded one and takes the §6.2.1 receiver cap only. Exactly one of the two numbers can ever apply — a receiver limit "**MUST NOT** be applied to a field the schema already bounds" — so the choice belongs in the call's name rather than in a pair of arguments where either may be left out. Neither has a default, and neither reads a negative value as "unlimited": a bound below zero is not a schema-unbounded read, it is a call that stated no bound at all, and it answers Error::InvalidArgument through rejectUnbounded.
The bound is passed in, never held
§6.2.1 leaves this corelib "the report and the category" and puts the numbers in generated code, so bound is the caller's, used for this one comparison and not retained. There is no stream-wide fallback of any kind. Passing the number here rather than testing it in front of the call is what keeps case 1 above true: the tag test is inside, so a field the decoder must skip never meets the ceiling.
Parameters
[out]valueDestination for the decoded text.
boundDeclared maxlen. Required and non-negative; a schema-unbounded field is read through readStringCapped instead.
Returns
true when the value was read; false when the field was left for the decoder to skip.

Definition at line 5520 of file sofab.hpp.

◆ readStringCapped()

template<typename S , typename Sizer = detail::NoSizer>
bool sofab::IStreamImpl::readStringCapped ( S &  value,
long  dynCap,
Sizer  sizer = {} 
)
inlinenoexcept

Read the current field as a schema-**unbounded** string under the receiver's max_dyn_string_len (§6.2.1).

The counterpart of readString for a field whose schema declares no maxlen. It refuses in the same order — tag (§7.3), then the cap (Error::LimitExceeded) — and the cap is the caller's, used for this one comparison and not retained.

It exists as its own entry point rather than as a defaulted argument because a defaulted one can be left out, and a schema-unbounded read with no cap is the sender choosing how much this process holds. There is nothing to default to: §6.2.1 forbids this codec a limit of its own.

Parameters
[out]valueDestination for the decoded text.
dynCapThe caller's max_dyn_string_len. Required and non-negative; a negative value is a call that stated no cap and answers Error::InvalidArgument.
Returns
true when the value was read; false when the field was left for the decoder to skip.

Definition at line 5548 of file sofab.hpp.

◆ readStringGated()

template<typename S , typename Sizer >
bool sofab::IStreamImpl::readStringGated ( S &  value,
long  bound,
long  dynCap,
Sizer  sizer 
)
inlineprotectednoexcept

The body both string reads share, so the two cannot answer differently.

Exactly one of bound / dynCap is non-negative.

Not an entry point. It carries no check that a number was stated — that is the job of readString and readStringCapped, which is why this is not public: a (-1, -1) call is the fail-open shape §6.2.1 forbids, and there is deliberately no way to spell it.

Definition at line 5565 of file sofab.hpp.

◆ reenterLevel()

bool sofab::IStreamImpl::reenterLevel ( FieldCb  cb,
Entry  entry 
)
inlineprotectednoexcept

Take the Entry::Descend or Entry::Resume path.

Definition at line 3985 of file sofab.hpp.

◆ rejectDestination()

void sofab::IStreamImpl::rejectDestination ( )
inlinenoexcept

Refuse the current field because the caller's destination is too short for it (§6.3's third refusal tier, §6.6.3).

The sibling of invalidate and exceedLimit, for the one refusal that is about neither the message nor the deployment: the value broke no schema bound and no configured cap, and simply does not fit the storage this caller handed over. §6.3: "<tt>InvalidMessage</tt> would mark a well-formed message malformed … <tt>LimitExceeded</tt> would promise a limit to raise that was never configured." The surrounding feed stops dispatching and returns Error::InvalidArgument. Idempotent; a no-op outside a feed since every feed clears the flag on entry.

Definition at line 4501 of file sofab.hpp.

◆ rejectElementIndex()

void sofab::IStreamImpl::rejectElementIndex ( sofab::id  bad)
inlinenoexcept

Refuse a wrapper-array element whose index is at or past a bound, in the category §6.3 gives that bound.

MESSAGE_SPEC §5.1 makes a wrapper array's length highest present id + 1, so the element index is the length and is what has to be checked — "A limit **MUST** be enforced … before the container it indexes into is extended" (§6.2.1). Three bounds can be armed at once and they do not share a verdict, so they are consulted in §6.3's order: the schema count first (InvalidMessage), then the configured receiver cap (LimitExceeded), then the destination's own capacity (InvalidArgument).

Parameters
badThe element index that crossed a bound.

Definition at line 4537 of file sofab.hpp.

◆ rejectUnbounded()

void sofab::IStreamImpl::rejectUnbounded ( )
inlinenoexcept

Refuse the current field because the call stated no bound for it at all (§6.3's InvalidArgument).

The one answer §6.2.1 leaves for a schema-unbounded field read with no receiver cap. This codec has no limit of its own to fall back on, and "an argument a caller may omit is an API affordance, never a licence to decode uncapped" — so the omission is reported rather than obeyed. It is a mistake in the call, exactly like a destination too short for the value (rejectDestination): the message is well-formed and the deployment configured nothing, so neither InvalidMessage nor LimitExceeded would say anything true about it (§6.3's three tiers).

Reaching it from generated code means a cap was not emitted; reaching it from a hand-written visitor means the wrong entry point was used — the …Capped forms exist so the number cannot be forgotten.

Definition at line 4520 of file sofab.hpp.

◆ reset()

virtual void sofab::IStreamImpl::reset ( )
inlinevirtualnoexcept

Drop every byte of decoder state, so the next feed starts a brand-new message.

Discards the buffered partial field, the sticky error/limit flags, the latched terminal verdict (§5.2/§6.3 — this is the only way to clear an INVALID or LimitExceeded stream), the nesting depth and the §7.3 skipped counter. There is no buffer to hand back: the decoder's working state is the fixed-size carry, path and progress it was constructed with (§6.6), so a reset is a handful of stores and the message loop pays no allocator for it.

It does not touch the destination — this class has none; it only dispatches. IStreamObject overrides this to reset the message it owns as well, which is what a caller reusing a decoder wants. A caller driving IStreamInline owns its destinations and must clear them itself.

Required between messages: MESSAGE_SPEC §2 omits an all-default field entirely, so an absent field delivers no callback and leaves the previous message's value in place — including a wrapper-array field, whose collector (StringSeq, BlobSeq, MessageSeq) only clears its destination when the wrapper sequence is actually present.

Reimplemented in sofab::IStreamObject< MessageType >.

Definition at line 4424 of file sofab.hpp.

◆ restorePending()

void sofab::IStreamImpl::restorePending ( )
inlineprotectednoexcept

Put the suspended field's header back before continuing it.

Definition at line 4041 of file sofab.hpp.

◆ resumed()

bool sofab::IStreamImpl::resumed ( ) const
inlinenoexcept

true when this delivery re-enters a sequence an earlier feed left open, rather than announcing a new field.

A nested sequence cut by a chunk boundary cannot be resumed from a byte offset — the handler chain that was inside it lives on the C++ stack, and a feed returning unwinds it. The decoder therefore replays the field ids of the open levels, so each handler is asked for the same member again and the chain is rebuilt exactly as it was. Nothing about the field is new: the id, the sequence and everything already decoded inside it are the ones the previous chunks produced.

A handler that only dispatches on the id — every generated deserialize, and any handler written the same way — needs this for nothing: reading the same member again is precisely right, and the codec continues where it stopped. It exists for a handler that keeps a position of its own rather than a schema, which must not advance it twice.

Distinct from progress, which is about the bytes of one field.

Definition at line 6036 of file sofab.hpp.

◆ roomFor()

template<typename D >
bool sofab::IStreamImpl::roomFor ( D &  value,
size_t  need 
)
inlineprotectednoexcept

Is there room for need bytes in the destination the caller handed over (§6.6.3)?

Two kinds of destination answer differently, and the difference is a fact the type publishes rather than a policy this read picks:

  • static room (D::capacity()) cannot change between chunks, so the refusal is decided from the header alone — before a byte of payload is consulted — and where the chunk boundaries fall cannot change it;
  • room the caller sized is judged against what this delivery can actually reach: the announced length, clamped to what has arrived. A declared length whose payload is absent or withheld reaches nothing and refuses nothing, so a truncated field stays INCOMPLETE (§5.2) instead of being mistaken for a destination that is too small; once the last piece is here the reach IS the announced length, and a destination genuinely too short is refused exactly then.
Returns
false with rejectDestination raised (InvalidArgument).

Definition at line 3612 of file sofab.hpp.

◆ schemaBoundsHeader()

static constexpr bool sofab::IStreamImpl::schemaBoundsHeader ( Wire  w)
inlinestaticconstexprprotectednoexcept

Does this wire type's header state a size the schema can bound?

True for the length-prefixed payload (maxlen) and the three array kinds (count) — exactly the fields whose §7.1 verdict outranks the field-size cap (#86), and exactly the ones exceedsBufferAtHeader derives a size from. A sequence states no size of its own (it accrues in dispatchLevel) and a varint carries no length word at all.

Parameters
wThe delivered field's wire type.
Returns
true when a declared maxlen/count could reject this field.

Definition at line 4966 of file sofab.hpp.

◆ skipPayload()

void sofab::IStreamImpl::skipPayload ( )
inlineprotectednoexcept

Step over the payload of the current field, resumably.

Called for a field the callback declined. Like every read, it never buffers what it has not finished: a payload cut by a chunk boundary leaves its byte (or element) progress in pendDone_ and is continued on the next feed, and a small item cut in half — a lone varint, an element — is backed up to its own start so the ≤ CARRY_CAP bytes of it can be carried (§6.6.2).

Assumes the cursor sits at the payload's resume point and the field metadata is set.

Definition at line 4150 of file sofab.hpp.

◆ skipped()

size_t sofab::IStreamImpl::skipped ( ) const
inlinenoexcept

Number of fields skipped this stream because their wire tag contradicted the type the callback asked for (MESSAGE_SPEC §7.3).

A diagnostic only — it never influences the decode outcome. A non-zero count on an otherwise COMPLETE message means the peer's schema and this one disagree about a field's type (or a hand-written callback asked for the wrong one).

Monotonic over the stream's lifetime — unlike the sticky error flags it is not cleared per feed, so a message dribbled in chunk by chunk still reports every skip it caused. Result::skipped carries the same value out of a one-shot decode.

Definition at line 5170 of file sofab.hpp.

◆ skipSequence()

void sofab::IStreamImpl::skipSequence ( )
inlineprotectednoexcept

Walk a sub-sequence nobody asked for, delivering nothing.

Split out of skipPayload because a skipped sequence, like every other construct, has to be re-enterable: when a chunk ends inside one the level is recorded in pathSkip_ and descendResume comes back through here, with no callback to replay.

§7.3: this sequence is not an element of the enclosing wrapper — and the fields INSIDE it are not that wrapper's elements either. Their ids are child ids of a field that never became a value, not array indices, so the element-index bound must not measure them: it is suspended for the whole subtree and restored after. Without this a child id at or past the wrapper's count would trip the §5.1/§7 reject from inside a field §7.3 says is not the array's at all (Crucible F-0051, corelib-cpp#65). The suspension is not specific to a §7.3-mistyped element: an unknown id skipped inside the wrapper reaches the same place and is equally not an element. Format-level rejects (§4.9 depth, over-64-bit varint, ...) still fire inside the subtree — §7.3 subordinates the SCHEMA bound only.

Definition at line 4249 of file sofab.hpp.

◆ skipVarint()

static bool sofab::IStreamImpl::skipVarint ( const uint8_t *&  p,
const uint8_t *  end,
bool *  overflow = nullptr 
)
inlinestaticprotectednoexcept

Advance the cursor past one varint without decoding it (bounds-checked).

Parameters
[in,out]pCursor; advanced past the varint on success.
endOne past the last readable byte.
Returns
true on success, false if the buffer ends mid-varint or it overflows 64 bits. As with getVarint, *overflow is set on a > 64-bit varint (§4.1), so an over-long varint is never mistaken for a truncated tail.

Definition at line 3409 of file sofab.hpp.

◆ skipVarintWindowed()

static bool sofab::IStreamImpl::skipVarintWindowed ( const uint8_t *&  p,
bool *  overflow 
)
inlinestaticprotectednoexcept

getVarintWindowed without building the value — see skipVarint.

Definition at line 3316 of file sofab.hpp.

◆ spanned()

size_t sofab::IStreamImpl::spanned ( ) const
inlineprotectednoexcept

The bytes of the current top-level field seen so far, across every chunk it spans (#26, Limits::max_buffered_field).

Pointer arithmetic alone stopped being enough once a field could span chunks without being buffered: within one window the span is p_ - spanBase_, and what earlier windows already consumed of the same field is carried in spanCarry_. Without that the cap would be a property of the caller's chunking, which §7.2 item 4 forbids.

Definition at line 4580 of file sofab.hpp.

◆ spannedLive()

size_t sofab::IStreamImpl::spannedLive ( ) const
inlineprotectednoexcept

spanned less what this field spent on skipped subtrees — the number the field-span cap is measured against (§6.2.1).

The cap bounds what the receiver materializes, and spanSkipped_ is exactly what it did not. Saturating rather than wrapping: the two counters are updated in different places, and a cap that ran backwards would be a cap that never fires.

Definition at line 4594 of file sofab.hpp.

◆ stash()

void sofab::IStreamImpl::stash ( const uint8_t *  p,
size_t  n 
)
inlineprotectednoexcept

Hold the ≤ CARRY_CAP bytes of a cut item until the next feed.

Definition at line 4619 of file sofab.hpp.

◆ suspendAtBoundary()

void sofab::IStreamImpl::suspendAtBoundary ( )
inlineprotectednoexcept

Claim the suspension for this level at a field boundary — nothing half-delivered, only a header cut in two or a sequence still open.

The ≤ CARRY_CAP bytes of the cut header ride in carry_ and are parsed again from their first byte; there is no pending field, so nothing is re-delivered.

Definition at line 4032 of file sofab.hpp.

◆ suspendHere()

void sofab::IStreamImpl::suspendHere ( sofab::id  fieldId,
bool  declined 
)
inlineprotectednoexcept

Record that this level's current field is the suspension point.

The innermost level claims suspendDepth_; every level above it then writes its own pathId_ entry as the stack unwinds, so the path is complete by the time feed sees the INCOMPLETE.

Parameters
fieldIdId of this level's field, for the pathId_ entry a level above the suspension records.
declinedWhether the field was being skipped rather than read.

Definition at line 4003 of file sofab.hpp.

◆ tagMatches() [1/3]

bool sofab::IStreamImpl::tagMatches ( Wire  wantWire)
inlineprotectednoexcept

The §7.3 seam: does the delivered field's wire tag match the one the caller's read declares?

A field's tag is its wire type plus, for the fixlen kinds, the subtype — the two are only meaningful together, since fp32, fp64, string and blob all share Wire::Fixlen. Every typed read compares the whole tag here, so half a comparison cannot be written.

On a mismatch the field is left unconsumed: the parser that delivered it — parseTopLevel at the top level, dispatchLevel inside a sequence — then skips it exactly like an unknown id, which is what MESSAGE_SPEC §7.3 requires — this is not an error, and never affects the decode outcome. The skip is counted in skipped_ as a diagnostic.

A read may admit more than one subtype — read(std::string&) takes a string or a blob, since both are fixlen payloads and a std::string is the documented destination for either. That is what the two-subtype overload is for: it is still one comparison of the whole tag, so a refusal counts exactly one skip, never one per candidate.

Parameters
wantWireWire type the read declares.
wantFixFixlen subtype it declares; ignored unless wantWire is a fixlen kind and the caller separates the subtypes.
Returns
true when the caller may consume the field.

Definition at line 3513 of file sofab.hpp.

◆ tagMatches() [2/3]

bool sofab::IStreamImpl::tagMatches ( Wire  wantWire,
Fix  wantFix 
)
inlineprotectednoexcept

Definition at line 3520 of file sofab.hpp.

◆ tagMatches() [3/3]

bool sofab::IStreamImpl::tagMatches ( Wire  wantWire,
Fix  wantFix,
Fix  wantFix2 
)
inlineprotectednoexcept

Parameters
wantFix2A second admissible fixlen subtype.

Definition at line 3529 of file sofab.hpp.

◆ wire()

Wire sofab::IStreamImpl::wire ( ) const
inlinenoexcept

Wire type of the field currently being delivered.

Valid inside a deliver callback. Introspection only: the typed reads compare the tag themselves and skip a contradicting field (§7.3), so a caller does not need this to be correct — it is here for diagnostics and for code that wants to branch on the delivered form. The type it returns lives in sofab::detail. Reads no bytes and does not consume the field.

Returns
The delivered field's Wire.

Definition at line 5962 of file sofab.hpp.

◆ wrapCb()

template<typename Cb >
static FieldCb sofab::IStreamImpl::wrapCb ( Cb &  cb)
inlinestaticprotectednoexcept

Wrap a level's callback as a FieldCb.

Definition at line 3747 of file sofab.hpp.

Member Data Documentation

◆ argError_

bool sofab::IStreamImpl::argError_ = false
protected

Category: a well-formed value did not fit the destination the caller handed over (§6.3's third refusal tier, §6.6.3).

Implies error_.

Lives for exactly one feed, like error_ and limitExceeded_, and is latched into terminal_ as Error::InvalidArgument by the feed that saw it.

Definition at line 3173 of file sofab.hpp.

◆ CAP_NEED_MAX

constexpr uint64_t sofab::IStreamImpl::CAP_NEED_MAX
staticconstexprprotected
Initial value:
=
static_cast<uint64_t>(ARRAY_MAX) * static_cast<uint64_t>(FIXLEN_MAX)
constexpr uint32_t FIXLEN_MAX
Largest fixlen payload byte-length (INT32_MAX).
Definition sofab.hpp:100
constexpr uint32_t ARRAY_MAX
Largest array element count (INT32_MAX).
Definition sofab.hpp:105

Upper bound of any header-declared need (§6.2 ceilings).

Definition at line 3670 of file sofab.hpp.

◆ capInert_

bool sofab::IStreamImpl::capInert_ = false
protected

Can the field-span cap provably not fire anywhere in the window being parsed (§6.2.1, #26)? Set once per parseWindow.

Every span the cap measures in one window is at most spanCarry_ plus the window's length, and every header-declared need is at most CAP_NEED_MAX (the §6.2 ceilings: ARRAY_MAX elements of at most FIXLEN_MAX bytes). When the stated budget covers both, exceedsBuffer would answer false for every field of the window, so asking it per field is work with a known answer. This is not an unlimited mode: the receiver's number is still the only input, and a budget that could be reached keeps the per-field check exactly as before.

Definition at line 3123 of file sofab.hpp.

◆ carry_

uint8_t sofab::IStreamImpl::carry_[CARRY_CAP]
protected

The prefix of one cut item, carried to the next feed.

This is what replaced the private reassembly accumulator §6.6.2 forbids: "A payload split across fed chunks has to be joined somewhere. That somewhere is storage the caller supplied — the codec copies each piece into it as the piece arrives … A codec <strong>MUST NOT</strong> grow a private accumulator instead." A fixed array of CARRY_CAP bytes cannot be grown, and a sender cannot make it larger by sending different bytes, which is §6.6's whole test.

Definition at line 3040 of file sofab.hpp.

◆ CARRY_CAP

constexpr size_t sofab::IStreamImpl::CARRY_CAP = 3 * detail::VARINT_MAX_BYTES
staticconstexprprotected

Widest prefix of a wire item that can outlive a chunk boundary, derived from this format's own constants (§6.6).

The parse never backs up over a payload — a string, a blob or an array element run is written into the caller's destination piece by piece as the pieces arrive (§6.6.2) — so what a chunk boundary can cut in half is only ever a small item: a field header, the words between it and its payload, a lone varint element, or a fixed-width scalar. The widest of those is an ARRAY_FIXLEN field's prefix: the header word, the element count and a fixlen_word, three varints of at most detail::VARINT_MAX_BYTES each.

That is what makes carry_ bounded working state in §6.6's sense rather than an accumulator: a constant of the specification caps it, no wire number can enlarge it, and it is sized when the decoder is constructed.

Definition at line 3027 of file sofab.hpp.

◆ carryLen_

size_t sofab::IStreamImpl::carryLen_ = 0
protected

Live bytes of carry_.

Definition at line 3041 of file sofab.hpp.

◆ consumed_

bool sofab::IStreamImpl::consumed_ = false
protected

Set once the callback has read the current field's value.

Definition at line 3150 of file sofab.hpp.

◆ count_

size_t sofab::IStreamImpl::count_ = 0
protected

Element count of the current array field.

Definition at line 3149 of file sofab.hpp.

◆ elemBound_

long sofab::IStreamImpl::elemBound_ = -1
protected

The tightest armed element-index bound of the wrapper sequence being read (§5.1); -1 = none.

A fast gate only — it answers "is any bound crossed?" in one compare. Which of §6.3's three tiers a crossing belongs to is decided by rejectElementIndex from the three bounds below, and only once a crossing has actually happened.

Definition at line 3205 of file sofab.hpp.

◆ elemDest_

long sofab::IStreamImpl::elemDest_ = -1
protected

The destination container's own capacity: InvalidArgument (§6.6.3).

Definition at line 3208 of file sofab.hpp.

◆ elemDyn_

long sofab::IStreamImpl::elemDyn_ = -1
protected

Configured max_dyn_array_count: LimitExceeded (§6.2.1).

Definition at line 3207 of file sofab.hpp.

◆ elemFix_

int sofab::IStreamImpl::elemFix_ = -1
protected

§7.3 fixlen subtype for that element type (a Fix as int); -1 = the element type has none.

Definition at line 3210 of file sofab.hpp.

◆ elemSchema_

long sofab::IStreamImpl::elemSchema_ = -1
protected

Schema count N: an id at or past it is InvalidMessage (§7.1).

Definition at line 3206 of file sofab.hpp.

◆ elemWire_

int sofab::IStreamImpl::elemWire_ = -1
protected

§7.3 wire type its elements must carry (a Wire as int); -1 = the collector decides the bound itself.

Definition at line 3209 of file sofab.hpp.

◆ end_

const uint8_t* sofab::IStreamImpl::end_ = nullptr
protected

One past the last readable byte.

Definition at line 3145 of file sofab.hpp.

◆ error_

bool sofab::IStreamImpl::error_ = false
protected

Sticky "this feed was refused" flag, and the only one the parse loops test.

Raised by every refusal, whichever of §6.3's three tiers it belongs to: invalidate raises it alone, exceedLimit and rejectDestination raise it alongside their own category flag. That keeps the per-field test in dispatchLevel and parseTopLevel a single load — the categories are read once, by feed, when the parse has already stopped.

Definition at line 3162 of file sofab.hpp.

◆ fieldId_

sofab::id sofab::IStreamImpl::fieldId_ = 0
protected

Id of the field being delivered.

Definition at line 3211 of file sofab.hpp.

◆ fixLen_

size_t sofab::IStreamImpl::fixLen_ = 0
protected

Payload length (fixlen) or element size (fixlen array), in bytes.

Definition at line 3148 of file sofab.hpp.

◆ fixType_

Fix sofab::IStreamImpl::fixType_ {}
protected

Sub-type of the current fixlen field.

Definition at line 3147 of file sofab.hpp.

◆ incomplete_

bool sofab::IStreamImpl::incomplete_ = false
protected

The field being delivered needs more bytes (§7 INCOMPLETE, not malformed).

Definition at line 3195 of file sofab.hpp.

◆ limitExceeded_

bool sofab::IStreamImpl::limitExceeded_ = false
protected

Category: a receiver-side limit was crossed (§6.2.1).

Implies error_.

Definition at line 3163 of file sofab.hpp.

◆ maxBufferedField_

size_t sofab::IStreamImpl::maxBufferedField_
protected

The receiver's byte budget for one top-level field (Limits::max_buffered_field), as this decode was told it.

Deliberately uninitialised here: there is no value this library may pick (§6.2.1), so the only way to reach it is through the constructor below, which every stream has to go through.

Definition at line 3221 of file sofab.hpp.

◆ p_

const uint8_t* sofab::IStreamImpl::p_ = nullptr
protected

Read cursor.

Definition at line 3144 of file sofab.hpp.

◆ pathId_

sofab::id sofab::IStreamImpl::pathId_[MAX_DEPTH+1]
protected

Id of the sequence field entered at each open level (§4.9).

A nested sequence cannot be resumed by remembering a byte offset: the handler chain that was descending into it lives on the C++ stack, which a feed returning unwinds. What survives is the path — one field id per open level — and replaying it re-enters exactly the handlers that were open, because each level's deserialize dispatches on the id. At most MAX_DEPTH ids, sized at construction (§6.6).

Definition at line 3065 of file sofab.hpp.

◆ pathSkip_

bool sofab::IStreamImpl::pathSkip_[MAX_DEPTH+1]
protected

That level was entered by skipPayload, not by a handler.

Definition at line 3067 of file sofab.hpp.

◆ pend_

bool sofab::IStreamImpl::pend_ = false
protected

A field at suspendDepth_ is half-delivered.

Definition at line 3069 of file sofab.hpp.

◆ pendCount_

size_t sofab::IStreamImpl::pendCount_ = 0
protected

That field's header, kept apart from the live type_ / fixLen_ / count_.

The live metadata belongs to whatever field the parser is looking at now, and re-descending pathId_ overwrites it with each sequence header it replays. The suspended field's own header therefore has to be kept separately and put back once its level is reached again — it is the header the read will be continued under, and re-parsing it is exactly what there are no bytes for.

Definition at line 3085 of file sofab.hpp.

◆ pendDone_

size_t sofab::IStreamImpl::pendDone_ = 0
protected

Progress through the pending field: payload bytes already written into the caller's destination, or array elements already decoded.

Definition at line 3092 of file sofab.hpp.

◆ pendFix_

Fix sofab::IStreamImpl::pendFix_ {}
protected

That field's header, kept apart from the live type_ / fixLen_ / count_.

The live metadata belongs to whatever field the parser is looking at now, and re-descending pathId_ overwrites it with each sequence header it replays. The suspended field's own header therefore has to be kept separately and put back once its level is reached again — it is the header the read will be continued under, and re-parsing it is exactly what there are no bytes for.

Definition at line 3083 of file sofab.hpp.

◆ pendId_

sofab::id sofab::IStreamImpl::pendId_ = 0
protected

That field's header, kept apart from the live type_ / fixLen_ / count_.

The live metadata belongs to whatever field the parser is looking at now, and re-descending pathId_ overwrites it with each sequence header it replays. The suspended field's own header therefore has to be kept separately and put back once its level is reached again — it is the header the read will be continued under, and re-parsing it is exactly what there are no bytes for.

Definition at line 3081 of file sofab.hpp.

◆ pendLen_

size_t sofab::IStreamImpl::pendLen_ = 0
protected

That field's header, kept apart from the live type_ / fixLen_ / count_.

The live metadata belongs to whatever field the parser is looking at now, and re-descending pathId_ overwrites it with each sequence header it replays. The suspended field's own header therefore has to be kept separately and put back once its level is reached again — it is the header the read will be continued under, and re-parsing it is exactly what there are no bytes for.

Definition at line 3084 of file sofab.hpp.

◆ pendSkip_

bool sofab::IStreamImpl::pendSkip_ = false
protected

...and it was declined, so skipPayload resumes it rather than the handler.

Definition at line 3087 of file sofab.hpp.

◆ pendType_

Wire sofab::IStreamImpl::pendType_ {}
protected

That field's header, kept apart from the live type_ / fixLen_ / count_.

The live metadata belongs to whatever field the parser is looking at now, and re-descending pathId_ overwrites it with each sequence header it replays. The suspended field's own header therefore has to be kept separately and put back once its level is reached again — it is the header the read will be continued under, and re-parsing it is exactly what there are no bytes for.

Definition at line 3082 of file sofab.hpp.

◆ replay_

bool sofab::IStreamImpl::replay_ = false
protected

Re-descending pathId_ to reach suspendDepth_.

Definition at line 3054 of file sofab.hpp.

◆ seqDepth_

int sofab::IStreamImpl::seqDepth_ = 0
protected

Current nested-sequence depth during dispatch (§4.9 MAX_DEPTH).

Definition at line 3193 of file sofab.hpp.

◆ skipped_

size_t sofab::IStreamImpl::skipped_ = 0
protected

§7.3 type-mismatch skips seen so far (skipped).

Definition at line 3194 of file sofab.hpp.

◆ spanBase_

const uint8_t* sofab::IStreamImpl::spanBase_ = nullptr
protected

Where that field's span continues in the window being parsed (#26).

Definition at line 3098 of file sofab.hpp.

◆ spanCarry_

size_t sofab::IStreamImpl::spanCarry_ = 0
protected

Bytes of the current top-level field consumed in earlier chunks (#26).

Definition at line 3096 of file sofab.hpp.

◆ spanSkip_

bool sofab::IStreamImpl::spanSkip_ = false
protected

Is the parse currently inside a skipped sequence subtree (§6.2.1, #129)?

The accruing arm of the field-span cap (beginField) is off while it is set. A skipped subtree is walked, never materialized, so no receiver limit governs it — the same reason skipSequence suspends the element-index bound, and set and restored in the same place, for the same subtree.

Definition at line 3109 of file sofab.hpp.

◆ spanSkipped_

size_t sofab::IStreamImpl::spanSkipped_ = 0
protected

Bytes of the current top-level field spent on SKIPPED subtrees (§6.2.1, #129 one level down).

spanned counts the field's raw byte span, which is what the accruing arm of the field-span cap used to measure. Inside a sequence this receiver DOES read, that span also contains every child it does NOT — an unknown id, or one §7.3 declines — and those bytes are walked, never materialized. §6.2.1: "a field the handler skips allocates nothing", so "a decode that steps over an over-cap field it was never going to read stays COMPLETE". spanSkip_ suppresses the check inside such a subtree; this discounts what the subtree cost, so the live field AFTER it — the sequence end included — is measured against the bulk this receiver actually took on and not against the sender's padding. Reset with spanCarry_, and carried across chunks for the same reason it is.

Definition at line 3141 of file sofab.hpp.

◆ suspendDepth_

int sofab::IStreamImpl::suspendDepth_ = -1
protected

Depth at which the parse is suspended, or -1 when nothing is.

The decoder resumes rather than re-parses, so a field that straddles a chunk boundary is never delivered from the beginning again. Three pieces of fixed-size state describe where it stopped: this depth, pathId_ / pathSkip_ for the sequences that are open above it, and pend_ / pendDone_ for the field itself.

Definition at line 3052 of file sofab.hpp.

◆ terminal_

Error sofab::IStreamImpl::terminal_ = Error::None
protected

The stream's latched terminal verdict, or Error::None while the stream is still usable (§5.2, §6.3).

error_, limitExceeded_ and argError_ live for exactly one feed; this outlives it. INVALID is terminal — §5.2 answers "can more bytes change it?" with "no — terminal" — and LimitExceeded is "a terminal, receiver-local policy rejection" (§6.3). InvalidArgument (§6.3's third tier) is terminal for the same reason the other two are: the field was refused rather than consumed, and letting a later chunk "recover" it would make the verdict depend on where the chunk boundaries fell. So once any of the three is the answer it stays the answer for every later feed, until reset starts a new message. Without the latch the verdict would depend on where the chunk boundaries fell: the offending bytes are consumed and gone, so the next call would start from a clean slate and resynchronize on whatever follows the fault — exactly the divergence §7.2 item 4 forbids.

Definition at line 3192 of file sofab.hpp.

◆ topCallback_

std::function<void(sofab::id, size_t, size_t)> sofab::IStreamImpl::topCallback_
protected

Delivers each top-level field.

Definition at line 3223 of file sofab.hpp.

◆ type_

Wire sofab::IStreamImpl::type_ {}
protected

Wire type of the field being delivered.

Definition at line 3146 of file sofab.hpp.

◆ utf8State_

uint32_t sofab::IStreamImpl::utf8State_ = 0
protected

Incremental UTF-8 DFA state for the string payload in progress (§6.4.4).

Definition at line 3094 of file sofab.hpp.


The documentation for this class was generated from the following file: