OnixS C++ eSpeed ITCH Market Data Handler 1.7.3
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#pragma once
21
22#include <cassert>
23
27
29
30
35
36template <template<class> class Block, class FieldAccessor>
38{
39 typedef MessageSize BlockSize;
40
43 const Block<FieldAccessor>& block() const
45 {
46 return *static_cast<const Block<FieldAccessor>*>(this);
47 }
48
49protected:
51 template <class FieldValue>
52 FieldValue ordinary(BlockSize offset) const
54 {
55 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
56
57 return FieldAccessor::get(FieldValue(), advanceByBytes(block().binary(), offset));
58 }
59
61 template <class FieldValue>
62 const FieldValue& ordinaryRef(BlockSize offset) const
64 {
65 assert(block().binarySize() >= (offset + sizeof(FieldValue)));
66
67 return *static_cast <const FieldValue*>(advanceByBytes(block().binary(), offset));
68 }
69
74 template <class Enumeration>
75 typename Enumeration::Enum enumeration(BlockSize offset) const
77 {
78 typedef typename Enumeration::Base Base;
79
80 typedef typename Enumeration::Enum Enum;
81
82 return static_cast<Enum>(ordinaryRef<Base>(offset));
83 }
84
89 template <BlockSize Size>
90 StrRef fixedStr(BlockSize offset) const
92 {
93 typedef Char Str[Size];
94
95 assert(block().binarySize() >= (offset + Size));
96
97 return
98 StrRef(ordinaryRef<Str>(offset), strnlen(ordinaryRef<Str>(offset), Size));
99 }
100};
101
103template <class Accessor>
105 : public BinaryFields<BinaryMessage, Accessor>
106{
107 const void* data_;
108 MessageSize size_;
109
110public:
113
116 const void* data,
117 MessageSize size)
119 : data_(data)
120 , size_(size)
121 {
122 }
123
125 ONIXS_ESPEED_ITCH_CONSTEXPR
127 const BinaryMessage& other)
129 : data_(other.data_)
130 , size_(other.size_)
131 {
132 }
133
135 const void* binary() const
137 {
138 return data_;
139 }
140
144 {
145 return size_;
146 }
147
151 const BinaryMessage& other)
153 {
154 data_ = other.data_;
155 size_ = other.size_;
156
157 return *this;
158 }
159
160#if defined(ONIXS_ESPEED_ITCH_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_ESPEED_ITCH_COMPILER_CXX_RVALUE_REFERENCES
161
164 : data_(std::move(other.data_))
165 , size_(std::move(other.size_))
166 {
167 }
168
170 operator=(
171 BinaryMessage&& other)
173 {
174 if (this == &other)
175 return *this;
176
177 data_ = std::move(other.data_);
178 size_ = std::move(other.size_);
179
180 return *this;
181 }
182
183#endif
184};
185
186ONIXS_ESPEED_ITCH_API
187void throwIncorrectSize(const std::string& messageName, MessageSize receivedSize, MessageSize expectedSize);
188
189
ONIXS_ESPEED_ITCH_API void throwIncorrectSize(const std::string &messageName, MessageSize receivedSize, MessageSize expectedSize)
#define ONIXS_ESPEED_ITCH_NAMESPACE_BEGIN
Definition Bootstrap.h:27
#define ONIXS_ESPEED_ITCH_NAMESPACE_END
Definition Bootstrap.h:31
#define ONIXS_ESPEED_ITCH_NOTHROW
Definition Compiler.h:27
ONIXS_ESPEED_ITCH_NAMESPACE_BEGIN typedef UInt16 MessageSize
Aliases message length type.
Definition Defines.h:34
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:98
ONIXS_ESPEED_ITCH_NAMESPACE_BEGIN typedef char Char
Character type alias.
Definition String.h:37
const FieldValue & ordinaryRef(BlockSize offset) const ONIXS_ESPEED_ITCH_NOTHROW
Returns value of a field by its offset.
StrRef fixedStr(BlockSize offset) const ONIXS_ESPEED_ITCH_NOTHROW
FieldValue ordinary(BlockSize offset) const ONIXS_ESPEED_ITCH_NOTHROW
Returns value of a field by its offset.
Enumeration::Enum enumeration(BlockSize offset) const ONIXS_ESPEED_ITCH_NOTHROW
Encapsulates services for manipulating encoded messages.
MessageSize BinarySize
Length of message binary data.
BinaryMessage(const void *data, MessageSize size) ONIXS_ESPEED_ITCH_NOTHROW
Initializes instance over given memory block.
ONIXS_ESPEED_ITCH_CONSTEXPR BinaryMessage(const BinaryMessage &other) ONIXS_ESPEED_ITCH_NOTHROW
Initializes instance as copy of the other one.
const void * binary() const ONIXS_ESPEED_ITCH_NOTHROW
Message content.
BinaryMessage & operator=(const BinaryMessage &other) ONIXS_ESPEED_ITCH_NOTHROW
Re-initializes instance as a copy of the other one.
MessageSize binarySize() const ONIXS_ESPEED_ITCH_NOTHROW
Size of message.
Provides efficient way of accessing text-based FIX field values.
Definition String.h:41