OnixS C++ CME iLink 3 Binary Order Entry Handler 1.18.9
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:
38 , size_(0)
39 {}
40
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)
64 , size_(0)
65 {
66 if ONIXS_ILINK3_UNLIKELY(size < sizeof(SimpleOpenFramingHeader))
67 throwBinaryBlockIsTooSmall(static_cast<MessageSize>(size), sizeof(SimpleOpenFramingHeader), "SimpleOpenFramingHeader");
68
69 const SimpleOpenFramingHeader* const header = reinterpret_cast<const SimpleOpenFramingHeader*>(data);
70
71 if ONIXS_ILINK3_UNLIKELY(header->encoding() != CmeSbeEncodingType)
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 ONIXS_ILINK3_NOTHROW
85 {
86 return data_;
87 }
88
91 {
92 return size_;
93 }
94
97 {
98 *this = NetworkMessage();
99 assert(!valid());
100 }
101
103
105 {
106 return (ONIXS_ILINK3_NULLPTR != data_);
107 }
108
110
112 {
113 assert(valid());
114
115#ifndef NDEBUG
116 SbeMessage(toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader), size_ - sizeof(SimpleOpenFramingHeader));
117#endif
118
119 return SbeMessage(
120 toByteBlock(toMutable(data_)) + sizeof(SimpleOpenFramingHeader),
122 }
123
124private:
125 const void* data_;
126 MessageSize size_;
127};
128
131void toStr(std::string&, const NetworkMessage&);
132
133inline
134std::string toStr(const NetworkMessage& message)
135{
136 std::string res;
137 toStr(res, message);
138 return res;
139}
140
#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_NULLPTR
Definition Compiler.h:182
#define ONIXS_ILINK3_EXPORTED
Definition Compiler.h:175
#define ONIXS_ILINK3_UNUSED
Definition Compiler.h:201
#define ONIXS_ILINK3_NOTHROW
Definition Compiler.h:176
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.
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