|
SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
|
Collects a struct/union or nested-array wrapper sequence into the container it is handed. More...
#include <sofab.hpp>
Public Types | |
| using | Container = std::conditional_t< detail::namesSeqContainer< A >(), A, std::vector< A > > |
Destination container: A itself, or std::vector<A> for the element spelling. | |
| using | Elem = typename Container::value_type |
| Element type — an IStreamMessage, or a container for a nested-array row. | |
Public Member Functions | |
| void | prepare () noexcept |
| §7.4 replace-whole, and absent ⇒ never called: | |
| void | deserialize (IStreamImpl &is, sofab::id id, size_t, size_t) noexcept override |
Consume one of this message's fields from istream. | |
Public Member Functions inherited from sofab::IStreamMessage | |
| virtual | ~IStreamMessage ()=default |
Public Attributes | |
| Container * | out = nullptr |
| Destination; a null one collects nothing. | |
| long | cap = -1 |
Schema count N, or -1; an id at or past N is Error::InvalidMessage (§5.1/§7.1). | |
| long | dynCap = -1 |
The configured receiver cap on the element index (max_dyn_array_count, §6.2.1); negative means none. | |
| long | rowCap = -1 |
The ROW's schema count N, or -1 — the second axis of a native nested row (array<array<u32>>), and the inner array's own §7.1 bound (corelib-cpp#124). | |
| long | rowDynCap = -1 |
The ROW's receiver cap (max_dyn_array_count), or -1 — the row-axis twin of dynCap. | |
Static Public Attributes | |
| static constexpr long | elemDestCap = detail::destCapacity<Container>() |
| The destination's own capacity, or -1 for a growable container. | |
| static constexpr int | elemWire |
| The declared element type, published to the stream (§7.3), as StringSeq::elemWire is. | |
Collects a struct/union or nested-array wrapper sequence into the container it is handed.
One element is placed and read per child: IStreamImpl::read descends into a struct/union element's own sub-sequence, and a native-scalar row goes through IStreamImpl::readArray — exactly as a top-level field of that type would be read.
The target is held by pointer rather than a bound reference so one instance can serve several fields.
| A | Destination container, as StringSeq takes it: std::vector<T> for the growable storage mode, InlineVector<T, N> for the heap-free one; its value_type is the element type. The older ELEMENT spelling MessageSeq<T>, which always collected into a std::vector<T>, still compiles — see detail::namesSeqContainer for how the two are told apart. |
| using sofab::MessageSeq< A >::Container = std::conditional_t<detail::namesSeqContainer<A>(), A, std::vector<A> > |
| using sofab::MessageSeq< A >::Elem = typename Container::value_type |
Element type — an IStreamMessage, or a container for a nested-array row.
|
inlineoverridevirtualnoexcept |
Consume one of this message's fields from istream.
Invoked once per field of the message; use id to dispatch and IStreamImpl::read to pull the value.
| istream | Stream positioned at the field's value. |
| id | Identifier of the field being delivered. |
| size | Payload length (fixlen) or element size (fixlen array), in bytes. |
| count | Element count for array fields, otherwise 0. |
Implements sofab::IStreamMessage.
|
inlinenoexcept |
§7.4 replace-whole, and absent ⇒ never called:
§7.4: the sequence IS the array's value, so a repeated field id replaces it whole.
IStreamImpl::read calls this once the SequenceStart tag matched, so a §7.3-skipped occurrence cannot wipe a valid earlier one.
out is left exactly as it was — so a destination reused across messages must be reset by its owner first (IStreamObject::reset, §5.1 "supplying a
cleanly initialised destination is the application's
responsibility"). This is not the collector's call to make: it never learns that the field was absent. | long sofab::MessageSeq< A >::cap = -1 |
Schema count N, or -1; an id at or past N is Error::InvalidMessage (§5.1/§7.1).
It used to default to the destination's own capacity, which bounded a heap-free container but reported the wrong category for it: a destination too short is neither a malformed message nor a configured limit. That bound now lives in elemDestCap, in §6.3's third category, and this member carries only what the schema said.
| long sofab::MessageSeq< A >::dynCap = -1 |
The configured receiver cap on the element index (max_dyn_array_count, §6.2.1); negative means none.
A wrapper array carries no count header, so there is no count word for a cap to bind: "for a <strong>sequence array</strong> it surfaces the <strong>index</strong> of the element in hand — a wrapper array's length is <em>highest present id + 1</em> (MESSAGE_SPEC §5.1), so the index is what has to be checked, there being no count header to check." An id at or past this is Error::LimitExceeded, decided before out is extended, so an announced index never becomes an allocation.
Deliberately not StringSeq::cap — cap is the schema count and its breach is InvalidMessage — the bytes contradict the schema both peers agreed on — while this is a policy rejection the same bytes survive under a looser cap, and §6.2.1 forbids folding the two. It is also ignored while cap is armed, since a receiver limit "MUST NOT be
applied to a field the schema already bounds". The number itself is generated code's to supply (§6.2.1: "The numbers and the allocation are
not the codec's"). There is no default: the constructor takes it, and a collector built without one does not compile. (corelib-cpp#124)
cap nor a dynCap nor a fixed-capacity destination is refused with Error::InvalidArgument at its first element (detail::seqIndexAdmitted). "No cap stated" is never read as "unlimited" (§6.2.1).
|
staticconstexpr |
The destination's own capacity, or -1 for a growable container.
§6.3's third tier: an index the container cannot hold, with neither the schema nor the deployment objecting, is Error::InvalidArgument. For a fixed-capacity container this is also what keeps the placement loop below terminating — InlineVector::emplace_back reuses the last slot once full, so out.size() would never pass a large id.
|
staticconstexpr |
The declared element type, published to the stream (§7.3), as StringSeq::elemWire is.
A struct/union element arrives as a sequence; a nested-array row arrives as the array wire type its element kind selects — the same choice IStreamImpl::read makes when it reads the row. -1 for a row type neither rule covers, which leaves the bound to the check below.
| Container* sofab::MessageSeq< A >::out = nullptr |
| long sofab::MessageSeq< A >::rowCap = -1 |
The ROW's schema count N, or -1 — the second axis of a native nested row (array<array<u32>>), and the inner array's own §7.1 bound (corelib-cpp#124).
A matrix has two axes and each needs its own pair of numbers. cap / dynCap bound the row id, which is the outer array's length (§5.1). These two bound the row's element count, which the row announces as a real count header because a row IS a native array — and that header is the enforcement point §6.2.1 names, "before the allocation it is meant to prevent".
Reusing dynCap for the row was wrong in both directions. Where the OUTER array carries a schema count, ARCHITECTURE §9.5 has generated code state no receiver cap at all — caps govern only what the schema left unbounded — so the row was read under -1 and every row was refused Error::InvalidArgument. Where the outer array was unbounded, a row past the inner count: was accepted under the OUTER array's element cap, which is a §7.1 INVALID gone missing and, had it fired, the wrong category for it.
Set it when the schema declares the inner count; leave it -1 and set rowDynCap when it does not. Both -1 is refused, not obeyed, exactly as on the id axis.
| long sofab::MessageSeq< A >::rowDynCap = -1 |
The ROW's receiver cap (max_dyn_array_count), or -1 — the row-axis twin of dynCap.
Consulted only where rowCap is absent, and its breach is Error::LimitExceeded: the bytes are well-formed and the same row decodes for a receiver configured with a larger cap (§6.2.1, §6.3). A row the schema bounds answers to rowCap alone — §6.2.1 forbids applying a receiver cap to a field the schema already bounds.