|
SofaBuffers C/C++ 0.12.0
API Documentation
|
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. | |
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.
std::vector<std::uint8_t> path: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.| N | Maximum number of bytes. |
| using sofab::FixedBytes< N >::size_type = std::size_t |
| using sofab::FixedBytes< N >::value_type = std::uint8_t |
|
defaultnoexcept |
Construct an empty blob.
|
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.
| init | Source bytes (excess beyond N is dropped). |
Definition at line 564 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinestaticconstexprnoexcept |
|
inlinenoexcept |
Negated operator==.
Definition at line 659 of file sofab.hpp.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
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.
| n | Requested logical length (clamped to N). |
Definition at line 613 of file sofab.hpp.
|
inlinenoexcept |