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

Collects the elements of a string wrapper-sequence array. More...

#include <sofab.hpp>

Inheritance diagram for sofab::StringSeq< C >:
[legend]
Collaboration diagram for sofab::StringSeq< C >:
[legend]

Public Member Functions

 StringSeq (C &o, long capacity, long elemMax, long indexCap, long elemLenCap) noexcept
 
void prepare () noexcept
 §7.4: the sequence IS the array's value, so a repeated field id replaces it whole.
 
void deserialize (IStreamImpl &is, sofab::id id, size_t size, 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
 
long emax
 
long dynCap
 The configured receiver cap on the element index (max_dyn_array_count, §6.2.1); negative means none.
 
long elemDynCap
 The §6.2.1 receiver cap on one ELEMENT's length, or -1 when the caller supplied none.
 

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>(detail::Wire::Fixlen)
 The declared element type, published to the stream (§7.3).
 
static constexpr int elemFix = static_cast<int>(detail::Fix::String)
 The declared element type, published to the stream (§7.3).
 

Detailed Description

template<typename C = std::vector<std::string>>
struct sofab::StringSeq< C >

Collects the elements of a string wrapper-sequence array.

MESSAGE_SPEC §5 lowers an array of strings to a sequence whose child ids are the element indices, so an element is placed at its id rather than appended: a default (empty) element is omitted on the wire (§2), and the gap it leaves is filled with the element default.

The schema bounds ride into the read, so a mis-typed element is skipped under §7.3 instead of being measured against bounds that are not its own, and an over-index element that survives that test is rejected by the stream — at the element header for an element type the header settles, and at the fixlen word for a fixlen one, which is where a string element's subtype becomes known.

Template Parameters
CDestination container. std::vector<std::string> for the growable storage mode, InlineVector<FixedString<M>, N> for the heap-free one; anything with clear/size/emplace_back/operator[] whose value_type readString accepts will do. Class template argument deduction makes the spelling identical either way: sofab::StringSeq s{dst, count, maxlen}.

Definition at line 6686 of file sofab.hpp.

Constructor & Destructor Documentation

◆ StringSeq()

template<typename C = std::vector<std::string>>
sofab::StringSeq< C >::StringSeq ( C &  o,
long  capacity,
long  elemMax,
long  indexCap,
long  elemLenCap 
)
inlineexplicitnoexcept
Parameters
oDestination vector; elements are placed at their index id.
capacitySchema count N, or -1 for an unbounded array. An element id at or past N is INVALID (§5.1/§7) once the element has passed the §7.3 type test, rejected before the container grows — which also bounds an over-index allocation.
elemMaxElement maxlen, or -1. A longer element is INVALID (§7.1), never truncated.
indexCapThe caller's max_dyn_array_count (dynCap), or -1 when none was supplied — there is no fallback, so no index cap then applies. An element id at or past it is Error::LimitExceeded, decided before the container grows.
elemLenCapThe caller's max_dyn_string_len / max_dyn_blob_len for one element (elemDynCap), or -1 when none was supplied. Consulted only where elemMax is -1.

Definition at line 6772 of file sofab.hpp.

Member Function Documentation

◆ deserialize()

template<typename C = std::vector<std::string>>
void sofab::StringSeq< C >::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 6793 of file sofab.hpp.

◆ prepare()

template<typename C = std::vector<std::string>>
void sofab::StringSeq< C >::prepare ( )
inlinenoexcept

§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 6791 of file sofab.hpp.

Member Data Documentation

◆ cap

template<typename C = std::vector<std::string>>
long sofab::StringSeq< C >::cap

Definition at line 6689 of file sofab.hpp.

◆ dynCap

template<typename C = std::vector<std::string>>
long sofab::StringSeq< C >::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 6713 of file sofab.hpp.

◆ elemDestCap

template<typename C = std::vector<std::string>>
constexpr long sofab::StringSeq< C >::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 6739 of file sofab.hpp.

◆ elemDynCap

template<typename C = std::vector<std::string>>
long sofab::StringSeq< C >::elemDynCap

The §6.2.1 receiver cap on one ELEMENT's length, or -1 when the caller supplied none.

dynCap bounds how many elements the array may have; this bounds how long each may be. Both are needed: an array of two elements a gigabyte each is under any index cap. It is consulted only where emax is -1 — a receiver limit "MUST NOT be applied to a field the schema already bounds" — and, like every cap here, it is passed in and never held. There is no default: a negative value means the caller stated no cap, and an element read under one answers Error::InvalidArgument rather than being read unbounded.

Definition at line 6728 of file sofab.hpp.

◆ elemFix

template<typename C = std::vector<std::string>>
constexpr int sofab::StringSeq< C >::elemFix = static_cast<int>(detail::Fix::String)
staticconstexpr

The declared element type, published to the stream (§7.3).

The §5.1/§7 over-index reject applies only to an element whose header agrees with this — one that contradicts it is not this array's element at all and is skipped like an unknown id, bound or no bound. The stream picks these up exactly as it picks up cap; they are compile-time constants, so no constructor signature changes.

Definition at line 6752 of file sofab.hpp.

◆ elemWire

template<typename C = std::vector<std::string>>
constexpr int sofab::StringSeq< C >::elemWire = static_cast<int>(detail::Wire::Fixlen)
staticconstexpr

The declared element type, published to the stream (§7.3).

The §5.1/§7 over-index reject applies only to an element whose header agrees with this — one that contradicts it is not this array's element at all and is skipped like an unknown id, bound or no bound. The stream picks these up exactly as it picks up cap; they are compile-time constants, so no constructor signature changes.

Definition at line 6750 of file sofab.hpp.

◆ emax

template<typename C = std::vector<std::string>>
long sofab::StringSeq< C >::emax

Definition at line 6690 of file sofab.hpp.

◆ out

template<typename C = std::vector<std::string>>
C& sofab::StringSeq< C >::out

Definition at line 6688 of file sofab.hpp.


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