OnixS C++ ICE Binary Order Entry Handler 1.0.0
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
31{
32public:
34 NetworkMessage() noexcept
35 : data_(nullptr)
36 , size_(0)
37 {}
38
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
53#endif
54
55 data_ = data;
56 size_ = header->size();
57 }
58
60 NetworkMessage(const void* data, size_t size)
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
76
77 data_ = data;
78 size_ = header->size();
79 }
80
82 const SimpleOpenFramingHeader* header() const noexcept
83 {
84 return reinterpret_cast<const SimpleOpenFramingHeader*>(data_);
85 }
86
88 const void* data() const noexcept
89 {
90 return data_;
91 }
92
94 MessageSize size() const noexcept
95 {
96 return size_;
97 }
98
100 void clear() noexcept
101 {
102 *this = NetworkMessage();
103 assert(!valid());
104 }
105
107
108 bool valid() const noexcept
109 {
110 return (nullptr != data_);
111 }
112
114
115 SbeMessage message() const noexcept
116 {
117 assert(valid());
118
119#ifndef NDEBUG
121#endif
122
123 return SbeMessage(
126 }
127
128private:
129 const void* data_;
130 MessageSize size_;
131};
132
135void toStr(std::string&, NetworkMessage);
136
137inline
138std::string toStr(NetworkMessage message)
139{
140 std::string res;
141 toStr(res, message);
142 return res;
143}
144
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_BEGIN
Definition ABI.h:102
#define ONIXS_ICEBOE_MESSAGING_NAMESPACE_END
Definition ABI.h:106
#define ONIXS_ICEBOE_UNUSED
Definition Compiler.h:162
#define ONIXS_ICEBOE_EXPORTED
Definition Compiler.h:153
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.
const SimpleOpenFramingHeader * header() const noexcept
const void * data() const noexcept
SbeMessage message() const noexcept
Retrieves the underlying SBE message.
ONIXS_ICEBOE_FORCEINLINE void * toMutable(const Type *ptr) noexcept
Definition Memory.h:74
std::string toStr(const FixedPointDecimal< Mantissa, Exponent > &)
Serializes a fixed-point decimal into a string.
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)
ONIXS_ICEBOE_FORCEINLINE Byte * toByteBlock(Type *ptr) noexcept
Reinterprets the pointer as a byte block one.
Definition Memory.h:86
void throwIncorrectEncoding(Messaging::UInt16 encoding, const void *data, MessageSize size)