|
SofaBuffers C++ 0.12.0
Pure-C++20 SofaBuffers — API Documentation
|
Bundles a message with an inline output buffer sized for it. More...
#include <sofab.hpp>
Public Member Functions | |
| OStreamObject () noexcept=default | |
| Construct with no flush callback. | |
| OStreamObject (typename OStreamImpl::flushCallback callback) noexcept | |
| Construct with a flush callback. | |
| MessageType * | operator-> () noexcept |
Reach the wrapped message, so its fields are obj->field. | |
| const MessageType * | operator-> () const noexcept |
Reach the wrapped message, so its fields are obj->field. | |
| OStreamImpl::Result | serialize () noexcept |
| Serialise the wrapped message into the inline buffer and flush. | |
Public Member Functions inherited from sofab::OStreamInline< N, Offset > | |
| OStreamInline () noexcept | |
| Construct with no flush callback; overflow returns Error::BufferFull. | |
| OStreamInline (flushCallback callback) noexcept | |
| Construct with a flush callback. | |
Public Member Functions inherited from sofab::OStreamImpl | |
| OStreamImpl (const OStreamImpl &)=delete | |
| OStreamImpl & | operator= (const OStreamImpl &)=delete |
| OStreamImpl (OStreamImpl &&) noexcept=default | |
| OStreamImpl & | operator= (OStreamImpl &&) noexcept=default |
| virtual | ~OStreamImpl () noexcept |
| Flushes any buffered bytes through the callback before destruction. | |
| size_t | flush () noexcept |
| Hand any buffered bytes to the flush callback and rewind the cursor. | |
| size_t | bytesUsed () const noexcept |
| const uint8_t * | data () const noexcept |
| bool | ok () const noexcept |
| Whether every write on this stream has succeeded. | |
| Error | error () const noexcept |
| The code behind ok, latched first-failure-wins. | |
| Result | rejectArgument () noexcept |
| Refuse the value being encoded: latch Error::InvalidArgument. | |
| template<typename T > | |
| Result | write (sofab::id fieldId, const T &value) noexcept |
| Write a field, dispatching on the value's type. | |
| template<typename T > requires std::is_base_of_v<OStreamMessage, T> | |
| Result | writeLazy (sofab::id fieldId, const T &value) noexcept |
| Write a nested message field, omitting it when it is all-default. | |
| Result | write (sofab::id fieldId, const void *value, int32_t size) noexcept |
| Write a raw byte blob field. | |
| template<typename T > | |
| Result | writeIf (sofab::id fieldId, const T &value, bool condition) noexcept |
Write a field only when condition holds. | |
| Result | sequenceBeginLazy (sofab::id fieldId) noexcept |
| Open a nested sub-message whose header is held back until the sub-message turns out to have content. | |
| Result | sequenceEnd () noexcept |
| Close the most recently opened sub-message, letting it vanish if it received no content. | |
| Result | sequenceEndKeep () noexcept |
| Close the most recently opened sub-message, keeping its frame even when it received no content. | |
Additional Inherited Members | |
Public Types inherited from sofab::OStreamImpl | |
| using | flushCallback = std::function< void(std::span< const uint8_t >)> |
| Callback invoked with a span of finished bytes whenever the buffer flushes. | |
Protected Member Functions inherited from sofab::OStreamImpl | |
| OStreamImpl () noexcept=default | |
| Construct an unattached stream; a derived class must call initBuffer. | |
| Error | latch (Error e) noexcept |
| Record a failure in the sticky verdict and hand it straight back. | |
| void | initBuffer (uint8_t *buffer, size_t buflen, size_t offset) noexcept |
| Point the stream at a buffer and position the write cursor. | |
| Error | pushByte (uint8_t b) noexcept |
| Append a single byte, flushing first if the buffer is full. | |
| Error | pushBytes (const uint8_t *data, size_t len) noexcept |
| Append a run of bytes. | |
| Error | putVarint (uint64_t v) noexcept |
| Encode a value as a varint and append it to the buffer. | |
| Error | putSequenceEnd () noexcept |
| Write the sequence-end marker (§4.9) — id 0, wire type 7. | |
| Error | commitPending () noexcept |
| Write out the held-back sequence headers, outermost first. | |
| Error | beforeContent () noexcept |
| Commit any held-back sequence run before writing content. | |
| Error | writeScalar (sofab::id fieldId, Wire type, uint64_t value) noexcept |
| Write a scalar field: header varint plus one value varint, in a single bulk write. | |
| Error | writeFixlen (sofab::id fieldId, Fix ft, const uint8_t *data, size_t len) noexcept |
| Write a length-prefixed field (string, blob or other fixlen payload). | |
| template<std::floating_point F> | |
| Error | writeFloatScalar (sofab::id fieldId, F value) noexcept |
| Write a single float or double as a little-endian fixlen field. | |
| template<typename E > requires (std::integral<E> || std::is_enum_v<E>) | |
| Error | writeIntArray (sofab::id fieldId, std::span< const E > elems) noexcept |
| Write an array of integers as a count-prefixed run of varints. | |
| template<std::floating_point F> | |
| Error | writeFloatArray (sofab::id fieldId, std::span< const F > elems) noexcept |
| Write an array of floats or doubles as a count-prefixed fixlen array. | |
Static Protected Member Functions inherited from sofab::OStreamImpl | |
| static size_t | encodeVarint (uint8_t *out, uint64_t v) noexcept |
| Encode an unsigned value as a base-128 varint. | |
| static size_t | encodeVarintPadded (uint8_t *out, uint64_t v) noexcept |
| Encode a varint into a destination with a full varint window. | |
| static constexpr uint64_t | headerWord (sofab::id fieldId, Wire w) noexcept |
| Compose a field header word: the id in the high bits, the wire type in the low three (§4.1). | |
| static constexpr uint64_t | fixlenWord (uint64_t len, Fix ft) noexcept |
| Compose a fixlen word: the payload length (or element size) in the high bits, the subtype in the low three (§4.6, §4.8). | |
Protected Attributes inherited from sofab::OStreamImpl | |
| uint8_t * | buffer_ = nullptr |
| Start of the active buffer. | |
| uint8_t * | cursor_ = nullptr |
| Current write position. | |
| uint8_t * | end_ = nullptr |
| One past the end of the buffer. | |
| size_t | offset_ = 0 |
| Start offset of the current installation (§5.1). | |
| flushCallback | flushCallback_ |
| Invoked when the buffer fills; may be empty. | |
| size_t | seqDepth_ = 0 |
| Number of currently-open nested sequences (§4.9 MAX_DEPTH). | |
| PendingRun | pending_ |
| Error | failure_ = Error::None |
| Sticky first failure of this stream (see ok, error). | |
| bool | installed_ = false |
| Set by initBuffer, cleared right before a flush callback runs. | |
Bundles a message with an inline output buffer sized for it.
Combines an OStreamInline buffer with an instance of MessageType, so a message can be populated through operator-> and then encoded in one serialize call without managing a separate stream and buffer.
| MessageType | A type satisfying sofab::OutputMessage. |
| N | Buffer capacity in bytes; defaults to MessageType::_maxSize. |
| Offset | Number of leading bytes to reserve before the cursor. |
|
defaultnoexcept |
Construct with no flush callback.
|
inlineexplicitnoexcept |
|
inlinenoexcept |
Reach the wrapped message, so its fields are obj->field.
operator-> is re-applied to what it returns until a pointer comes back, so this has to hand out a pointer to the message: returning a reference to a type that has no operator-> of its own is not a member access at all, it is a compile error at every use.
|
inlinenoexcept |
Reach the wrapped message, so its fields are obj->field.
operator-> is re-applied to what it returns until a pointer comes back, so this has to hand out a pointer to the message: returning a reference to a type that has no operator-> of its own is not a member access at all, it is a compile error at every use.
|
inlinenoexcept |
Serialise the wrapped message into the inline buffer and flush.