SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
sofab::IStreamImpl Class Reference

Base input stream: incrementally decodes fed bytes into bound targets. More...

#include <sofab.hpp>

Inheritance diagram for sofab::IStreamImpl:
[legend]
Collaboration diagram for sofab::IStreamImpl:
[legend]

Data Structures

class  Result
 Outcome of a feed call. More...
 

Public Member Functions

 IStreamImpl (const IStreamImpl &)=delete
 Copy construction is deleted (the context owns raw pointers).
 
IStreamImpl & operator= (const IStreamImpl &)=delete
 Copy assignment is deleted (the context owns raw pointers).
 
 IStreamImpl (IStreamImpl &&) noexcept=default
 Move construction (transfers the underlying context).
 
IStreamImpl & operator= (IStreamImpl &&) noexcept=default
 Move assignment (transfers the underlying context).
 
Result feed (const uint8_t *buffer, size_t buflen) noexcept
 Feed raw encoded bytes to the decoder.
 
void invalidate () noexcept
 Reject the message in progress as malformed, from within a field callback (§6.3's first tier).
 
void exceedLimit () noexcept
 Reject the message because a configured receiver limit was exceeded (§6.3's second tier, §6.2.1).
 
void refuseArgument () noexcept
 Reject the message because the destination this caller handed over cannot hold the value (§6.3's third tier, §6.6.3).
 
bool refuse (size_t n, long room) noexcept
 Refuse an announced length or element count the caller's own destination cannot hold.
 
bool refuseSchema (size_t n, long schemaBound) noexcept
 §6.3's first tier: the bound the schema declares.
 
bool refuseCap (size_t n, size_t dynCap) noexcept
 §6.3's second tier: the receiver cap on a schema-unbounded field (§6.2.1).
 
bool refuseUnbounded (long schemaBound, long room) noexcept
 Refuse a read that was given no ceiling of any kind.
 
bool refuseBound (size_t n, long schemaBound, DynCap dynCap) noexcept
 The two message-side refusals of §6.3 in one call, in the order §6.2.1 fixes: the schema first, the receiver cap only where the schema declared nothing — and a diagnosis where neither was stated.
 
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.
 
bool delivered (Wire w) const noexcept
 Whether the field currently being delivered has wire type w.
 
bool delivered (Wire w, Fix f) const noexcept
 Whether the field currently being delivered has wire type w and fixlen subtype f.
 
template<typename T >
bool readMatch (T &value) noexcept
 read for a scalar, reporting whether the field will be decoded into value.
 
template<typename T >
void read (T &value) noexcept
 Bind the current field to a typed destination, deducing the wire type from T.
 
size_t read (void *dst, size_t maxlen) noexcept
 Decode a blob field into a caller-owned, address-stable buffer.
 
template<typename T >
void readString (T &value, size_t size, long maxlen=-1) noexcept
 Bind a string field, sizing the destination first.
 
template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void readString (Select &&select, size_t size, long maxlen=-1) noexcept
 readString into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and the two refusals, and returns the destination.
 
template<typename T >
void readStringCapped (T &value, size_t size, size_t dynCap) noexcept
 readString for a schema-unbounded string, bounded by the receiver cap the caller supplies (§6.2.1).
 
template<typename T >
void readBlob (T &value, size_t size, long maxlen=-1) noexcept
 Bind a blob field, sizing the destination first.
 
template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void readBlob (Select &&select, size_t size, long maxlen=-1) noexcept
 readBlob into a destination that comes into existence only once the field matched – the blob counterpart of the selecting readString overload, for a tagged union's blob option.
 
template<typename T >
void readBlobCapped (T &value, size_t size, size_t dynCap) noexcept
 readBlob for a schema-unbounded blob, bounded by the receiver cap the caller supplies (§6.2.1).
 
template<typename C >
void readArray (C &out, size_t wireCount=0, long cap=-1) noexcept
 Bind a native scalar array, preparing the destination first.
 
template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void readArray (Select &&select, size_t wireCount=0, long cap=-1) noexcept
 readArray into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and returns the destination – the array counterpart of the selecting readString overload, for a tagged union's array option.
 
template<typename C >
void readArrayCapped (C &out, size_t wireCount, size_t dynCap) noexcept
 readArray for a schema-unbounded array, bounded by the receiver cap the caller supplies (§6.2.1).
 
template<typename C , typename Out >
void readSequence (C &collector, Out &out) noexcept
 Bind a wrapper-array field through a collector, clearing the destination first.
 
template<typename C , typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void readSequence (C &collector, Select &&select) noexcept
 readSequence into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and returns the destination – for a tagged union's wrapper-array option.
 

Protected Member Functions

 IStreamImpl () noexcept=default
 
void latchRefusal_ (sofab_ret_t category) noexcept
 
void resetRefusal_ () noexcept
 Clear a latched refusal, for a subclass that re-initialises the stream itself.
 
void noteSkip_ () noexcept
 
bool bindMatch_ (void *var, size_t len, uint8_t opt) noexcept
 
template<typename T >
void bindString_ (T &value, size_t size) noexcept
 
template<typename T >
void bindBlob_ (T &value, size_t size) noexcept
 
template<typename C >
bool arrayTagOk_ () noexcept
 
template<typename C >
void bindArray_ (C &out, size_t wireCount, long room) noexcept
 

Static Protected Member Functions

template<typename C >
static long arrayRoom_ (C &out, size_t wireCount) noexcept
 

Protected Attributes

sofab_istream_t ctx_
 Underlying C input stream context.
 
sofab_istream_decoder_t arrayDecoder_
 
uint8_t refusal_ = SOFAB_RET_OK
 

Detailed Description

Base input stream: incrementally decodes fed bytes into bound targets.

Thin C++ facade over sofab_istream_t. Bytes are supplied via feed; inside a field callback (or a message's deserialize) the matching read() overload binds the destination for the current field. Decoding is lazy — a bound target is filled by subsequent feed calls, so targets must stay alive and address-stable until decoding completes.

Definition at line 2056 of file sofab.hpp.

Constructor & Destructor Documentation

◆ IStreamImpl() [1/3]

sofab::IStreamImpl::IStreamImpl ( )
protecteddefaultnoexcept

◆ IStreamImpl() [2/3]

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

Copy construction is deleted (the context owns raw pointers).

◆ IStreamImpl() [3/3]

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

Move construction (transfers the underlying context).

Member Function Documentation

◆ arrayRoom_()

template<typename C >
static long sofab::IStreamImpl::arrayRoom_ ( C &  out,
size_t  wireCount 
)
inlinestaticprotectednoexcept

Definition at line 2254 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ arrayTagOk_()

template<typename C >
bool sofab::IStreamImpl::arrayTagOk_ ( )
inlineprotectednoexcept

Definition at line 2227 of file sofab.hpp.

Here is the call graph for this function:

◆ bindArray_()

template<typename C >
void sofab::IStreamImpl::bindArray_ ( C &  out,
size_t  wireCount,
long  room 
)
inlineprotectednoexcept

Definition at line 2271 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindBlob_()

template<typename T >
void sofab::IStreamImpl::bindBlob_ ( T &  value,
size_t  size 
)
inlineprotectednoexcept

Definition at line 2202 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindMatch_()

bool sofab::IStreamImpl::bindMatch_ ( void *  var,
size_t  len,
uint8_t  opt 
)
inlineprotectednoexcept

Definition at line 2156 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindString_()

template<typename T >
void sofab::IStreamImpl::bindString_ ( T &  value,
size_t  size 
)
inlineprotectednoexcept

Definition at line 2178 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delivered() [1/2]

bool sofab::IStreamImpl::delivered ( Wire  w) const
inlinenoexcept

Whether the field currently being delivered has wire type w.

The §7.3 tag test for a field whose type has no fixlen subtype (varint, integer array, sequence) as ONE comparison. Valid, like wire, only before read binds a destination. A Wire::Fixlen / Wire::ArrayFixlen field is tested with the two-argument form: its subtype is part of the test, and this form would read it as Fix::Fp32 (subtype 0).

Definition at line 2684 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delivered() [2/2]

bool sofab::IStreamImpl::delivered ( Wire  w,
Fix  f 
) const
inlinenoexcept

Whether the field currently being delivered has wire type w and fixlen subtype f.

wire() == w && fixType() == f as ONE comparison: the type and the subtype share one byte of the stream state, bits 0-2 and 3-5. Valid, like wire, only before read binds a destination.

Definition at line 2697 of file sofab.hpp.

Here is the call graph for this function:

◆ exceedLimit()

void sofab::IStreamImpl::exceedLimit ( )
inlinenoexcept

Reject the message because a configured receiver limit was exceeded (§6.3's second tier, §6.2.1).

For a schema-unbounded field only: the bytes are well-formed and the same message decodes on a receiver configured more loosely, so this reports Error::LimitExceeded and never Error::InvalidMessage. Terminal, like invalidate.

readStringCapped, readBlobCapped, readArrayCapped and the growable wrapper-array collectors call it for you, at the length/count header and before the destination is sized. Call it directly when a callback enforces a limit those cannot see.

Definition at line 2453 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ feed()

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

Feed raw encoded bytes to the decoder.

May be called repeatedly with arbitrary chunk boundaries; field callbacks fire as complete field headers are parsed.

The outcome is three-valued (no separate finalize step): the returned Result is ok() when the consumed bytes end on a field boundary (a complete message), Result::incomplete() when they end mid-field or with an open sequence (a valid but partial decode — feed more bytes to continue), and carries Error::InvalidMessage when malformed.

A callback may end the decode itself — invalidate, exceedLimit or refuseArgument — and the category it chose is what this reports, in place of the core's plain Error::InvalidMessage. All three are terminal: every later feed repeats the same answer until the stream is re-initialized.

Parameters
bufferPointer to the bytes to decode.
buflenNumber of bytes at buffer.
Returns
Result: complete (ok), incomplete, or a decode error.

Definition at line 2410 of file sofab.hpp.

Here is the call graph for this function:

◆ fixType()

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

Fixlen sub-type of the field currently being delivered.

Only meaningful when wire is Wire::Fixlen or Wire::ArrayFixlen; §7.3 bounds the type check at wire type plus this subtype, since fp32 / fp64 / string / blob share the fixlen wire type. Valid inside a field callback / deserialize before read; reads no bytes and does not consume the field.

Returns
The delivered field's Fix.

Definition at line 2667 of file sofab.hpp.

Here is the caller graph for this function:

◆ invalidate()

void sofab::IStreamImpl::invalidate ( )
inlinenoexcept

Reject the message in progress as malformed, from within a field callback (§6.3's first tier).

The bytes broke a bound the schema declares — a maxlen, a count, an element index at or beyond a fixed-count array's capacity — which is a statement about the message's validity (MESSAGE_SPEC §7.1), so it is INVALID. Sticky: this feed and every subsequent one report Error::InvalidMessage until the stream is re-initialized.

Not for a receiver limit (exceedLimit) and not for a destination that is merely too small (refuseArgument): §6.2.1 forbids folding either into the INVALID outcome.

Definition at line 2434 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ latchRefusal_()

void sofab::IStreamImpl::latchRefusal_ ( sofab_ret_t  category)
inlineprotectednoexcept

Definition at line 2099 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ noteSkip_()

void sofab::IStreamImpl::noteSkip_ ( )
inlineprotectednoexcept

Definition at line 2133 of file sofab.hpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

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

Copy assignment is deleted (the context owns raw pointers).

◆ operator=() [2/2]

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

Move assignment (transfers the underlying context).

◆ read() [1/2]

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

Bind the current field to a typed destination, deducing the wire type from T.

Call from within a field callback / deserialize for the active field. Supports integers, bool, float, double, std::string (pre-sized to the field length), fixed contiguous ranges (arrays/vectors/spans), and nested IStreamMessage objects. The destination must outlive decoding (filled by later feed calls).

Parameters
valueDestination to decode into.

Definition at line 2778 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read() [2/2]

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

Decode a blob field into a caller-owned, address-stable buffer.

The templated read() above routes std::string to a STRING-tagged read and a std::vector<uint8_t> span to a VARINTARRAY-tagged read; neither matches a BLOB field, so the C type check rejects them and the bytes are dropped. This overload binds with the BLOB tag (via read_blob) so blob fields decode correctly. The caller must size the destination to the field length (provided as size in the field callback); the bytes are filled by a subsequent feed() pass into this buffer, which must stay alive and unmoved until decoding of the field completes.

Parameters
dstDestination buffer of at least maxlen bytes.
maxlenField length to read (a zero length is a no-op).
Returns
Number of bytes bound to be read (maxlen, or 0 if maxlen is 0).

Definition at line 2970 of file sofab.hpp.

Here is the call graph for this function:

◆ readArray() [1/2]

template<typename C >
void sofab::IStreamImpl::readArray ( C &  out,
size_t  wireCount = 0,
long  cap = -1 
)
inlinenoexcept

Bind a native scalar array, preparing the destination first.

Like readString, this exists because the destination is touched before it is bound — an inline std::array is reset so elements the encoder trimmed off the tail decode as the element default rather than as a schema default (MESSAGE_SPEC §3), and a std::vector is sized to the wire count. Both must wait until the delivered field is known to be an array of this element type (§7.3), and the count must be checked against the schema bound before a resize, so an over-count message cannot make the receiver allocate what the bound exists to prevent.

The refusals of readString apply unchanged, counting elements instead of bytes, and so does the split into two entry points: this one takes the schema count, readArrayCapped takes SOFAB_MAX_DYN_ARRAY_COUNT. Tier 3 matters more here than it does for a string: a heap-free destination's resize clamps, so without the check an over-capacity count would decode as a silently short array rather than as a refusal.

Parameters
outDestination array or vector.
wireCountElement count delivered to the field callback.
capSchema count, or -1 when the schema declares none — in which case out must publish a capacity.

Definition at line 3266 of file sofab.hpp.

Here is the call graph for this function:

◆ readArray() [2/2]

template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void sofab::IStreamImpl::readArray ( Select &&  select,
size_t  wireCount = 0,
long  cap = -1 
)
inlinenoexcept

readArray into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and returns the destination – the array counterpart of the selecting readString overload, for a tagged union's array option.

Where the destination type fixes its room (a heap-free container, or one that resizes), select is also called only behind the count refusals, as in the selecting readString. A fixed-size view publishes its room per object and is selected before them; a refusal is terminal either way.

Parameters
selectCallable returning the destination array by reference.
wireCountElement count delivered to the field callback.
capSchema count, or -1 when the schema declares none.

Definition at line 3303 of file sofab.hpp.

Here is the call graph for this function:

◆ readArrayCapped()

template<typename C >
void sofab::IStreamImpl::readArrayCapped ( C &  out,
size_t  wireCount,
size_t  dynCap 
)
inlinenoexcept

readArray for a schema-unbounded array, bounded by the receiver cap the caller supplies (§6.2.1).

The array counterpart of readStringCapped: dynCap is required and unsigned, it is compared against the wire count at the count header — behind the §7.3 tag test, before anything is sized from it — and a breach is Error::LimitExceeded.

Parameters
outDestination array or vector.
wireCountElement count delivered to the field callback.
dynCapThe §6.2.1 receiver cap on the element count.

Definition at line 3359 of file sofab.hpp.

Here is the call graph for this function:

◆ readBlob() [1/2]

template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void sofab::IStreamImpl::readBlob ( Select &&  select,
size_t  size,
long  maxlen = -1 
)
inlinenoexcept

readBlob into a destination that comes into existence only once the field matched – the blob counterpart of the selecting readString overload, for a tagged union's blob option.

Parameters
selectCallable returning the destination buffer by reference.
sizeField length, as delivered to the field callback.
maxlenSchema maxlen, or -1 when the schema declares none.

Definition at line 3194 of file sofab.hpp.

Here is the call graph for this function:

◆ readBlob() [2/2]

template<typename T >
void sofab::IStreamImpl::readBlob ( T &  value,
size_t  size,
long  maxlen = -1 
)
inlinenoexcept

Bind a blob field, sizing the destination first.

The blob counterpart of readString, and for the same reason: the destination must be sized before it is bound, so the delivered type is checked before value is touched (MESSAGE_SPEC §7.3).

The refusals of readString apply unchanged, and so does the split into two entry points: this one takes the schema maxlen, readBlobCapped takes SOFAB_MAX_DYN_BLOB_LEN. blob and string are separate limits in §6.2.1 because a deployment may well accept a megabyte of opaque bytes and no such quantity of text.

Parameters
valueDestination byte buffer (FixedBytes or std::vector<uint8_t>).
sizeField length, as delivered to the field callback.
maxlenSchema maxlen, or -1 when the schema declares none — in which case value must publish a capacity.

Definition at line 3167 of file sofab.hpp.

Here is the call graph for this function:

◆ readBlobCapped()

template<typename T >
void sofab::IStreamImpl::readBlobCapped ( T &  value,
size_t  size,
size_t  dynCap 
)
inlinenoexcept

readBlob for a schema-unbounded blob, bounded by the receiver cap the caller supplies (§6.2.1).

The blob counterpart of readStringCapped, with the same required, unsigned dynCap and the same ordering guarantees.

Parameters
valueDestination byte buffer.
sizeField length, as delivered to the field callback.
dynCapThe §6.2.1 receiver cap. A maximum, not an exclusive bound.

Definition at line 3224 of file sofab.hpp.

Here is the call graph for this function:

◆ readMatch()

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

read for a scalar, reporting whether the field will be decoded into value.

Binds exactly as read does and returns the §7.3 tag test the stream applies to that bind once the callback returns: on false the field is skipped and value is never written. The value itself arrives after the callback returns, so the caller may act on the result – a tagged union selects the option here – before it is written. Integers, bool, float and double; must be the first read of the field.

Parameters
valueDestination to decode into.
Returns
true when the delivered field has the type T maps to.

Definition at line 2719 of file sofab.hpp.

Here is the call graph for this function:

◆ readSequence() [1/2]

template<typename C , typename Out >
void sofab::IStreamImpl::readSequence ( C &  collector,
Out &  out 
)
inlinenoexcept

Bind a wrapper-array field through a collector, clearing the destination first.

A wrapper array arrives as a sequence whose element index is the field id (MESSAGE_SPEC §5.1); collector turns those elements into entries of out. The destination is emptied first — a wrapper array replaces rather than merges (§7.4) — and that, again, is a change that must not happen for a field which turns out not to be a sequence at all.

Parameters
collectorCollector for the element type (e.g. FixedStringSeq).
outDestination container; must outlive decoding.

Definition at line 3389 of file sofab.hpp.

Here is the call graph for this function:

◆ readSequence() [2/2]

template<typename C , typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void sofab::IStreamImpl::readSequence ( C &  collector,
Select &&  select 
)
inlinenoexcept

readSequence into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and returns the destination – for a tagged union's wrapper-array option.

Parameters
collectorCollector for the element type (e.g. FixedStringSeq).
selectCallable returning the destination container by reference; it must outlive decoding.

Definition at line 3414 of file sofab.hpp.

Here is the call graph for this function:

◆ readString() [1/2]

template<typename Select , std::enable_if_t< std::is_invocable_v< Select & >, int > = 0>
void sofab::IStreamImpl::readString ( Select &&  select,
size_t  size,
long  maxlen = -1 
)
inlinenoexcept

readString into a destination that comes into existence only once the field matched: select is called behind the §7.3 test and the two refusals, and returns the destination.

For a tagged union's string option. Selecting the option – ending the held one and constructing this one's storage – is a change a skipped or refused field must not make, so it cannot happen before the call; and spelling the test in front of the call makes it twice, since the construction in between is a store the compiler cannot prove leaves the stream's state alone. Here the test is made once:

is.readString([this]() -> auto & { return mutable_s(); }, _size, 8);
bool bitsEqual(const T *a, std::size_t na, const T *b, std::size_t nb) noexcept
True iff both float arrays have the same length and the same bit pattern at every index.
Definition floats.hpp:58
Parameters
selectCallable returning the destination string by reference.
sizeField length, as delivered to the field callback.
maxlenSchema maxlen, or -1 when the schema declares none.

Definition at line 3084 of file sofab.hpp.

Here is the call graph for this function:

◆ readString() [2/2]

template<typename T >
void sofab::IStreamImpl::readString ( T &  value,
size_t  size,
long  maxlen = -1 
)
inlinenoexcept

Bind a string field, sizing the destination first.

A string destination has to be given its logical length before the read binds it, and that is a change to the destination — so unlike a scalar read it cannot be issued unconditionally and left to the decoder to unbind. This checks the delivered type first (MESSAGE_SPEC §7.3) and touches value only if the field really is a string: a contradicting field leaves the destination exactly as it was and is skipped like an unknown id.

Accepts both storage shapes: a FixedString (inline, set_len) and a std::string (resize), so the same call works in the no-heap and the dynamic profile.

The four ways a read refuses (§6.3)
All of them are decided on the length header, after the §7.3 type check and before value is sized — and they are four different answers, not one:
  1. maxlen is declared and the field is longer → Error::InvalidMessage. The schema says these bytes are invalid (MESSAGE_SPEC §7.1).
  2. the schema declares no bound and the field is longer than the receiver cap → Error::LimitExceeded. The bytes are well-formed; this receiver declines to hold that much (§6.2.1). That is readStringCapped's answer, and only its: a cap must never be applied to a field the schema already bounds.
  3. Both admit the field, but value is a FixedString too small for it → Error::InvalidArgument (§6.6.3). Nothing is wrong with the message or with the deployment; the storage this caller offered is too short, and it is refused rather than filled part-way.
  4. No ceiling was stated at all — no maxlen, no cap, and a growable value → Error::InvalidArgument (§6.2.1, refuseUnbounded). The message and the deployment are again blameless; what is missing is part of the call. A std::string destination never reaches 3: it can hold whatever 1 and 2 let through. A FixedString never reaches 4: its capacity is a ceiling of its own.
This is the schema-bounded entry point
§6.2.1 gives the receiver caps to generated code and leaves this corelib "the report and the category", so there is no limit on the stream to fall back on — and, since the clause also forbids reading an omitted argument as unlimited, there is no dynCap = -1 here to omit. A field the schema leaves unbounded goes through readStringCapped instead, which takes the cap and cannot be called without one. The two are never both in play: §6.2.1 forbids a receiver cap on a field the schema already bounds.

A read given neither ceiling — no maxlen, and a growable value that publishes no capacity — is refused as Error::InvalidArgument (refuseUnbounded), not decoded. A heap-free value needs no maxlen: its capacity is a ceiling of its own.

This is what generated code emits for the embedded profile, where every string carries a maxlen:

is.readString(name, _size, 32);
Parameters
valueDestination string.
sizeField length, as delivered to the field callback.
maxlenSchema maxlen, or -1 when the schema declares none — in which case value must publish a capacity.

Definition at line 3047 of file sofab.hpp.

Here is the call graph for this function:

◆ readStringCapped()

template<typename T >
void sofab::IStreamImpl::readStringCapped ( T &  value,
size_t  size,
size_t  dynCap 
)
inlinenoexcept

readString for a schema-unbounded string, bounded by the receiver cap the caller supplies (§6.2.1).

The separate entry point is the point. dynCap is required and unsigned, so "no cap" has no spelling: §6.2.1's "no unset state and no unlimited mode" becomes a property of the signature rather than a rule every caller has to remember. A breach is Error::LimitExceeded — a policy rejection of well-formed bytes, never Error::InvalidMessage and never a truncating read.

The cap is applied at the length header, after the MESSAGE_SPEC §7.3 tag test and before value is sized. Both halves matter: checking in front of the call would cap a field this read is required to skip, which §6.2.1 forbids in as many words, and checking after the resize would be the allocation the cap exists to prevent.

dynCap is used for this one comparison and not retained — the number is the caller's, and this corelib neither defaults it nor remembers it.

is.readStringCapped(name, _size, SOFAB_MAX_DYN_STRING_LEN);
Parameters
valueDestination string.
sizeField length, as delivered to the field callback.
dynCapThe §6.2.1 receiver cap. A maximum, not an exclusive bound.

Definition at line 3131 of file sofab.hpp.

Here is the call graph for this function:

◆ refuse()

bool sofab::IStreamImpl::refuse ( size_t  n,
long  room 
)
inlinenoexcept

Refuse an announced length or element count the caller's own destination cannot hold.

This is the only bound the codec judges. CORELIB_PLAN §6.2.1 gives the receiver caps to generated code — "the visitor decides. The codec never invents a limit of its own and never clamps to one" — and MESSAGE_SPEC §7 gives it the schema bounds, because "the corelib cannot know the schema". Both are measured by the handler, at the size / count this corelib reports to it in the field callback, before it binds a destination at all.

What is left here is not a limit but the caller's storage: §6.6.3 requires "the codec refusing a destination too short rather than growing it. That refusal is **<tt>InvalidArgument</tt>**: the message is well-formed and within every bound it declares — what does not fit is the storage this caller offered."

Called before the destination is written, and terminal. Rejected, never clamped — a short write with a COMPLETE verdict is the data corruption §6.2.1 calls "a safety jacket".

Parameters
nThe announced length in bytes, or element count.
roomWhat the destination can actually hold, or -1 for a growable one, which this corelib never bounds.
Returns
true when the value was refused, in which case the caller must return without touching the destination.

Definition at line 2503 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refuseArgument()

void sofab::IStreamImpl::refuseArgument ( )
inlinenoexcept

Reject the message because the destination this caller handed over cannot hold the value (§6.3's third tier, §6.6.3).

Neither bound that speaks about the message has anything left to object to — the schema admits the value and so does the configured limit — and what does not fit is the storage. That is a mistake in the call, so it is Error::InvalidArgument. Error::InvalidMessage would mark a well-formed message malformed, and Error::LimitExceeded would promise a limit to raise that was never configured. Terminal, like invalidate.

Definition at line 2470 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refuseBound()

bool sofab::IStreamImpl::refuseBound ( size_t  n,
long  schemaBound,
DynCap  dynCap 
)
inlinenoexcept

The two message-side refusals of §6.3 in one call, in the order §6.2.1 fixes: the schema first, the receiver cap only where the schema declared nothing — and a diagnosis where neither was stated.

refuse is the third tier and answers a different question — that one is about the caller's storage, these two are about the message.

This is the collectors' entry point (seqRefuse). A growable wrapper array has no capacity to fall back on, so "the schema declared nothing and no cap was stated" is not a decode without a ceiling: it is Error::InvalidArgument, exactly as in refuseUnbounded.

Parameters
nThe announced length in bytes, or element index + 1.
schemaBoundSchema maxlen/count, or -1 when the schema declares none — which is what arms dynCap.
dynCapThe §6.2.1 receiver cap for a schema-unbounded field. An unstated one is refused, never read as unlimited.
Returns
true when the value was refused, in which case the caller must return without touching the destination.

Definition at line 2623 of file sofab.hpp.

Here is the call graph for this function:

◆ refuseCap()

bool sofab::IStreamImpl::refuseCap ( size_t  n,
size_t  dynCap 
)
inlinenoexcept

§6.3's second tier: the receiver cap on a schema-unbounded field (§6.2.1).

The bytes are well-formed — the same message decodes on a receiver configured more loosely — so a breach is Error::LimitExceeded and never Error::InvalidMessage. Rejected, never clamped.

DynCap is the parameter type on purpose: a cap this corelib was not given has no spelling here, so there is no omitted-argument path that could be read as unlimited (§6.2.1). The value is used for this one comparison and not retained.

Parameters
nThe announced length in bytes, or element count.
dynCapThe caller's cap. A maximum: n > dynCap is refused.
Returns
true when the value was refused.

Definition at line 2561 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refuseSchema()

bool sofab::IStreamImpl::refuseSchema ( size_t  n,
long  schemaBound 
)
inlinenoexcept

§6.3's first tier: the bound the schema declares.

A value past a declared maxlen / count is a statement about the message's validity, so it is Error::InvalidMessage (MESSAGE_SPEC §7.1). The number is the caller's, passed in for this one comparison and not kept: §6.2.1 leaves the codec "the report and the category" and forbids it to invent or store a bound, which is not the same as forbidding it to compare against one it was handed. Passing it here rather than testing it before the call is what keeps a §7.3-skipped field unjudged — every caller of this runs the tag test first, so a header contradicting the declared type has already returned.

Parameters
nThe announced length in bytes, or element count.
schemaBoundSchema maxlen/count, or -1 when the schema declares none, in which case nothing is refused here and the field is the receiver cap's business instead.
Returns
true when the value was refused, in which case the caller must return without touching the destination.

Definition at line 2534 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refuseUnbounded()

bool sofab::IStreamImpl::refuseUnbounded ( long  schemaBound,
long  room 
)
inlinenoexcept

Refuse a read that was given no ceiling of any kind.

The gap corelib-c-cpp#152 was filed for, and the one a long dynCap = -1 parameter used to swallow. A read of a field the schema does not bound, into a destination that publishes no capacity, with no receiver cap stated, sizes the caller's storage from a number the sender chose. §6.2.1 forbids treating that as unlimited: "there is no unset state and no unlimited mode", and a format ceiling reached because no cap was stated "is the FORMAT's bound and MUST NOT be presented as a receiver cap".

So it is diagnosed instead. Nothing about the message is wrong and no limit was configured to raise, which rules out the other two categories: the mistake is in the call, and §6.3 gives that Error::InvalidArgument. The fix at the call site is to state one of the two ceilings — pass the schema bound, or use the …Capped entry point with the receiver cap.

A heap-free destination needs neither: its capacity is a ceiling the sender cannot move, so room >= 0 passes here and an over-capacity value is refused by refuse as the third tier.

Parameters
schemaBoundSchema maxlen/count, or -1 for none.
roomThe destination's static capacity, or -1 for a growable one.
Returns
true when the read must not proceed.

Definition at line 2595 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetRefusal_()

void sofab::IStreamImpl::resetRefusal_ ( )
inlineprotectednoexcept

Clear a latched refusal, for a subclass that re-initialises the stream itself.

invalidate documents the verdict as cleared by re-initialising the stream, and the C core's own sticky flag is. This one is not: it is a member, so it survives a bare sofab_istream_init() on the embedded context and would report a stale category on the next message. The library never hits that — sofab_istream_init is called from the constructors — but a subclass that re-inits to reuse one object (as bench/cpp does) must call this in the same breath.

Definition at line 2120 of file sofab.hpp.

◆ wire()

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

Wire type of the field currently being delivered.

Valid inside a field callback / deserialize, before the field's read binds a destination. MESSAGE_SPEC §7.3: compare it against the wire type the declared field maps to and, on a mismatch, return without calling read — the field is then skipped automatically, exactly like an unknown id (a framing mismatch, not a malformed message). Reads no bytes and does not consume the field.

Returns
The delivered field's Wire.

Definition at line 2648 of file sofab.hpp.

Here is the caller graph for this function:

Field Documentation

◆ arrayDecoder_

sofab_istream_decoder_t sofab::IStreamImpl::arrayDecoder_
protected

Definition at line 2073 of file sofab.hpp.

◆ ctx_

sofab_istream_t sofab::IStreamImpl::ctx_
protected

Underlying C input stream context.

Definition at line 2059 of file sofab.hpp.

◆ refusal_

uint8_t sofab::IStreamImpl::refusal_ = SOFAB_RET_OK
protected

Definition at line 2092 of file sofab.hpp.


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