SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
Loading...
Searching...
No Matches
sofab::MessageSeq< A > Struct Template Reference

Collects a struct/union or nested-array wrapper sequence into the container it is handed. More...

#include <sofab.hpp>

Inheritance diagram for sofab::MessageSeq< A >:
[legend]
Collaboration diagram for sofab::MessageSeq< A >:
[legend]

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.
 

Detailed Description

template<typename A>
struct sofab::MessageSeq< A >

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.

Template Parameters
ADestination 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.

Definition at line 6939 of file sofab.hpp.

Member Typedef Documentation

◆ Container

template<typename A >
using sofab::MessageSeq< A >::Container = std::conditional_t<detail::namesSeqContainer<A>(), A, std::vector<A> >

Destination container: A itself, or std::vector<A> for the element spelling.

Definition at line 6942 of file sofab.hpp.

◆ Elem

template<typename A >
using sofab::MessageSeq< A >::Elem = typename Container::value_type

Element type — an IStreamMessage, or a container for a nested-array row.

Definition at line 6944 of file sofab.hpp.

Member Function Documentation

◆ deserialize()

template<typename A >
void sofab::MessageSeq< A >::deserialize ( IStreamImpl &  istream,
sofab::id  id,
size_t  size,
size_t  count 
)
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.

Parameters
istreamStream positioned at the field's value.
idIdentifier of the field being delivered.
sizePayload length (fixlen) or element size (fixlen array), in bytes.
countElement count for array fields, otherwise 0.

Implements sofab::IStreamMessage.

Definition at line 7045 of file sofab.hpp.

◆ prepare()

template<typename A >
void sofab::MessageSeq< A >::prepare ( )
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.

Warning
It runs only when the wrapper sequence is present. Since MESSAGE_SPEC §2 omits an all-default array field, an absent field reaches no collector at all and 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.

Definition at line 7043 of file sofab.hpp.

Member Data Documentation

◆ cap

template<typename A >
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.

Definition at line 6958 of file sofab.hpp.

◆ dynCap

template<typename A >
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)

Note
This collector is an aggregate — callers fill it field by field — so a member cannot be made mandatory the way StringSeq's constructor argument is. The sentinel is therefore still spellable here, and it is diagnosed rather than obeyed: an array with neither a schema 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).

Definition at line 6972 of file sofab.hpp.

◆ elemDestCap

template<typename A >
constexpr long sofab::MessageSeq< A >::elemDestCap = detail::destCapacity<Container>()
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.

Definition at line 7011 of file sofab.hpp.

◆ elemWire

template<typename A >
constexpr int sofab::MessageSeq< A >::elemWire
staticconstexpr
Initial value:
= []() constexpr -> int {
if constexpr (std::is_base_of_v<IStreamMessage, Elem>)
return static_cast<int>(detail::Wire::SequenceStart);
else if constexpr (requires { typename Elem::value_type; })
{
using RowElem = typename Elem::value_type;
if constexpr (std::is_integral_v<RowElem>)
return static_cast<int>(std::is_unsigned_v<RowElem> ? detail::Wire::ArrayUnsigned
: detail::Wire::ArraySigned);
else if constexpr (std::is_same_v<RowElem, float> || std::is_same_v<RowElem, double>)
return static_cast<int>(detail::Wire::ArrayFixlen);
else
return -1;
}
else
return -1;
}()
@ ArrayUnsigned
Count-prefixed array of unsigned varints.
@ ArrayFixlen
Count-prefixed array of fixed-size elements.
@ SequenceStart
Opens a nested sub-message.

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.

Definition at line 7022 of file sofab.hpp.

◆ out

template<typename A >
Container* sofab::MessageSeq< A >::out = nullptr

Destination; a null one collects nothing.

Definition at line 6946 of file sofab.hpp.

◆ rowCap

template<typename A >
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.

Definition at line 6998 of file sofab.hpp.

◆ rowDynCap

template<typename A >
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.

Definition at line 7009 of file sofab.hpp.


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