OnixS C++ FMX UST BIMP Market Data Handler 1.2.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/FmxUST/MarketData/Bimp/Export.h>
30
31namespace OnixS
32{
33 namespace FmxUST
34 {
35 namespace MarketData
36 {
37 namespace Bimp
38 {
40 template <class FieldValue>
42 {
43 static FieldValue extract(const void* p) ONIXS_FMXUST_BIMP_NOTHROW
44 {
46 }
47 };
48
49 template<class MantissaType, class ExponentType>
58
63 template <class Block, class BlockSize>
65 {
68 const Block& block() const
70 {
71 return *static_cast<const Block*>(this);
72 }
73
74 protected:
76 template <class SubMessage>
77 const SubMessage submessage(BlockSize offset, BlockSize size) const
79 {
80 assert(block().binarySize() >= (offset + size));
81
82 return
83 SubMessage(advanceByBytes(block().binary(), offset), size);
84 }
85
87 template <class FieldValue>
88 FieldValue ordinary(BlockSize offset) const
90 {
91 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
92
93 return OrdinaryExtractor<FieldValue>::extract(advanceByBytes(block().binary(), offset));
94 }
95
97 template <class FieldValue>
98 const FieldValue& ordinaryRef(BlockSize offset) const
100 {
101 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
102
103 return
104 *static_cast <const FieldValue*>(advanceByBytes(block().binary(), offset));
105 }
106
111 template <class Enumeration>
112 typename Enumeration::Enum enumeration(BlockSize offset) const
114 {
115 typedef typename Enumeration::Base Base;
116
117 typedef typename Enumeration::Enum Enum;
118
119 return static_cast<Enum>(ordinary<Base>(offset));
120 }
121
126 template <BlockSize Size>
127 StrRef fixedStr(BlockSize offset) const
129 {
130 typedef Char Str[Size];
131
132 const Str& str = ordinaryRef<Str>(offset);
133
134 return StrRef(str, strnlen(str, Size));
135 }
136 };
137
139 class ONIXS_FMXUST_BIMP_API BinaryMessage : public BinaryFields<BinaryMessage, MessageSize>
140 {
141 const void* data_;
142 MessageSize size_;
143
144 public:
147
152 , size_(0)
153 {
154 }
155
158 const void* data,
159 MessageSize size)
161 : data_(data)
162 , size_(size)
163 {
164 }
165
168 const BinaryMessage& other)
170 : data_(other.data_)
171 , size_(other.size_)
172 {
173 }
174
177 operator bool() const
179 {
180 return (ONIXS_FMXUST_BIMP_NULLPTR != data_);
181 }
182
184 const void* binary() const
186 {
187 return data_;
188 }
189
193 {
194 return size_;
195 }
196
199 operator =(
200 const BinaryMessage& other)
202 {
203 if (this == &other)
204 return *this;
205
206 data_ = other.data_;
207 size_ = other.size_;
208
209 return *this;
210 }
211
212#if defined(ONIXS_FMXUST_BIMP_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_FMXUST_BIMP_COMPILER_CXX_RVALUE_REFERENCES
213
216 : data_(std::move(other.data_))
217 , size_(std::move(other.size_))
218 {
219 }
220
221 BinaryMessage&
222 operator=(
223 BinaryMessage&& other)
225 {
226 if (this == &other)
227 return *this;
228
229 data_ = std::move(other.data_);
230 size_ = std::move(other.size_);
231
232 return *this;
233 }
234#endif
235
236 };
237
238 ONIXS_FMXUST_BIMP_API
239 ONIXS_FMXUST_BIMP_COLDPATH
240 ONIXS_FMXUST_BIMP_NORETURN
241 void throwIncorrectSize(const std::string& messageName, MessageSize receivedSize, MessageSize expectedSize);
242
243 }
244 }
245 }
246}
#define ONIXS_FMXUST_BIMP_NOTHROW
Definition Compiler.h:108
#define ONIXS_FMXUST_BIMP_EXPLICIT
Definition Compiler.h:110
#define ONIXS_FMXUST_BIMP_NULLPTR
Definition Compiler.h:122
StrRef fixedStr(BlockSize offset) const ONIXS_FMXUST_BIMP_NOTHROW
Enumeration::Enum enumeration(BlockSize offset) const ONIXS_FMXUST_BIMP_NOTHROW
const SubMessage submessage(BlockSize offset, BlockSize size) const ONIXS_FMXUST_BIMP_NOTHROW
Returns sub message.
const FieldValue & ordinaryRef(BlockSize offset) const ONIXS_FMXUST_BIMP_NOTHROW
Returns value of a field by its offset.
FieldValue ordinary(BlockSize offset) const ONIXS_FMXUST_BIMP_NOTHROW
Returns value of a field by its offset.
Encapsulates services for manipulating little endian encoded messages.
MessageSize BinarySize
Length of message binary data.
MessageSize binarySize() const ONIXS_FMXUST_BIMP_NOTHROW
Size of message.
BinaryMessage() ONIXS_FMXUST_BIMP_NOTHROW
Initializes blank instance referencing to nothing.
BinaryMessage(const void *data, MessageSize size) ONIXS_FMXUST_BIMP_NOTHROW
Initializes instance over given memory block.
const void * binary() const ONIXS_FMXUST_BIMP_NOTHROW
Message content.
BinaryMessage(const BinaryMessage &other) ONIXS_FMXUST_BIMP_NOTHROW
Initializes instance as copy of the other one.
MantissaType Mantissa
Aliases mantissa component type.
Definition Decimal.h:52
Provides efficient way of accessing text-based FIX field values.
Definition String.h:46
ONIXS_FMXUST_BIMP_API ONIXS_FMXUST_BIMP_COLDPATH ONIXS_FMXUST_BIMP_NORETURN void throwIncorrectSize(const std::string &messageName, MessageSize receivedSize, MessageSize expectedSize)
Integer2 MessageSize
Aliases message length type.
Definition Defines.h:100
char Char
Character type alias.
Definition String.h:42
Type * advanceByBytes(Type *pointer, ptrdiff_t distance) ONIXS_FMXUST_BIMP_NOTHROW
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:109
FieldValue unalignedCopy(const void *p) ONIXS_FMXUST_BIMP_NOTHROW
Definition Memory.h:166
static FixedPointDecimal< MantissaType, ExponentType > extract(const void *p) ONIXS_FMXUST_BIMP_NOTHROW
static FieldValue extract(const void *p) ONIXS_FMXUST_BIMP_NOTHROW