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

Collects a wrapper sequence whose elements are rows the stream cannot read on its own — a row that is itself a wrapper sequence (array<array<string>>, array<array<struct>>, deeper), or a row that must bind through a view of its elements (an enum or boolean row). More...

#include <sofab.hpp>

Inheritance diagram for sofab::RowSeq< C, Reader >:
[legend]
Collaboration diagram for sofab::RowSeq< C, Reader >:
[legend]

Public Types

using Container = C
 Destination container.
 
using Elem = typename C::value_type
 Row type: the container's element.
 

Public Member Functions

 RowSeq (C &o, long capacity, long indexCap, Reader reader={}) noexcept
 
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

C & out
 
long cap
 Schema count N, or -1; an id at or past N is INVALID (§5.1/§7.1).
 
long dynCap
 The configured receiver cap on the element index (max_dyn_array_count, §6.2.1); negative means none.
 
Reader readRow
 The row read (Reader).
 

Static Public Attributes

static constexpr long elemDestCap = detail::destCapacity<C>()
 The destination's own capacity, or -1 for a growable container.
 
static constexpr int elemWire = static_cast<int>(Reader::wire())
 The row's wire type, published to the stream (§7.3), as StringSeq::elemWire is.
 

Detailed Description

template<typename C, typename Reader>
struct sofab::RowSeq< C, Reader >

Collects a wrapper sequence whose elements are rows the stream cannot read on its own — a row that is itself a wrapper sequence (array<array<string>>, array<array<struct>>, deeper), or a row that must bind through a view of its elements (an enum or boolean row).

MessageSeq hands each element to IStreamImpl::read, which reads a message or a span of native scalars and nothing else. A row of strings is neither, so its read has to be stated by the caller: that is Reader, and it is the only part of a row collector that differs between schemas. Everything else is the wrapper-array rule every collector here applies, in the same order:

  1. §7.3 first. An element whose wire type contradicts the row's is not an element of this array at all. It is skipped like an unknown id, before the index bound — so it cannot breach it — and before the placement, so the destination is left exactly as it was. The row's wire type is published as elemWire, so the stream runs the same test one step earlier, at the element header, and applies the bound only to an element that survives it.
  2. §5.1 index bound, in §6.3's three categories (detail::seqIndexAdmitted): the schema count (cap, InvalidMessage), else the receiver cap (dynCap, LimitExceeded), and the destination's own capacity (elemDestCap).
  3. Placement. The element id IS the index: the container is grown with default rows up to it and the row is read in place at dest[id].
  4. §7.4. A repeated field id replaces the array whole, via prepare.
Template Parameters
CDestination container of rows — std::vector<Row> or InlineVector<Row, N>; deduced from the constructor.
ReaderThe row read, one level down. A default-constructible type with
  • static constexpr detail::Wire wire(), the wire type a row of this schema arrives with — SequenceStart for a row that is a wrapper sequence, the array wire type of the backing integer for an enum or boolean row; and
  • void operator()(IStreamImpl &, typename C::value_type &), reading the row that was placed.

wire() is a function rather than a constant because a local class — which is where generated code declares the reader, next to the field it reads — may not have static data members.

Example
// array<array<string>>: outer count 2, row count 3, element maxlen 8
struct Row {
static constexpr sofab::detail::Wire wire() noexcept { return sofab::detail::Wire::SequenceStart; }
void operator()(sofab::IStreamImpl &is, std::vector<std::string> &row) const noexcept {
sofab::StringSeq c{row, 3, 8, -1, -1}; sofab::read(is, c);
}
};
sofab::RowSeq c{grid, 2, -1, Row{}}; sofab::read(is, c);
Base of the input streams: decodes fields from fed bytes.
Definition sofab.hpp:2919
Wire
Wire type stored in the low 3 bits of every field header.
Definition sofab.hpp:264
@ SequenceStart
Opens a nested sub-message.
bool read(IStreamImpl &is, T &dst) noexcept
IStreamImpl::read with the destination sized first — the generated layer's untyped read.
Definition sofab.hpp:6565
Collects a wrapper sequence whose elements are rows the stream cannot read on its own — a row that is...
Definition sofab.hpp:7182
Collects the elements of a string wrapper-sequence array.
Definition sofab.hpp:6687

Definition at line 7181 of file sofab.hpp.

Member Typedef Documentation

◆ Container

template<typename C , typename Reader >
using sofab::RowSeq< C, Reader >::Container = C

Destination container.

Definition at line 7184 of file sofab.hpp.

◆ Elem

template<typename C , typename Reader >
using sofab::RowSeq< C, Reader >::Elem = typename C::value_type

Row type: the container's element.

Definition at line 7186 of file sofab.hpp.

Constructor & Destructor Documentation

◆ RowSeq()

template<typename C , typename Reader >
sofab::RowSeq< C, Reader >::RowSeq ( C &  o,
long  capacity,
long  indexCap,
Reader  reader = {} 
)
inlineexplicitnoexcept
Parameters
oDestination; rows are placed at their index id.
capacitySchema count N, or -1 for an unbounded array.
indexCapThe caller's max_dyn_array_count (dynCap), or -1 when none was supplied. Mandatory, as on StringSeq: a schema-unbounded growable array with neither is refused with Error::InvalidArgument, never read as unlimited (§6.2.1).
readerThe row read.

Definition at line 7213 of file sofab.hpp.

Member Function Documentation

◆ deserialize()

template<typename C , typename Reader >
void sofab::RowSeq< C, Reader >::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 7219 of file sofab.hpp.

◆ prepare()

template<typename C , typename Reader >
void sofab::RowSeq< C, Reader >::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 7217 of file sofab.hpp.

Member Data Documentation

◆ cap

template<typename C , typename Reader >
long sofab::RowSeq< C, Reader >::cap

Schema count N, or -1; an id at or past N is INVALID (§5.1/§7.1).

Definition at line 7190 of file sofab.hpp.

◆ dynCap

template<typename C , typename Reader >
long sofab::RowSeq< C, Reader >::dynCap

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)

Definition at line 7192 of file sofab.hpp.

◆ elemDestCap

template<typename C , typename Reader >
constexpr long sofab::RowSeq< C, Reader >::elemDestCap = detail::destCapacity<C>()
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 7197 of file sofab.hpp.

◆ elemWire

template<typename C , typename Reader >
constexpr int sofab::RowSeq< C, Reader >::elemWire = static_cast<int>(Reader::wire())
staticconstexpr

The row's wire type, published to the stream (§7.3), as StringSeq::elemWire is.

Definition at line 7201 of file sofab.hpp.

◆ out

template<typename C , typename Reader >
C& sofab::RowSeq< C, Reader >::out

Definition at line 7188 of file sofab.hpp.

◆ readRow

template<typename C , typename Reader >
Reader sofab::RowSeq< C, Reader >::readRow

The row read (Reader).

Definition at line 7194 of file sofab.hpp.


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