44template <typename MessageType, bool isFix = std::is_base_of<Messaging::FIX::Message, MessageType>::value>
struct HeldAdapter;
46template <
typename MessageType>
47struct HeldAdapter<MessageType, true> final :
public MessageType
49 static_assert(std::is_base_of<Messaging::FIX::Message, MessageType>::value,
"Not a message.");
51 static constexpr bool isFix =
true;
53 using SbeType =
typename MessageType::Binary;
60 : MessageType(
SbeType(data, length, version))
70template <
typename MessageType>
71struct HeldAdapter<MessageType, false> final :
public MessageType
73 static_assert(std::is_base_of<Messaging::SbeMessage, MessageType>::value,
"Not a message.");
75 static constexpr bool isFix =
false;
84 : MessageType(data, length, version)
96template <
typename,
size_t>
class MessageHolder;
106template <
typename MessageType,
size_t MaxMessageSize>
112 str +=
"MessageHolder[";
114 str +=
"BufferSize=";
149 typename MessageTypeT,
154 using SbeType =
typename details::HeldAdapter<MessageTypeT>::SbeType;
175 Messaging::fromEmptyStorage<MessagePrefix>(buffer_);
187 const unsigned char*
buffer() const noexcept
199 return header().messageSize();
232 template <
typename Callable>
234 std::forward<Callable>(callable)(std::declval<MessageType&>()), std::declval<MessageHolder&>())
236 std::forward<Callable>(callable)(
message());
303 const auto calculatedMessageSize =
message().calculateBinarySize();
305 assert(calculatedMessageSize <= MaxMessageSize);
308 return calculatedMessageSize;
351 static_assert(std::is_nothrow_default_constructible<MessageType>::value,
"MessageType must be nothrow default constructible.");
352 static_assert(std::is_nothrow_move_assignable<MessageType>::value,
"MessageType must be nothrow move assignable.");
353 static_assert(MaxMessageSize >=
sizeof(
Messaging::MessageHeader),
"MaxMessageSize template parameter is too small");
354 static_assert(MaxMessageSize >= Messaging::GetMinMessageSize<SbeType>::Size,
"The buffer can not fit the message");
356 static_assert(Messaging::IsTriviallyCopyable<MessagePrefix>::value,
"MessagePrefix must be trivially copiable.");
357 static_assert(std::is_nothrow_default_constructible<MessagePrefix>::value,
"MessagePrefix must be nothrow default constructible.");
358 static_assert(std::is_trivially_destructible<MessagePrefix>::value,
"MessagePrefix must be trivially destructible.");
370 MessageType message_;
371 alignas(MessagePrefix) Messaging::Byte buffer_[BufferSize] = {};
381template <
typename MessageType,
size_t MaxMessageSize>
398template <
typename MessageType,
size_t MaxMessageSize>
401 return stream <<
toStr(rhs);
#define ONIXS_CME_MDH_TESTING_NAMESPACE_END
#define ONIXS_CME_MDH_TESTING_NAMESPACE_BEGIN
#define ONIXS_CMEMDH_NODISCARD
Represents the length prefix preceding each message in an MDP packet.
Owns fixed-capacity storage for a prefixed CME message.
details::HeldAdapter< MessageTypeT > MessageType
Messaging::MessageSize messageSize() const noexcept
std::string toString() const
Creates a string containing the capacity, prefix, and message.
ByteSpan toNetworkBytes() noexcept
Commits the current payload size and returns the network-ready bytes.
MessageHolder(Messaging::SchemaVersion version=SbeType::Schema::Version)
Constructs an empty message for a schema version.
MessageType & message() noexcept
Provides mutable access to the stored message.
const MessageType & message() const noexcept
Provides read-only access to the stored message.
ByteSpan asSpan() const noexcept
auto operator%(Callable &&callable) &-> decltype(std::forward< Callable >(callable)(std::declval< MessageType & >()), std::declval< MessageHolder & >())
Applies a callable customization to the stored message.
Messaging::MessageSize setHeader() noexcept
Commits the current encoded payload size to the message prefix.
const MessagePrefix & header() const noexcept
Provides read-only access to the message prefix.
const unsigned char * buffer() const noexcept
Provides read-only access to the prefixed message buffer.
const MessageType * operator->() const noexcept
Provides pointer-style read-only access to the stored message.
Messaging::MessageSize bufferSize() const noexcept
Returns the committed size of the prefixed message.
MessageType * operator->() noexcept
Provides pointer-style mutable access to the stored message.
void toStr(std::string &str, const Message &message)
Serializes into a tag=value format.
constexpr MessageSize MaxMessageSize
Maximum supported message size.
MessageHeader::Version SchemaVersion
Aliases SBE-encoded data version type.
UInt16 MessageSize
Message length type.
void toStr(std::string &, Int8)
Serializes given integer into a string.
void toStr(std::string &str, const MessageHolder< MessageType, MaxMessageSize > &holder)
Appends the holder's capacity, prefix, and message to a string.
std::ostream & operator<<(std::ostream &stream, const MessageHolder< MessageType, MaxMessageSize > &rhs)
Writes the holder's capacity, prefix, and message to a stream.
std::span< const std::uint8_t > ByteSpan
Provides a non-owning read-only view over contiguous byte storage.
static constexpr bool isFix
HeldAdapter(void *data, EncodedLength length, Messaging::SbeMessage::NoInit, Messaging::SbeMessage::NoCheck) noexcept
HeldAdapter(void *data, EncodedLength length, Messaging::SchemaVersion version)
typename SbeType::EncodedLength EncodedLength
static constexpr bool isFix
HeldAdapter(void *data, EncodedLength length, Messaging::SbeMessage::NoInit, Messaging::SbeMessage::NoCheck) noexcept
HeldAdapter(void *data, EncodedLength length, Messaging::SchemaVersion version)
typename SbeType::EncodedLength EncodedLength
typename MessageType::Binary SbeType