OnixS C++ ICE Binary Order Entry Handler 1.1.1
API Documentation
Loading...
Searching...
No Matches
NetworkMessage Class Reference

Public Member Functions

 NetworkMessage () noexcept
 NetworkMessage (const void *data, size_t size, SbeMessage::NoCheck) noexcept
 NetworkMessage (const void *data, size_t size)
const SimpleOpenFramingHeaderheader () const noexcept
const void * data () const noexcept
MessageSize size () const noexcept
void clear () noexcept
bool valid () const noexcept
SbeMessage message () const noexcept
std::string toString () const

Detailed Description

Definition at line 30 of file NetworkMessage.h.

Constructor & Destructor Documentation

◆ NetworkMessage() [1/3]

NetworkMessage ( )
inlinenoexcept

Constructs an empty instance.

Definition at line 34 of file NetworkMessage.h.

35 : data_(nullptr)
36 , size_(0)
37 {}

◆ NetworkMessage() [2/3]

NetworkMessage ( const void * data,
size_t size,
SbeMessage::NoCheck  )
inlinenoexcept

Constructs NetworkMessage from a data block. Performs no checks.

Definition at line 40 of file NetworkMessage.h.

41 : data_(nullptr)
42 , size_(0)
43 {
44 assert(size >= sizeof(SimpleOpenFramingHeader));
45
46 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
47
48 assert(header->encoding() == SbeEncodingType);
49 assert(header->size() <= size);
50
51#ifndef NDEBUG
52 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
53#endif
54
55 data_ = data;
56 size_ = header->size();
57 }
ONIXS_ICEBOE_FORCEINLINE void * toMutable(const Type *ptr) noexcept
Definition Memory.h:74
ONIXS_ICEBOE_FORCEINLINE Byte * toByteBlock(Type *ptr) noexcept
Reinterprets the pointer as a byte block one.
Definition Memory.h:86

◆ NetworkMessage() [3/3]

NetworkMessage ( const void * data,
size_t size )
inline

Constructs NetworkMessage from a data block.

Definition at line 60 of file NetworkMessage.h.

61 : data_(nullptr)
62 , size_(0)
63 {
64 if ONIXS_ICEBOE_UNLIKELY(size < sizeof(SimpleOpenFramingHeader))
65 throwBinaryBlockIsTooSmall(static_cast<MessageSize>(size), sizeof(SimpleOpenFramingHeader), "SimpleOpenFramingHeader");
66
67 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
68
69 if ONIXS_ICEBOE_UNLIKELY(header->encoding() != SbeEncodingType)
70 throwIncorrectEncoding(header->encoding(), data, static_cast<MessageSize>(size));
71
72 if ONIXS_ICEBOE_UNLIKELY(header->size() > size)
73 throwNetPacketIsTooSmall(static_cast<MessageSize>(size), header->size());
74
75 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
76
77 data_ = data;
78 size_ = header->size();
79 }
void throwBinaryBlockIsTooSmall(MessageSize actual, MessageSize required)
Raises an exception when the given binary block is too small.
UInt16 MessageSize
Message length type.
Definition Aliases.h:29
void throwNetPacketIsTooSmall(MessageSize actual, MessageSize required)
void throwIncorrectEncoding(Messaging::UInt16 encoding, const void *data, MessageSize size)

Member Function Documentation

◆ clear()

void clear ( )
inlinenoexcept

Blank the instance.

Definition at line 100 of file NetworkMessage.h.

101 {
102 *this = NetworkMessage();
103 assert(!valid());
104 }

◆ data()

const void * data ( ) const
inlinenoexcept

Definition at line 88 of file NetworkMessage.h.

89 {
90 return data_;
91 }

◆ header()

const SimpleOpenFramingHeader * header ( ) const
inlinenoexcept

Definition at line 82 of file NetworkMessage.h.

83 {
84 return reinterpret_cast<const SimpleOpenFramingHeader*>(data_);
85 }

◆ message()

SbeMessage message ( ) const
inlinenoexcept

Retrieves the underlying SBE message.

Definition at line 115 of file NetworkMessage.h.

116 {
117 assert(valid());
118
119#ifndef NDEBUG
120 SbeMessage(toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader), size_ - sizeof(SimpleOpenFramingHeader));
121#endif
122
123 return SbeMessage(
124 toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader),
125 size_ - sizeof(SimpleOpenFramingHeader), SbeMessage::NoCheck());
126 }

◆ size()

MessageSize size ( ) const
inlinenoexcept

Definition at line 94 of file NetworkMessage.h.

95 {
96 return size_;
97 }

◆ toString()

std::string toString ( ) const
inline

Serializes into a string.

Definition at line 148 of file NetworkMessage.h.

149{
150 return toStr(*this);
151}
std::string toStr(Order::PriceOptional value)
Definition Order.cpp:34

◆ valid()

bool valid ( ) const
inlinenoexcept
Returns
true if the instance refers to a valid packet, otherwise - false.

Definition at line 108 of file NetworkMessage.h.

109 {
110 return (nullptr != data_);
111 }