|
SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
|
Namespaces | |
| namespace | detail |
| Implementation details of the wire format; not part of the public API. | |
Classes | |
| struct | BlobSeq |
The blob counterpart of StringSeq; see it for the placement and bound rules. More... | |
| struct | ElemBound |
| The value range a declared integer type admits (MESSAGE_SPEC §7.1). More... | |
| class | FixedBytes |
Fixed-capacity, heap-free byte blob of up to N bytes. More... | |
| class | FixedString |
Fixed-capacity, heap-free string of up to N characters. More... | |
| class | InlineVector |
Fixed-capacity, heap-free sequence of up to N elements of type T. More... | |
| class | IStreamImpl |
| Base of the input streams: decodes fields from fed bytes. More... | |
| class | IStreamInline |
| Input stream that delivers each top-level field to a user callback. More... | |
| class | IStreamInto |
| Decoder that decodes into a message instance the CALLER owns. More... | |
| class | IStreamMessage |
| Base class for user-defined messages that can deserialise themselves. More... | |
| class | IStreamObject |
| Holds a message and routes decoded top-level fields into it. More... | |
| struct | Limits |
| The one stream-scoped receiver cap: how many bytes a single top-level field may span. More... | |
| struct | Message |
| A message that both encodes and decodes: exactly OStreamMessage + IStreamMessage. More... | |
| struct | MessageSeq |
| Collects a struct/union or nested-array wrapper sequence into the container it is handed. More... | |
| class | OStream |
| Output stream over a caller-supplied buffer whose lifetime is shared. More... | |
| class | OStreamImpl |
| Base of the output streams: encodes values into a caller-provided buffer. More... | |
| class | OStreamInline |
| Output stream whose buffer is stored inline (the buffer costs no heap allocation). More... | |
| class | OStreamMessage |
| Base class for user-defined messages that can serialise themselves. More... | |
| class | OStreamObject |
| Bundles a message with an inline output buffer sized for it. More... | |
| class | OStreamView |
| Output stream over a buffer the caller already owns. More... | |
| struct | RowSeq |
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... | |
| struct | StringSeq |
Collects the elements of a string wrapper-sequence array. More... | |
Concepts | |
| concept | OutputMessage |
Constrains a serialisable message: derives from sofab::OStreamMessage and exposes a static constexpr std::size_t _maxSize. | |
| concept | InputMessage |
| Constrains a deserialisable message: must derive from sofab::IStreamMessage. | |
Typedefs | |
| using | id = uint32_t |
| Field identifier on the wire. | |
Enumerations | |
| enum class | Error { None = 0 , BufferFull = 3 , InvalidArgument = 1 , InvalidMessage = 4 , Incomplete = 5 , LimitExceeded = 6 } |
Status codes returned by the encode/decode API; None signals success. More... | |
| enum class | DecodeStatus { Complete = 0 , Incomplete = 1 , Invalid = 2 , LimitExceeded = 3 , InvalidArgument = 4 } |
| Three-valued decode outcome of a sofab::IStreamImpl::feed call (spec §7). More... | |
Functions | |
| template<std::ranges::contiguous_range A, std::ranges::contiguous_range B> requires std::ranges::sized_range<A> && std::ranges::sized_range<B> && detail::FloatElement<std::remove_cv_t<std::ranges::range_value_t<A>>> && std::same_as<std::remove_cv_t<std::ranges::range_value_t<A>>, std::remove_cv_t<std::ranges::range_value_t<B>>> | |
| bool | bitsEqual (const A &a, const B &b) noexcept |
True iff a and b have the same length and every element pair has the same IEEE-754 bit pattern. | |
| template<detail::FloatElement T, std::ranges::contiguous_range A> requires std::ranges::sized_range<A> && std::same_as<std::remove_cv_t<std::ranges::range_value_t<A>>, T> | |
| bool | bitsEqual (const A &a, std::initializer_list< T > b) noexcept |
Braced-list default: bitsEqual(field, {0.0f, 1.5f}). | |
| constexpr bool | utf8_valid (std::string_view bytes) noexcept |
| Public UTF-8 validity primitive (spec CORELIB_PLAN §6.4). | |
| template<typename S > | |
| bool | readString (IStreamImpl &is, S &dst, long maxlen) noexcept |
Read the current field as a string into a destination this call sizes — the generated layer's IStreamImpl::readString. | |
| template<typename S > | |
| bool | readStringCapped (IStreamImpl &is, S &dst, long dynCap) noexcept |
The schema-unbounded sofab::readString: sizes dst only once the §6.2.1 receiver cap has admitted the field. | |
| template<typename B > | |
| bool | readBlob (IStreamImpl &is, B &dst, long maxlen) noexcept |
The blob counterpart of sofab::readString. | |
| template<typename B > | |
| bool | readBlobCapped (IStreamImpl &is, B &dst, long dynCap) noexcept |
The blob counterpart of sofab::readStringCapped. | |
| template<typename T > | |
| bool | readArray (IStreamImpl &is, T &dst, long schemaCount, ElemBound elem={}) noexcept |
| Read the current count-prefixed array into a destination this call sizes — the generated layer's IStreamImpl::readArray. | |
| template<typename T > | |
| bool | readArrayCapped (IStreamImpl &is, T &dst, long dynCap, ElemBound elem={}) noexcept |
The schema-unbounded sofab::readArray: sizes dst only once the §6.2.1 receiver cap has admitted the count. | |
| template<typename T > | |
| bool | read (IStreamImpl &is, T &dst) noexcept |
| IStreamImpl::read with the destination sized first — the generated layer's untyped read. | |
Variables | |
| constexpr int | API_VERSION = 1 |
| Version of the SofaBuffers public API implemented by this header. | |
| constexpr uint32_t | ID_MAX = 0x7fffffffu |
Largest valid field id (INT32_MAX). | |
| constexpr uint32_t | FIXLEN_MAX = 0x7fffffffu |
Largest fixlen payload byte-length (INT32_MAX). | |
| constexpr uint32_t | ARRAY_MAX = 0x7fffffffu |
Largest array element count (INT32_MAX). | |
| constexpr int | MAX_DEPTH = 255 |
| Maximum nested-sequence depth (§4.9). | |
| constexpr size_t | MIN_OUTPUT_BUFFER = 1 |
| Smallest output buffer this port accepts for streaming (§5.1). | |
| template<typename > | |
| constexpr bool | always_false_v = false |
Always-false trait used to trigger static_assert in the otherwise-unreachable branch of an if constexpr chain. | |
| using sofab::id = typedef uint32_t |
|
strong |
Three-valued decode outcome of a sofab::IStreamImpl::feed call (spec §7).
The decoder reports where the consumed bytes ended, with no separate finish/finalize step (§7.1): the same three outcomes apply to a one-shot buffer and to chunked streaming. Whether an Incomplete result is acceptable is the caller's decision — a streaming caller reads it as "feed
me the next chunk", a whole-message caller reads it as a truncated message.
| Enumerator | |
|---|---|
| Complete | Consumed bytes end exactly at a field boundary — a valid message. |
| Incomplete | Consumed bytes end inside a field or with an open sequence. Not an error. |
| Invalid | Bytes are malformed regardless of what follows. Terminal. |
| LimitExceeded | A configured receiver-side limit (§6.2.1) was exceeded on a schema-**unbounded** field. The bytes are well-formed — the same message decodes under a looser limit — so this is a policy rejection and not DecodeStatus::Invalid — §6.3 requires an implementation to "keep the two distinguishable to the caller" and forbids reporting it as §6.3 offers two ways to surface it, "either a <strong>fourth decode outcome</strong>, or a terminal failure carrying the <tt>LimitExceeded</tt> code on the error channel"; this port does both, so a caller switching on sofab::IStreamImpl::Result::status alone cannot mistake it for malformation. |
| InvalidArgument | The value broke neither the schema bound nor a receiver cap, but does not fit the destination this caller handed over (§6.6.3, §6.3's third refusal tier). A mistake in the call, not in the message: the same bytes decode for a caller who passes a larger destination. Terminal. |
|
strong |
Status codes returned by the encode/decode API; None signals success.
| Enumerator | |
|---|---|
| None | Operation succeeded (decode: |
| BufferFull | Encode-only: the encoder ran out of room. Either the output buffer filled and no flush callback was set, or — the rare second case — OStreamImpl::sequenceBeginLazy could not allocate room to hold one more sequence header back (see OStreamImpl::sequenceBeginLazy). |
| InvalidArgument | An argument was out of range (e.g. a field id above the limit) — and, on the decode side, §6.3's third refusal tier: a value that broke neither the schema bound nor a receiver cap but does not fit the destination the caller handed over (§6.6.3). "The third is a mistake in the <strong>call</strong>, not a property of the message or of the deployment, and the other two codes each say something untrue about it. <tt>InvalidMessage</tt> would mark a well-formed message malformed — the same bytes decode for a caller who passes a larger destination, and no §5.2.2 condition is present. <tt>LimitExceeded</tt> would promise a limit to raise that was never configured." (§6.3) |
| InvalidMessage | The input bytes are malformed (decode: |
| Incomplete | Decode-only: the fed bytes end inside a field — a partial varint (§4.1), a fixlen/array payload shorter than declared (§4.6/§4.8), or an open sequence (§4.9). This is |
| LimitExceeded | Decode-only: a receiver-configured cap (§6.2.1) was exceeded on a field the schema leaves unbounded — the field-span budget Limits::max_buffered_field, or the Policy, not malformation — deliberately distinct from InvalidMessage, so a differential fuzzer never reads a local buffering limit as a conformance divergence. The bytes are never clamped or truncated; IStreamImpl::feed simply fails with this code. Never raised for a field the schema bounds (§6.2.1/§6.3). A declared |
|
inlinenoexcept |
True iff a and b have the same length and every element pair has the same IEEE-754 bit pattern.
Accepts anything contiguous and sized whose element type is float or double, on both sides: std::vector, sofab::InlineVector, std::array, std::span, a C array, or a braced list (bitsEqual(v, {0.0f, 1.5f}) binds a std::initializer_list<float>). Both sides must have the same element type. The length is compared first; nothing is allocated or modified.
false on a length mismatch or any differing bit pattern. Definition at line 72 of file bits_equal.hpp.
|
inlinenoexcept |
Braced-list default: bitsEqual(field, {0.0f, 1.5f}).
Definition at line 84 of file bits_equal.hpp.
|
noexcept |
IStreamImpl::read with the destination sized first — the generated layer's untyped read.
Dispatches like IStreamImpl::read and adds nothing for a scalar or a sub-message, whose destinations hold no room to size. A std::string payload destination and a contiguous element range are sized here, so the codec never has to grow one.
|
noexcept |
Read the current count-prefixed array into a destination this call sizes — the generated layer's IStreamImpl::readArray.
Sizes dst for the announced element count, clamped to what the bytes in hand could fill, and only once the tag (§7.3), the schema count (§7.1) and the configured receiver cap (§6.2.1) all admit the field — so neither a mistyped occurrence nor a hostile count reaches an allocator. The codec then fills what it was given room for and refuses a destination shorter than the array actually is (§6.6.3).
Two entry points, neither defaulted, exactly as for sofab::readString.
| is | Stream delivering the field. |
| dst | Destination range. |
| schemaCount | Declared count: N. Required and non-negative. |
| elem | Declared element range (ElemBound). |
true when the array was read.
|
noexcept |
The schema-unbounded sofab::readArray: sizes dst only once the §6.2.1 receiver cap has admitted the count.
| is | Stream delivering the field. |
| dst | Destination range. |
| dynCap | The caller's max_dyn_array_count. Required and non-negative. |
| elem | Declared element range (ElemBound). |
|
noexcept |
The blob counterpart of sofab::readString.
Sizes dst for the announced payload and then hands it to the codec, which refuses a destination too short rather than growing one (§6.6.3). For a destination with static room (FixedString) it adds nothing and compiles away; for a std::string it is the one place the allocation happens.
The sizing runs only once every gate IStreamImpl::readString applies has admitted the field — the tag (§7.3), the declared maxlen (§7.1) and the configured receiver cap dynCap (§6.2.1) — so a mistyped, an over-long or an over-cap occurrence leaves dst exactly as it was (§7.4). Sizing on a subset of them would defeat the point of a receiver cap: §6.2.1 puts the check "before the allocation it is meant to prevent", and this call is that allocation. A schema-unbounded field sized here from the wire-announced length is precisely the sender dictating the receiver's allocation.
dst from the wire with neither number stated is precisely the sender dictating the receiver's allocation, so a negative one is refused with Error::InvalidArgument rather than obeyed.| is | Stream delivering the field. |
| dst | Destination for the decoded text. |
| maxlen | Declared maxlen. Required and non-negative. |
true when the value was read.
|
noexcept |
The blob counterpart of sofab::readStringCapped.
| is | Stream delivering the field. |
| dst | Destination for the decoded text. |
| dynCap | The caller's max_dyn_string_len. Required and non-negative. |
|
noexcept |
Read the current field as a string into a destination this call sizes — the generated layer's IStreamImpl::readString.
Sizes dst for the announced payload and then hands it to the codec, which refuses a destination too short rather than growing one (§6.6.3). For a destination with static room (FixedString) it adds nothing and compiles away; for a std::string it is the one place the allocation happens.
The sizing runs only once every gate IStreamImpl::readString applies has admitted the field — the tag (§7.3), the declared maxlen (§7.1) and the configured receiver cap dynCap (§6.2.1) — so a mistyped, an over-long or an over-cap occurrence leaves dst exactly as it was (§7.4). Sizing on a subset of them would defeat the point of a receiver cap: §6.2.1 puts the check "before the allocation it is meant to prevent", and this call is that allocation. A schema-unbounded field sized here from the wire-announced length is precisely the sender dictating the receiver's allocation.
dst from the wire with neither number stated is precisely the sender dictating the receiver's allocation, so a negative one is refused with Error::InvalidArgument rather than obeyed.| is | Stream delivering the field. |
| dst | Destination for the decoded text. |
| maxlen | Declared maxlen. Required and non-negative. |
true when the value was read.
|
noexcept |
|
constexprnoexcept |
Public UTF-8 validity primitive (spec CORELIB_PLAN §6.4).
Returns true iff bytes is well-formed UTF-8 by detail::utf8Valid (rejecting overlong forms, surrogates and out-of-range code points; accepting embedded NUL). Independent of SOFAB_STRICT_UTF8 — this is the validator itself, always available; the compile-time flag only decides whether the encode/decode paths invoke it.
| bytes | Candidate string payload. |
true iff bytes is valid UTF-8.
|
inlineconstexpr |
Always-false trait used to trigger static_assert in the otherwise-unreachable branch of an if constexpr chain.
Because the value depends on the template parameter, the assertion only fires when that branch is actually instantiated, which is the idiomatic way to reject unsupported types at compile time.
| T | The type the dependent assertion is bound to. |
|
inlineconstexpr |
|
inlineconstexpr |
Largest array element count (INT32_MAX).
Encoding a longer array is Error::InvalidArgument; decoding one is Error::InvalidMessage.
|
inlineconstexpr |
Largest fixlen payload byte-length (INT32_MAX).
Encoding a longer payload is Error::InvalidArgument; decoding one is Error::InvalidMessage.
|
inlineconstexpr |
Largest valid field id (INT32_MAX).
Encoding a larger id is Error::InvalidArgument; decoding one is Error::InvalidMessage.
|
inlineconstexpr |
Maximum nested-sequence depth (§4.9).
Deeper nesting is rejected (encode: Error::InvalidArgument; decode: Error::InvalidMessage).
|
inlineconstexpr |
Smallest output buffer this port accepts for streaming (§5.1).
This implementation writes byte-at-a-time whenever the buffer is tight — every write funnels through OStreamImpl::pushBytes, which falls back to a per-byte push that flushes across the boundary — so it splits atomic units too and declares the smallest value §5.1 admits, 1. A caller therefore never has to reserve headroom: any non-empty buffer streams a message of any size, and the bytes are identical to the one-shot path.
It binds a buffer installed together with a flush sink, and only such a buffer: buflen - offset >= MIN_OUTPUT_BUFFER is checked where the buffer is handed over — a constructor or OStream::setBuffer — and never partway through a message. A buffer installed without a sink is subject to no minimum at all: no flush can occur, so it either holds the message or reports Error::BufferFull, and a two-byte message still encodes into two bytes.
A rejected installation leaves the stream inert and latched at Error::InvalidArgument (OStreamImpl::ok is false, OStreamImpl::error reports it); no write it is then asked for touches the buffer.