SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
Loading...
Searching...
No Matches
sofab::ElemBound Struct Reference

The value range a declared integer type admits (MESSAGE_SPEC §7.1). More...

#include <sofab.hpp>

Public Member Functions

constexpr ElemBound () noexcept=default
 
constexpr ElemBound (int64_t low, int64_t high) noexcept
 An explicit inclusive range, armed.
 

Static Public Member Functions

template<typename E >
static constexpr ElemBound of () noexcept
 The bound a declared element type E implies.
 

Public Attributes

int64_t lo = 0
 Smallest admissible value, inclusive.
 
int64_t hi = 0
 Largest admissible value, inclusive.
 
bool armed = false
 false: no bound — the decode is unchanged.
 

Detailed Description

The value range a declared integer type admits (MESSAGE_SPEC §7.1).

§7/§7.1 turned the declared integer width from a storage hint into a validity bound: a wire value that does not fit the declared type is INVALID alongside M > N and maxlen, and MUST NOT be masked to the width, nor kept. The wire itself carries no width — every integer is a varint read into a 64-bit accumulator — so the width is a schema fact and has to reach the decoder the same way count and maxlen do (IStreamImpl::readArray, IStreamImpl::readString).

For a scalar a caller can range-check the value once IStreamImpl::read has returned it. An array element cannot be checked that way without decoding the whole array into a wider temporary and copying it down — precisely the cost the bulk path exists to avoid — so for arrays the bound rides into the read and is applied where each element is decoded.

Default-constructed it is unarmed, so an existing call site keeps the behaviour it had.

Note
The range is inclusive and applied in full: an element below lo or above hi makes the decode INVALID. For an unsigned element type lo is consulted only when positive, since a varint cannot be negative.

Definition at line 2880 of file sofab.hpp.

Constructor & Destructor Documentation

◆ ElemBound() [1/2]

constexpr sofab::ElemBound::ElemBound ( )
constexprdefaultnoexcept

◆ ElemBound() [2/2]

constexpr sofab::ElemBound::ElemBound ( int64_t  low,
int64_t  high 
)
inlineconstexprnoexcept

An explicit inclusive range, armed.

Definition at line 2889 of file sofab.hpp.

Member Function Documentation

◆ of()

template<typename E >
static constexpr ElemBound sofab::ElemBound::of ( )
inlinestaticconstexprnoexcept

The bound a declared element type E implies.

Unarmed for a 64-bit type, whose range is the accumulator's own and therefore cannot be exceeded — so generated code may hand this in unconditionally and a u64/i64 array pays nothing for it.

Definition at line 2900 of file sofab.hpp.

Member Data Documentation

◆ armed

bool sofab::ElemBound::armed = false

false: no bound — the decode is unchanged.

Definition at line 2884 of file sofab.hpp.

◆ hi

int64_t sofab::ElemBound::hi = 0

Largest admissible value, inclusive.

Definition at line 2883 of file sofab.hpp.

◆ lo

int64_t sofab::ElemBound::lo = 0

Smallest admissible value, inclusive.

Definition at line 2882 of file sofab.hpp.


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