OnixS C++ LSE GTP Market Data Handler 1.0.6
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/LSE/MarketData/GTP/Export.h>
30
31
32namespace OnixS
33{
34 namespace LSE
35 {
36 namespace MarketData
37 {
38 namespace GTP
39 {
40
45 template <class Block, class BlockSize>
47 {
50 const Block& block() const
52 {
53 return *static_cast<const Block*>(this);
54 }
55
56 protected:
58 template <class FieldValue>
59 FieldValue ordinary(BlockSize offset) const
61 {
62 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
63
64 return
65 unalignedCopy<FieldValue>(advanceByBytes(block().binary(), offset));
66 }
67
69 template <class FieldValue>
70 const FieldValue& ordinaryRef(BlockSize offset) const
72 {
73 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
74
75 return
76 *static_cast <const FieldValue*>(advanceByBytes(block().binary(), offset));
77 }
78
83 template <class Enumeration>
84 typename Enumeration::Enum enumeration(BlockSize offset) const
86 {
87 typedef typename Enumeration::Base Base;
88
89 typedef typename Enumeration::Enum Enum;
90
91 return static_cast<Enum>(ordinary<Base>(offset));
92 }
93
98 template <BlockSize Size>
99 StrRef fixedStr(BlockSize offset) const
101 {
102 typedef Char Str[Size];
103
104 return StrRef(ordinaryRef<Str>(offset), strnlen(ordinaryRef<Str>(offset), Size));
105 }
106 };
107
109 class ONIXS_LSE_GTP_API BinaryMessage : public BinaryFields<BinaryMessage, MessageSize>
110 {
111 const void* data_;
112 MessageSize size_;
113
114 public:
117
121 : data_(ONIXS_LSE_GTP_NULLPTR)
122 , size_(0)
123 {
124 }
125
128 const void* data,
129 MessageSize size)
131 : data_(data)
132 , size_(size)
133 {
134 }
135
138 const BinaryMessage& other)
140 : data_(other.data_)
141 , size_(other.size_)
142 {
143 }
144
147 operator bool() const
149 {
150 return (ONIXS_LSE_GTP_NULLPTR != data_);
151 }
152
154 const void* binary() const
156 {
157 return data_;
158 }
159
163 {
164 return size_;
165 }
166
169 operator =(
170 const BinaryMessage& other)
172 {
173 if (this == &other)
174 return *this;
175
176 data_ = other.data_;
177 size_ = other.size_;
178
179 return *this;
180 }
181
182#if defined(ONIXS_LSE_GTP_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_LSE_GTP_COMPILER_CXX_RVALUE_REFERENCES
183
186 : data_(std::move(other.data_))
187 , size_(std::move(other.size_))
188 {
189 }
190
191 BinaryMessage&
192 operator=(
193 BinaryMessage&& other)
195 {
196 if (this == &other)
197 return *this;
198
199 data_ = std::move(other.data_);
200 size_ = std::move(other.size_);
201
202 return *this;
203 }
204#endif
205
206 };
207
208 ONIXS_LSE_GTP_API
209 void throwIncorrectSize(const std::string& messageName, MessageSize receivedSize, MessageSize expectedSize);
210
211 }
212 }
213 }
214}
#define ONIXS_LSE_GTP_NULLPTR
Definition Compiler.h:132
#define ONIXS_LSE_GTP_NOTHROW
Definition Compiler.h:118
#define ONIXS_LSE_GTP_EXPLICIT
Definition Compiler.h:120
Enumeration::Enum enumeration(BlockSize offset) const ONIXS_LSE_GTP_NOTHROW
const FieldValue & ordinaryRef(BlockSize offset) const ONIXS_LSE_GTP_NOTHROW
Returns value of a field by its offset.
FieldValue ordinary(BlockSize offset) const ONIXS_LSE_GTP_NOTHROW
Returns value of a field by its offset.
StrRef fixedStr(BlockSize offset) const ONIXS_LSE_GTP_NOTHROW
Encapsulates services for manipulating little endian encoded messages.
MessageSize BinarySize
Length of message binary data.
BinaryMessage(const void *data, MessageSize size) ONIXS_LSE_GTP_NOTHROW
Initializes instance over given memory block.
MessageSize binarySize() const ONIXS_LSE_GTP_NOTHROW
Size of message.
BinaryMessage() ONIXS_LSE_GTP_NOTHROW
Initializes blank instance referencing to nothing.
BinaryMessage(const BinaryMessage &other) ONIXS_LSE_GTP_NOTHROW
Initializes instance as copy of the other one.
const void * binary() const ONIXS_LSE_GTP_NOTHROW
Message content.
Provides efficient way of accessing text-based FIX field values.
Definition String.h:46
ONIXS_LSE_GTP_API void throwIncorrectSize(const std::string &messageName, MessageSize receivedSize, MessageSize expectedSize)
char Char
Character type alias.
Definition String.h:42
FieldValue unalignedCopy(const void *p) ONIXS_LSE_GTP_NOTHROW
Definition Memory.h:166
FixedPointDecimal< UInt64, IntegralConstant< Int8, -8 > > Size
Little-Endian encoded 64 bit unsigned integer with eight implied decimal places.
Definition Defines.h:111
UInt16 MessageSize
Aliases message length type.
Definition Defines.h:141
Type * advanceByBytes(Type *pointer, ptrdiff_t distance) ONIXS_LSE_GTP_NOTHROW
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:109