SofaBuffers C/C++ 0.12.0
API Documentation
Loading...
Searching...
No Matches
sofab::FixedBytes< N > Class Template Reference

Fixed-capacity, heap-free byte blob of up to N bytes. More...

#include <sofab.hpp>

Public Types

using value_type = std::uint8_t
 Element type (mirrors std::vector).
 
using size_type = std::size_t
 Size type (mirrors std::vector).
 

Public Member Functions

 FixedBytes () noexcept=default
 Construct an empty blob.
 
 FixedBytes (std::initializer_list< std::uint8_t > init) noexcept
 Construct from a brace-enclosed list of bytes (clamped to N; extra bytes are dropped).
 
FixedBytes & operator= (std::initializer_list< std::uint8_t > init) noexcept
 Replace the contents from a brace-enclosed list (clamped to N; extra bytes are dropped).
 
FixedBytes & assign (std::initializer_list< std::uint8_t > init) noexcept
 Replace the contents from a brace-enclosed list (clamped to N; extra bytes are dropped).
 
std::uint8_t * data () noexcept
 Mutable pointer to the byte buffer (decode target).
 
const std::uint8_t * data () const noexcept
 Const pointer to the byte buffer.
 
std::size_t size () const noexcept
 Number of bytes currently stored.
 
bool empty () const noexcept
 True if the blob is empty.
 
void set_len (std::size_t n) noexcept
 Decode hook: set the logical length (clamped to N).
 
void clear () noexcept
 Reset to an empty blob.
 
void push_back (std::uint8_t b) noexcept
 Append one byte (no-op once at capacity N).
 
std::uint8_t & operator[] (std::size_t i) noexcept
 Access the byte at i (no bounds checking).
 
const std::uint8_t & operator[] (std::size_t i) const noexcept
 Access the byte at i (no bounds checking).
 
std::uint8_t * begin () noexcept
 Iterator to the first byte.
 
std::uint8_t * end () noexcept
 Iterator past the last byte.
 
const std::uint8_t * begin () const noexcept
 Const iterator to the first byte.
 
const std::uint8_t * end () const noexcept
 Const iterator past the last byte.
 
bool operator== (const FixedBytes &o) const noexcept
 Content equality (same logical length and bytes).
 
bool operator!= (const FixedBytes &o) const noexcept
 Negated operator==.
 

Static Public Member Functions

static constexpr std::size_t capacity () noexcept
 Maximum number of bytes (the template parameter N).
 
static constexpr std::size_t max_size () noexcept
 Alias of capacity.
 

Detailed Description

template<std::size_t N>
class sofab::FixedBytes< N >

Fixed-capacity, heap-free byte blob of up to N bytes.

The embedded-friendly counterpart of std::vector<std::uint8_t> for blob fields, mirroring FixedString for bytes. The payload lives in an inline std::array, so an instance allocates nothing and never throws (overflow clamps to N). Because the buffer never moves, an instance is a valid address-stable decode target for the deferred IStreamImpl decoder.

A logical length (size, <= N) is tracked separately from the capacity N: a blob shorter than its schema maxlen occupies only size bytes on the wire. This is exactly why the type cannot be a plain std::array<std::uint8_t,N> (always length N) and must not reintroduce the heap of std::vector.

Generator integration contract
Generated code mirrors the std::vector<std::uint8_t> path:
  • encode passes data / size to the blob write, byte-for-byte identical to the same-content vector;
  • decode emits b.set_len(_size); if (_size) is.read(b); — set_len fixes the logical length (clamped to N) before the read binds the inline buffer over size bytes. Binding the container this way (not a bare is.read(b.data(), _size)) lets the decoder reject an over-N wire length as INVALID per MESSAGE_SPEC §7.1 instead of truncating it.
Template Parameters
NMaximum number of bytes.

Definition at line 540 of file sofab.hpp.

Member Typedef Documentation

◆ size_type

template<std::size_t N>
using sofab::FixedBytes< N >::size_type = std::size_t

Size type (mirrors std::vector).

Definition at line 549 of file sofab.hpp.

◆ value_type

template<std::size_t N>
using sofab::FixedBytes< N >::value_type = std::uint8_t

Element type (mirrors std::vector).

Definition at line 547 of file sofab.hpp.

Constructor & Destructor Documentation

◆ FixedBytes() [1/2]

template<std::size_t N>
sofab::FixedBytes< N >::FixedBytes ( )
defaultnoexcept

Construct an empty blob.

◆ FixedBytes() [2/2]

template<std::size_t N>
sofab::FixedBytes< N >::FixedBytes ( std::initializer_list< std::uint8_t >  init)
inlinenoexcept

Construct from a brace-enclosed list of bytes (clamped to N; extra bytes are dropped).

Providing this constructor makes FixedBytes a non-aggregate, so a brace-init such as b = {1, 2, 3} routes through here and sets size — it cannot silently fill the buffer while leaving the logical length at zero.

Parameters
initSource bytes (excess beyond N is dropped).

Definition at line 564 of file sofab.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ assign()

template<std::size_t N>
FixedBytes & sofab::FixedBytes< N >::assign ( std::initializer_list< std::uint8_t >  init)
inlinenoexcept

Replace the contents from a brace-enclosed list (clamped to N; extra bytes are dropped).

Definition at line 576 of file sofab.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/2]

template<std::size_t N>
const std::uint8_t * sofab::FixedBytes< N >::begin ( ) const
inlinenoexcept

Const iterator to the first byte.

Definition at line 637 of file sofab.hpp.

◆ begin() [2/2]

template<std::size_t N>
std::uint8_t * sofab::FixedBytes< N >::begin ( )
inlinenoexcept

Iterator to the first byte.

Definition at line 633 of file sofab.hpp.

◆ capacity()

template<std::size_t N>
static constexpr std::size_t sofab::FixedBytes< N >::capacity ( )
inlinestaticconstexprnoexcept

Maximum number of bytes (the template parameter N).

Definition at line 600 of file sofab.hpp.

Here is the call graph for this function:

◆ clear()

template<std::size_t N>
void sofab::FixedBytes< N >::clear ( )
inlinenoexcept

Reset to an empty blob.

Definition at line 616 of file sofab.hpp.

◆ data() [1/2]

template<std::size_t N>
const std::uint8_t * sofab::FixedBytes< N >::data ( ) const
inlinenoexcept

Const pointer to the byte buffer.

Definition at line 593 of file sofab.hpp.

◆ data() [2/2]

template<std::size_t N>
std::uint8_t * sofab::FixedBytes< N >::data ( )
inlinenoexcept

Mutable pointer to the byte buffer (decode target).

Definition at line 591 of file sofab.hpp.

◆ empty()

template<std::size_t N>
bool sofab::FixedBytes< N >::empty ( ) const
inlinenoexcept

True if the blob is empty.

Definition at line 598 of file sofab.hpp.

◆ end() [1/2]

template<std::size_t N>
const std::uint8_t * sofab::FixedBytes< N >::end ( ) const
inlinenoexcept

Const iterator past the last byte.

Definition at line 639 of file sofab.hpp.

◆ end() [2/2]

template<std::size_t N>
std::uint8_t * sofab::FixedBytes< N >::end ( )
inlinenoexcept

Iterator past the last byte.

Definition at line 635 of file sofab.hpp.

◆ max_size()

template<std::size_t N>
static constexpr std::size_t sofab::FixedBytes< N >::max_size ( )
inlinestaticconstexprnoexcept

Alias of capacity.

Definition at line 602 of file sofab.hpp.

Here is the call graph for this function:

◆ operator!=()

template<std::size_t N>
bool sofab::FixedBytes< N >::operator!= ( const FixedBytes< N > &  o) const
inlinenoexcept

Negated operator==.

Definition at line 659 of file sofab.hpp.

Here is the call graph for this function:

◆ operator=()

template<std::size_t N>
FixedBytes & sofab::FixedBytes< N >::operator= ( std::initializer_list< std::uint8_t >  init)
inlinenoexcept

Replace the contents from a brace-enclosed list (clamped to N; extra bytes are dropped).

Definition at line 570 of file sofab.hpp.

Here is the call graph for this function:

◆ operator==()

template<std::size_t N>
bool sofab::FixedBytes< N >::operator== ( const FixedBytes< N > &  o) const
inlinenoexcept

Content equality (same logical length and bytes).

Definition at line 642 of file sofab.hpp.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<std::size_t N>
const std::uint8_t & sofab::FixedBytes< N >::operator[] ( std::size_t  i) const
inlinenoexcept

Access the byte at i (no bounds checking).

Definition at line 630 of file sofab.hpp.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<std::size_t N>
std::uint8_t & sofab::FixedBytes< N >::operator[] ( std::size_t  i)
inlinenoexcept

Access the byte at i (no bounds checking).

Definition at line 628 of file sofab.hpp.

Here is the call graph for this function:

◆ push_back()

template<std::size_t N>
void sofab::FixedBytes< N >::push_back ( std::uint8_t  b)
inlinenoexcept

Append one byte (no-op once at capacity N).

Definition at line 619 of file sofab.hpp.

Here is the call graph for this function:

◆ set_len()

template<std::size_t N>
void sofab::FixedBytes< N >::set_len ( std::size_t  n)
inlinenoexcept

Decode hook: set the logical length (clamped to N).

Called by generated decode before binding the buffer, so size reports the field length and data over that many bytes is the fill target.

Parameters
nRequested logical length (clamped to N).

Definition at line 613 of file sofab.hpp.

Here is the call graph for this function:

◆ size()

template<std::size_t N>
std::size_t sofab::FixedBytes< N >::size ( ) const
inlinenoexcept

Number of bytes currently stored.

Definition at line 596 of file sofab.hpp.


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