|
SofaBuffers C/C++ 0.12.0
API Documentation
|
Output stream over a buffer the caller already owns. More...
#include <sofab.hpp>
Public Member Functions | |
| OStreamView (uint8_t *buffer, size_t buflen, size_t offset=0) noexcept | |
| Construct over caller storage. | |
| OStreamView (flushCallback callback, uint8_t *buffer, size_t buflen, size_t offset=0) noexcept | |
| Construct over caller storage with a flush callback. | |
Public Member Functions inherited from sofab::OStreamImpl | |
| OStreamImpl (const OStreamImpl &)=delete | |
| Copy construction is deleted (the context owns raw buffer pointers). | |
| OStreamImpl & | operator= (const OStreamImpl &)=delete |
| Copy assignment is deleted (the context owns raw buffer pointers). | |
| OStreamImpl (OStreamImpl &&) noexcept=default | |
| Move construction (transfers the underlying context). | |
| OStreamImpl & | operator= (OStreamImpl &&) noexcept=default |
| Move assignment (transfers the underlying context). | |
| virtual | ~OStreamImpl () noexcept |
| Destructor; flushes any buffered bytes. | |
| size_t | flush () noexcept |
| Flush buffered bytes through the flush callback (if any). | |
| size_t | bytesUsed () noexcept |
| Number of bytes written to the active buffer since the last flush. | |
| const uint8_t * | data () const noexcept |
| Pointer to the start of the active encode buffer. | |
| template<typename T > | |
| Result | write (sofab_id_t id, const T &value) noexcept |
Encode a single field, deducing the wire type from T. | |
| template<typename T > | |
| Result | writeLazy (sofab_id_t id, const T &value) noexcept |
| Encode a nested message field, omitting it when all-default. | |
| Result | write (sofab_id_t id, const void *value, int32_t size) noexcept |
| Encode a raw binary blob field. | |
| template<typename T > | |
| Result | writeIf (sofab_id_t id, const T &value, bool condition) noexcept |
Encode a field only when condition is true. | |
| Result | sequenceBeginLazy (sofab_id_t id) noexcept |
| Open a nested sequence whose header is held back until it turns out to have content. | |
| Result | sequenceEnd () noexcept |
| Close the current nested sequence, letting it vanish if it got no content (MESSAGE_SPEC §2). | |
| Result | sequenceEndKeep () noexcept |
| Close the current nested sequence, keeping its frame even without content. | |
| bool | ok () const noexcept |
| Whether every write on this stream has succeeded. | |
| Error | error () const noexcept |
| The first failure this stream saw, or Error::None. | |
| Result | rejectArgument () noexcept |
| Refuse the value being encoded: latch Error::InvalidArgument. | |
Additional Inherited Members | |
Public Types inherited from sofab::OStreamImpl | |
| using | flushCallback = void(*)(std::span< const uint8_t >) |
| Callback invoked with the bytes to flush (buffer full or on flush()). | |
Protected Member Functions inherited from sofab::OStreamImpl | |
| void | onFlushCallback (size_t len) noexcept |
Invoke the user flush callback (if any) with len buffered bytes. | |
| OStreamImpl () noexcept=default | |
Static Protected Member Functions inherited from sofab::OStreamImpl | |
| static void | static_flush_callback (sofab_ostream_t *ctx, const uint8_t *data, size_t len, void *usrptr) noexcept |
C-ABI flush trampoline: forwards to onFlushCallback() via usrptr. | |
Protected Attributes inherited from sofab::OStreamImpl | |
| sofab_ostream_t | ctx_ |
| Underlying C output stream context. | |
| uint8_t * | buffer_ |
| Pointer to the active encode buffer. | |
| flushCallback | flushCallback_ {} |
| Optional user flush callback. | |
| uint8_t | failed_ = 0 |
| Sticky: first failing write's sofab_ret_t (0 = none). | |
Output stream over a buffer the caller already owns.
Neither allocates nor copies: encoding writes straight into buffer. The counterpart to OStreamInline (buffer inside the object) and OStream (buffer held by a shared_ptr) — this is the one to use when the destination already exists: a DMA or radio frame, a slot in a ring buffer, or the dst of a generated encodeTo.
The buffer must outlive the stream, and it is not restored if encoding fails: a write past buflen ends in Error::BufferFull with the bytes written so far already in place. That is the price of not staging the output elsewhere first — a caller needing all-or-nothing encodes into scratch storage and copies on success.
|
inlinenoexcept |
Construct over caller storage with a flush callback.
| callback | Invoked with buffered bytes when the buffer fills or on flush(). |
| buffer | Destination; must outlive this stream. |
| buflen | Usable size of buffer in bytes. |
| offset | Initial write offset within the buffer (default 0). |
Definition at line 1779 of file sofab.hpp.