OnixS C++ CME iLink 3 Binary Order Entry Handler 1.19.3
API Documentation
Loading...
Searching...
No Matches
NetworkMessage.h
Go to the documentation of this file.
1// Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2//
3// This software owned by Onix Solutions Limited [OnixS] and is
4// protected by copyright law and international copyright treaties.
5//
6// Access to and use of the software is governed by the terms of the applicable
7// OnixS Software Services Agreement (the Agreement) and Customer end user license
8// agreements granting a non-assignable, non-transferable and non-exclusive license
9// to use the software for it's own data processing purposes under the terms defined
10// in the Agreement.
11//
12// Except as otherwise granted within the terms of the Agreement, copying or
13// reproduction of any part of this source code or associated reference material
14// to any other location for further reproduction or redistribution, and any
15// amendments to this copyright notice, are expressly prohibited.
16//
17// Any reproduction or redistribution for sale or hiring of the Software not in
18// accordance with the terms of the Agreement is a violation of copyright law.
19//
20
21#pragma once
22
26
28
30
33{
34public:
36 NetworkMessage() noexcept
37 : data_(nullptr)
38 , size_(0)
39 {}
40
43 : data_(nullptr)
44 , size_(0)
45 {
46 assert(size >= sizeof(SimpleOpenFramingHeader));
47
48 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
49
50 assert(header->encoding() == CmeSbeEncodingType);
51 assert(header->size() <= size);
52
53#ifndef NDEBUG
54 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
55#endif
56
57 data_ = data;
58 size_ = header->size();
59 }
60
62 NetworkMessage(const void* data, size_t size)
63 : data_(nullptr)
64 , size_(0)
65 {
67 throwBinaryBlockIsTooSmall(static_cast<MessageSize>(size), sizeof(SimpleOpenFramingHeader), "SimpleOpenFramingHeader");
68
69 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
70
72 throwIncorrectEncoding(header->encoding(), data, static_cast<MessageSize>(size));
73
74 if ONIXS_ILINK3_UNLIKELY(header->size() > size)
75 throwNetPacketIsTooSmall(static_cast<MessageSize>(size), header->size());
76
77 SbeMessage(toByteBlock(toMutable(data)) + sizeof(SimpleOpenFramingHeader), header->size() - sizeof(SimpleOpenFramingHeader));
78
79 data_ = data;
80 size_ = header->size();
81 }
82
84 const void* data() const noexcept
85 {
86 return data_;
87 }
88
90 MessageSize size() const noexcept
91 {
92 return size_;
93 }
94
96 void clear() noexcept
97 {
98 *this = NetworkMessage();
99 assert(!valid());
100 }
101
103
104 bool valid() const noexcept
105 {
106 return (nullptr != data_);
107 }
108
110 SbeMessage message() const noexcept
111 {
112 assert(valid());
113
114#ifndef NDEBUG
115 SbeMessage(toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader), size_ - sizeof(SimpleOpenFramingHeader));
116#endif
117
118 return SbeMessage(
119 toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader),
121 }
122
124 std::string toString() const;
125
126private:
127 const void* data_;
128 MessageSize size_;
129};
130
133void toStr(std::string&, NetworkMessage);
134
135inline
136std::string toStr(NetworkMessage message)
137{
138 std::string res;
139 toStr(res, message);
140 return res;
141}
142
143inline std::string NetworkMessage::toString() const
144{
145 return toStr(*this);
146}
147
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_END
Definition ABI.h:144
#define ONIXS_ILINK3_LTWT_CLASS
Definition ABI.h:84
#define ONIXS_ILINK3_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:140
#define ONIXS_ILINK3_UNLIKELY(cond)
Definition Compiler.h:158
#define ONIXS_ILINK3_EXPORTED
Definition Compiler.h:145
#define ONIXS_ILINK3_UNUSED
Definition Compiler.h:155
void clear() noexcept
Blank the instance.
NetworkMessage(const void *data, size_t size, SbeMessage::NoCheck) noexcept
Constructs NetworkMessage from a data block. Performs no checks.
std::string toString() const
Serializes into a string.
NetworkMessage(const void *data, size_t size)
Constructs NetworkMessage from a data block.
NetworkMessage() noexcept
Constructs an empty instance.
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
UInt16 MessageSize
Message length type.
Definition Aliases.h:29