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

Self-contained encoder that owns a message and an inline buffer. More...

#include <sofab.hpp>

Inheritance diagram for sofab::OStreamObject< MessageType, N, Offset >:
[legend]
Collaboration diagram for sofab::OStreamObject< MessageType, N, Offset >:
[legend]

Public Member Functions

 OStreamObject () noexcept=default
 Construct with no flush callback.
 
 OStreamObject (OStreamImpl::flushCallback callback) noexcept
 Construct with a flush callback.
 
MessageType & operator-> () noexcept
 Member-access to the owned message (e.g. obj->field = ...).
 
OStreamImpl::Result serialize () noexcept
 Serialize the owned message and flush.
 
- Public Member Functions inherited from sofab::OStreamInline< N, Offset >
 OStreamInline () noexcept
 Construct with no flush callback.
 
 OStreamInline (flushCallback callback) noexcept
 Construct 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).
 

Detailed Description

template<OutputMessage MessageType, size_t N = max_size_v<MessageType>, size_t Offset = 0>
class sofab::OStreamObject< MessageType, N, Offset >

Self-contained encoder that owns a message and an inline buffer.

Bundles a OStreamMessage instance with an OStreamInline buffer sized from the message's worst-case size, so a message can be populated and encoded in one object.

Template Parameters
MessageTypeAn OutputMessage type.
NBuffer size in bytes (defaults to the message's MAX_SIZE, or its deprecated _maxSize).
OffsetInitial write offset within the buffer.

Definition at line 1867 of file sofab.hpp.

Constructor & Destructor Documentation

◆ OStreamObject() [1/2]

template<OutputMessage MessageType, size_t N = max_size_v<MessageType>, size_t Offset = 0>
sofab::OStreamObject< MessageType, N, Offset >::OStreamObject ( )
defaultnoexcept

Construct with no flush callback.

◆ OStreamObject() [2/2]

template<OutputMessage MessageType, size_t N = max_size_v<MessageType>, size_t Offset = 0>
sofab::OStreamObject< MessageType, N, Offset >::OStreamObject ( OStreamImpl::flushCallback  callback)
inlinenoexcept

Construct with a flush callback.

Parameters
callbackInvoked with buffered bytes when the buffer fills or on flush().

Definition at line 1881 of file sofab.hpp.

Here is the call graph for this function:

Member Function Documentation

◆ operator->()

template<OutputMessage MessageType, size_t N = max_size_v<MessageType>, size_t Offset = 0>
MessageType & sofab::OStreamObject< MessageType, N, Offset >::operator-> ( )
inlinenoexcept

Member-access to the owned message (e.g. obj->field = ...).

Definition at line 1886 of file sofab.hpp.

◆ serialize()

template<OutputMessage MessageType, size_t N = max_size_v<MessageType>, size_t Offset = 0>
OStreamImpl::Result sofab::OStreamObject< MessageType, N, Offset >::serialize ( )
inlinenoexcept

Serialize the owned message and flush.

Returns
The encode OStreamImpl::Result.

Definition at line 1895 of file sofab.hpp.

Here is the call graph for this function:

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