Skip to content

feat(seq): RowSeq, a collector for rows the stream cannot read on its own - #151

Merged
Andste82 merged 2 commits into
mainfrom
feat/row-seq
Oct 2, 2026
Merged

Andste82 merged 2 commits into
mainfrom
feat/row-seq

Conversation

@Andste82

@Andste82 Andste82 commented Oct 1, 2026

Copy link
Copy Markdown
Member

What

sofab::RowSeq<C, Reader>: a wrapper-array collector for rows the stream cannot read on its own: a row that is itself a wrapper sequence (array<array<string>>, array<array<struct>>, deeper), or an enum/boolean row that has to bind through a view of its elements.

MessageSeq hands each element to IStreamImpl::read, which reads a message or a span of native scalars and nothing else. For other rows the generator emitted its own collector per field into every user's header. That collector was a static helper, and this suite could not see it. sofa-buffers/generator#627 found it applying the index bound before the §7.3 test.

RowSeq takes the row read from the caller (Reader) and owns the rest, in the order every other collector here applies it:

  1. §7.3 first. The row's wire type is published as elemWire, so the stream runs the test at the element header, ahead of the bound.
  2. The §5.1 index bound in §6.3's three categories (detail::seqIndexAdmitted).
  3. Placement at dest[id], with the gap filled.
  4. §7.4 replace-whole via prepare().

The reader has two parts:

  • static constexpr detail::Wire wire() names the row's wire type. It is a function because a local class, where generated code declares the reader, may not have static data members.
  • operator()(IStreamImpl &, Row &) reads the placed row.

The schema count and the receiver index cap are constructor arguments, as on StringSeq, so neither can be left out.

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, /*count*/ 2, /*dynCap*/ -1, Row{}};
sofab::read(is, c);

Tests

test_roundtrip.cpp rowSeqCollector() covers:

  • placement with an id gap, fed whole and fed one byte at a time
  • §7.3 before the bound, both for an element past the count and for one in range
  • §7.4: a repeat replaces the array, and a skipped repeat leaves it intact
  • all three refusal tiers: InvalidMessage, LimitExceeded and InvalidArgument
  • heap-free storage, with no allocation
  • an array-wire row

Removing the §7.3 test from RowSeq fails two of these checks. ctest passes 6/6.

Consumers

sofa-buffers/generator#629 makes the C++ backend emit only the reader and this call. The generator PR follows. Its lang-cpp job pins corelib main, so it goes green once this and the corelib-c-cpp twin are merged.

…ot read

MessageSeq hands each element to IStreamImpl::read, which reads a message or a
span of native scalars and nothing else. A row that is itself a wrapper sequence
(array<array<string>>, array<array<struct>>, deeper) is neither, and an enum or
boolean row has to bind through a view of its elements. The generator therefore
emitted its own collector for such rows, per field, into every user's header
(sofa-buffers/generator#629) -- a static helper whose shape is the same for every
schema, and one the corelib suite could not see: generator#627 found it applying
the index bound before the §7.3 wire-type test.

RowSeq<C, Reader> takes the row read from the caller and owns the rest, in the
order every other collector here applies it:

- §7.3 first: an element whose wire type contradicts the row's is skipped before
  the index bound and before the placement. The row's wire type is published as
  elemWire, so the stream runs the same test at the element header and applies
  the bound only to an element that survives it.
- the §5.1 index bound in §6.3's categories (detail::seqIndexAdmitted): schema
  count, receiver cap, destination capacity.
- placement at dest[id], with the gap filled.
- §7.4 replace-whole via prepare().

The Reader states the row's wire type through a static constexpr wire() -- a
function, because a local class, which is where generated code declares it, may
not have static data members -- and reads the placed row in operator(). The
schema count and the receiver cap are constructor arguments, as on StringSeq, so
neither can be left out.

test_roundtrip.cpp's rowSeqCollector() pins placement with a gap, byte-by-byte
resume, §7.3 before the bound (in range and past it), §7.4 replace and the
skipped-repeat case, all three refusal tiers, heap-free storage with no
allocation, and an array-wire row. Removing the §7.3 test from RowSeq fails two
of its checks.
clang instantiates a polymorphic class's virtual members for sizeof, so pairing
ByteRowReader with a container of string rows failed to compile there. Compare
against the members' size instead.
@Andste82
Andste82 merged commit 44c58ef into main Oct 2, 2026
9 checks passed
@Andste82
Andste82 deleted the feat/row-seq branch October 2, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant