OnixS C++ CME MDP Premium Market Data Handler 5.11.1
Users' manual and API documentation
Loading...
Searching...
No Matches
MessageHolder< MessageTypeT, MaxMessageSize > Class Template Reference

#include <OnixS/CME/MDH/testing/MessageHolder.h>

Public Types

enum  : Messaging::MessageSize
using MessageType = details::HeldAdapter<MessageTypeT>

Public Member Functions

 MessageHolder (Messaging::SchemaVersion version=SbeType::Schema::Version)
const unsigned char * buffer () const noexcept
Messaging::MessageSize bufferSize () const noexcept
MessageType & message () noexcept
const MessageType & message () const noexcept
template<typename Callable>
auto operator% (Callable &&callable) &-> decltype(std::forward< Callable >(callable)(std::declval< MessageType & >()), std::declval< MessageHolder & >())
Messaging::MessageSize messageSize () const noexcept
MessageType * operator-> () noexcept
const MessageType * operator-> () const noexcept
const MessageType & operator* () const noexcept
MessageType & operator* () noexcept
const MessagePrefix & header () const noexcept
Messaging::MessageSize setHeader () noexcept
ByteSpan toNetworkBytes () noexcept
ByteSpan asSpan () const noexcept
std::string toString () const

Detailed Description

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
class OnixS::CME::MDH::Test::MessageHolder< MessageTypeT, MaxMessageSize >

The storage contains a MessagePrefix followed by an SBE-encoded message. Both binary SBE message types and tag-based FIX message types are supported; the latter provide a tag-based view of the same SBE payload.

The message wrapper, buffer pointer, and direct references returned by this class refer to the holder's owned storage and remain valid until the holder is destroyed. Views of repeating-group entries have a shorter lifetime: growing any earlier repeating group can relocate and invalidate them, so reacquire entry views after structural message changes. The holder is therefore neither copyable nor movable.

The message prefix does not track mutations automatically. Call setHeader() after populating or changing the message and before consuming the encoded buffer.

Template Parameters
MessageTypeTBinary SBE message type or tag-based FIX message type to store.
MaxMessageSizeMaximum encoded message size in bytes, excluding the message prefix. The value must accommodate the message's minimum encoded size and must not exceed Messaging::MaxMessageSize.

Definition at line 152 of file MessageHolder.h.

Member Typedef Documentation

◆ MessageType

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
using MessageType = details::HeldAdapter<MessageTypeT>

Message wrapper bound to the holder's encoded payload storage.

Definition at line 161 of file MessageHolder.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
anonymous enum : Messaging::MessageSize

Total buffer capacity in bytes, including the message prefix.

Enumerator
BufferSize MaxMessageSize + sizeof(MessagePrefix) 

Definition at line 164 of file MessageHolder.h.

Constructor & Destructor Documentation

◆ MessageHolder()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
MessageHolder ( Messaging::SchemaVersion version = SbeType::Schema::Version)
inlineexplicit

Constructs an empty message for a schema version.

The message wrapper is initialized over the owned payload storage. The prefix initially reports only its own size because no payload size has been committed; call setHeader() after populating the message.

Parameters
versionSchema version used to initialize the encoded message.

Definition at line 173 of file MessageHolder.h.

Member Function Documentation

◆ asSpan()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
ByteSpan asSpan ( ) const
inlinenoexcept

Returns the currently committed prefixed message bytes.

Returns
Read-only view of the first bufferSize() bytes in the owned buffer.
Note
This method does not refresh the message prefix. Call setHeader() or toNetworkBytes() after mutations that change the encoded payload size.

Definition at line 330 of file MessageHolder.h.

◆ buffer()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
const unsigned char * buffer ( ) const
inlinenoexcept

Provides read-only access to the prefixed message buffer.

Returns
Pointer to the first byte of the owned buffer. The first bufferSize() bytes contain the committed prefixed message.

Definition at line 187 of file MessageHolder.h.

◆ bufferSize()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
Messaging::MessageSize bufferSize ( ) const
inlinenoexcept

Returns the committed size of the prefixed message.

Returns
Value stored in the message prefix, in bytes, including the prefix itself.

Definition at line 197 of file MessageHolder.h.

◆ header()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
const MessagePrefix & header ( ) const
inlinenoexcept

Provides read-only access to the message prefix.

Returns
Prefix stored at the start of the owned buffer.

Definition at line 290 of file MessageHolder.h.

◆ message() [1/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
const MessageType & message ( ) const
inlinenoexcept

Provides read-only access to the stored message.

Returns
Message wrapper backed by the owned payload storage.

Definition at line 216 of file MessageHolder.h.

◆ message() [2/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
MessageType & message ( )
inlinenoexcept

Provides mutable access to the stored message.

Returns
Message wrapper backed by the owned payload storage.
Note
Call setHeader() after a mutation that changes the encoded size.

Definition at line 207 of file MessageHolder.h.

◆ messageSize()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
Messaging::MessageSize messageSize ( ) const
inlinenoexcept

Returns the committed payload size.

Returns
Encoded message size derived from the message prefix, in bytes, excluding the prefix itself.

Definition at line 245 of file MessageHolder.h.

◆ operator%()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
template<typename Callable>
auto operator% ( Callable && callable) & -> decltype( std::forward< Callable >(callable)(std::declval< MessageType & >()), std::declval< MessageHolder & >())
inline

Applies a callable customization to the stored message.

Template Parameters
CallableCallable type invoked with the mutable underlying message.
Parameters
callableCallable to invoke immediately.
Returns
This holder, allowing multiple customizations to be chained.
Note
Use the infix form holder % callable. The holder must be a named, mutable object; temporary and const holders are not supported.
The callable's return value is ignored. Mutable callables are supported.
Warning
Do not retain repeating-group entry views obtained by callable. Growing any earlier repeating group can relocate and invalidate them; acquire a fresh view after structural message changes.
Exceptions
Anyexception thrown by the callable.

Definition at line 233 of file MessageHolder.h.

◆ operator*() [1/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
const MessageType & operator* ( ) const
inlinenoexcept

Provides read-only reference-style access to the stored message.

Returns
Message wrapper backed by the owned payload storage.

Definition at line 271 of file MessageHolder.h.

◆ operator*() [2/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
MessageType & operator* ( )
inlinenoexcept

Provides mutable reference-style access to the stored message.

Returns
Message wrapper backed by the owned payload storage.
Note
Call setHeader() after a mutation that changes the encoded size.

Definition at line 281 of file MessageHolder.h.

◆ operator->() [1/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
const MessageType * operator-> ( ) const
inlinenoexcept

Provides pointer-style read-only access to the stored message.

Returns
Pointer to the message wrapper backed by the owned payload storage.

Definition at line 262 of file MessageHolder.h.

◆ operator->() [2/2]

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
MessageType * operator-> ( )
inlinenoexcept

Provides pointer-style mutable access to the stored message.

Returns
Pointer to the message wrapper backed by the owned payload storage.
Note
Call setHeader() after a mutation that changes the encoded size.

Definition at line 254 of file MessageHolder.h.

◆ setHeader()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
Messaging::MessageSize setHeader ( )
inlinenoexcept

Commits the current encoded payload size to the message prefix.

Returns
Committed payload size in bytes, excluding the message prefix.
Precondition
The calculated payload size must not exceed MaxMessageSize.
Note
Builds with assertions enabled diagnose a payload that exceeds the holder's capacity.

Definition at line 301 of file MessageHolder.h.

◆ toNetworkBytes()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
ByteSpan toNetworkBytes ( )
inlinenoexcept

Commits the current payload size and returns the network-ready bytes.

Returns
Read-only view of the message prefix and encoded payload.
Precondition
The calculated payload size must not exceed MaxMessageSize.
Note
The returned view refers to the holder's owned storage and remains valid until the holder is destroyed.

Definition at line 318 of file MessageHolder.h.

◆ toString()

template<typename MessageTypeT, size_t MaxMessageSize = Messaging::MaxMessageSize>
std::string toString ( ) const
inline

Creates a string containing the capacity, prefix, and message.

Returns
Human-readable representation of the holder.
Exceptions
Anyexception thrown while allocating or formatting the result.

Definition at line 340 of file MessageHolder.h.