OnixS C++ HKEX OMD-C Handler 1.0.0
API documentation
Loading...
Searching...
No Matches
BinaryMessage.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
23#include <cassert>
24
25#include <OnixS/HKEX/MarketData/Omdc/Export.h>
30
31namespace OnixS
32{
33 namespace HKEX
34 {
35 namespace MarketData
36 {
37 namespace Omdc
38 {
40 template <class FieldValue>
42 {
43 static FieldValue extract(const void* p) ONIXS_HKEX_OMDC_NOTHROW
44 {
46 }
47 };
48
53 template <class Block, class BlockSize>
55 {
58 const Block& block() const
60 {
61 return *static_cast<const Block*>(this);
62 }
63
64 protected:
66 template <class SubMessage>
67 const SubMessage submessage(BlockSize offset, BlockSize size) const
69 {
70 assert(block().binarySize() >= (offset + size));
71
72 return
73 SubMessage(advanceByBytes(block().binary(), offset), size);
74 }
75
77 template <class FieldValue>
78 FieldValue ordinary(BlockSize offset) const
80 {
81 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
82
83 return OrdinaryExtractor<FieldValue>::extract(advanceByBytes(block().binary(), offset));
84 }
85
87 template <class FieldValue>
88 const FieldValue& ordinaryRef(BlockSize offset) const
90 {
91 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
92
93 return
94 *static_cast <const FieldValue*>(advanceByBytes(block().binary(), offset));
95 }
96
101 template <class Enumeration>
102 typename Enumeration::Enum enumeration(BlockSize offset) const
104 {
105 typedef typename Enumeration::Base Base;
106
107 typedef typename Enumeration::Enum Enum;
108
109 return static_cast<Enum>(ordinary<Base>(offset));
110 }
111
116 template <BlockSize Size>
117 StrRef fixedStr(BlockSize offset) const
119 {
120 typedef Char Str[Size];
121
122 const Str& str = ordinaryRef<Str>(offset);
123
124 return StrRef(str, strnlen(str, Size));
125 }
126 };
127
129 class ONIXS_HKEX_OMDC_API BinaryMessage : public BinaryFields<BinaryMessage, MessageSize>
130 {
131 const void* data_;
132 MessageSize size_;
133
134 public:
137
142 , size_(0)
143 {
144 }
145
148 const void* data,
149 MessageSize size)
151 : data_(data)
152 , size_(size)
153 {
154 }
155
158 const BinaryMessage& other)
160 : data_(other.data_)
161 , size_(other.size_)
162 {
163 }
164
167 operator bool() const
169 {
170 return (ONIXS_HKEX_OMDC_NULLPTR != data_);
171 }
172
174 const void* binary() const
176 {
177 return data_;
178 }
179
183 {
184 return size_;
185 }
186
189 operator =(
190 const BinaryMessage& other)
192 {
193 if (this == &other)
194 return *this;
195
196 data_ = other.data_;
197 size_ = other.size_;
198
199 return *this;
200 }
201
202#if defined(ONIXS_HKEX_OMDC_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_HKEX_OMDC_COMPILER_CXX_RVALUE_REFERENCES
203
206 : data_(std::move(other.data_))
207 , size_(std::move(other.size_))
208 {
209 }
210
211 BinaryMessage&
212 operator=(
213 BinaryMessage&& other)
215 {
216 if (this == &other)
217 return *this;
218
219 data_ = std::move(other.data_);
220 size_ = std::move(other.size_);
221
222 return *this;
223 }
224#endif
225
226 };
227
228 ONIXS_HKEX_OMDC_API
231 void throwIncorrectSize(const std::string& messageName, MessageSize receivedSize, MessageSize expectedSize);
232
233 }
234 }
235 }
236}
#define ONIXS_HKEX_OMDC_EXPLICIT
Definition Compiler.h:170
#define ONIXS_HKEX_OMDC_COLDPATH
Definition Compiler.h:181
#define ONIXS_HKEX_OMDC_NOTHROW
Definition Compiler.h:169
#define ONIXS_HKEX_OMDC_NULLPTR
Definition Compiler.h:175
#define ONIXS_HKEX_OMDC_NORETURN
Definition Compiler.h:177
Exposes base services to access fields stored in little Endian block of memory.
Enumeration::Enum enumeration(BlockSize offset) const noexcept
Returns value of a field by its offset.
const FieldValue & ordinaryRef(BlockSize offset) const noexcept
Returns value of a field by its offset.
StrRef fixedStr(BlockSize offset) const noexcept
Provides access to string field by its offset.
const SubMessage submessage(BlockSize offset, BlockSize size) const noexcept
Returns sub message.
FieldValue ordinary(BlockSize offset) const noexcept
Returns value of a field by its offset.
Encapsulates services for manipulating little endian encoded messages.
const void * binary() const noexcept
Message content.
MessageSize BinarySize
Length of message binary data.
MessageSize binarySize() const noexcept
Size of message.
BinaryMessage(const BinaryMessage &other) noexcept
Initializes instance as copy of the other one.
BinaryMessage(const void *data, MessageSize size) noexcept
Initializes instance over given memory block.
BinaryMessage() noexcept
Initializes blank instance referencing to nothing.
Provides efficient way of accessing text-based FIX field values.
Definition String.h:46
char Char
Character type alias.
Definition String.h:42
UInt16 MessageSize
Aliases message length type.
Definition Defines.h:93
Type * advanceByBytes(Type *pointer, ptrdiff_t distance) noexcept
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:109
FieldValue unalignedCopy(const void *p) noexcept
Definition Memory.h:166
ONIXS_HKEX_OMDC_API void throwIncorrectSize(const std::string &messageName, MessageSize receivedSize, MessageSize expectedSize)
static FieldValue extract(const void *p) noexcept