OnixS C++ CME MDP Streamlined Market Data Handler 1.2.0
API Documentation
Loading...
Searching...
No Matches
Packet.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#include <stdexcept>
25
29
31ONIXS_CMESTREAMLINEDMDH_DATA_PACKING_BEGIN(1)
32
34
38{
39 // Messages are prefixed with message header.
40 struct Header
41 {
42 MessageSize messageSize;
43 };
44
45 const Header* header_;
46 const void* end_;
47
48 void
49 validate() const
50 {
51 if (const
52 size_t
53 availableSize =
55 end_, header_))
56 {
57 if (availableSize < sizeof(Header) ||
58 availableSize < header_->messageSize)
59 {
60 throw std::runtime_error(
61 "Not enough data to retrieve SBE message. ");
62 }
63 }
64 }
65
66public:
67 // Identifies iterator category.
68 typedef
69 std::forward_iterator_tag
71
73 typedef
74 ptrdiff_t
76
78 typedef
79 const BinaryMessage
81
84
87
93 const void* dataBegin,
94 const void* dataEnd)
95 : header_(
96 static_cast
97 <const Header*>
98 (dataBegin))
99 , end_(
100 dataEnd)
101 {
102 assert(dataBegin <= dataEnd);
103
104 validate();
105 }
106
112 {
113 assert(header_ != end_);
114
115 return
117 header_ + 1,
118 header_->messageSize -
119 sizeof(Header));
120 }
121
123 BinaryMessage operator *() const
124 {
125 return message();
126 }
127
131 operator ++()
132 {
133 header_ =
135 header_,
136 header_->messageSize);
137
138 validate();
139
140 return *this;
141 }
142
144 bool
145 operator ==(
146 const BinaryMessageIterator& other) const
147 {
148 return header_ == other.header_;
149 }
150
152 bool
153 operator !=(
154 const BinaryMessageIterator& other) const
155 {
156 return header_ != other.header_;
157 }
158};
159
162{
163 // Memory block keeping messages.
164 const void* begin_;
165 const void* end_;
166
167public:
170 const void* messagesBegin,
171 const void* messagesEnd)
172 : begin_(messagesBegin)
173 , end_(messagesEnd)
174 {
175 }
176
179 {
180 return BinaryMessageIterator(begin_, end_);
181 }
182
185 {
186 return BinaryMessageIterator(end_, end_);
187 }
188};
189
192typedef
193UInt32
195
197inline
198void
200 size_t packetSize,
201 size_t minimalSize)
202{
203 std::string error;
204
205 error +=
206 "Cannot construct packet over given buffer "
207 "because it doesn't meet requirements on minimal size. "
208 "Size of buffer is ";
209
210 toStr(error, packetSize);
211
212 error += " byte(s), whereas packet must have at least ";
213
214 toStr(error, minimalSize);
215
216 error += " bytes. ";
217
218 throw std::runtime_error(error);
219}
220
223{
224 struct Header
225 {
228 };
229
230 const Header* header_;
231 size_t size_;
232
233public:
237 , size_(0)
238 {
239 }
240
246 const void* data,
247 size_t size)
248 : header_(
249 static_cast
250 <const Header*>
251 (data))
252 , size_(size)
253 {
254 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != header_);
255 assert(0 != size_);
256
257 const
258 size_t
259 headerSize =
260 sizeof(Header);
261
262 if (size < headerSize)
263 {
265 size, headerSize);
266 }
267 }
268
271 const Packet& other)
272 : header_(other.header_)
273 , size_(other.size_)
274 {
275 }
276
279 {
280 }
281
283 const void* data() const
284 {
285 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != header_);
286
287 return static_cast<const void*>(header_);
288 }
289
291 size_t size() const
292 {
293 return size_;
294 }
295
298 {
299 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != header_);
300
301 return header_->seqNumber;
302 }
303
305 const Timestamp& sendingTime() const
306 {
307 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != header_);
308
309 return header_->sendingTime;
310 }
311
314 {
315 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != header_);
316
317 return
319 header_ + 1,
321 header_, size_));
322 }
323
325 void reset()
326 {
328 size_ = 0;
329 }
330
333 void
335 const void* data,
336 size_t size)
337 {
338 const
339 size_t
340 headerSize =
341 sizeof(Header);
342
343 if (data &&
344 size >= headerSize)
345 {
346 header_ =
347 static_cast
348 <const Header*>
349 (data);
350
351 size_ = size;
352 }
353 else
354 {
356 size, headerSize);
357 }
358 }
359
362 Packet&
363 operator =(
364 const Packet& other)
365 {
366 header_ = other.header_;
367 size_ = other.size_;
368
369 return *this;
370 }
371};
372
374NetPacket : public Packet
375{
376 const NetFeed* source_;
377 Timestamp receiveTime_;
378
379public:
383 {
384 }
385
388 const void* data,
389 size_t size)
390 : Packet(data, size)
391 {
392 }
393
396 const NetPacket& other)
397 : Packet(
398 static_cast
399 <const Packet&>
400 (other))
401 , source_(
402 other.source_)
403 , receiveTime_(
404 other.receiveTime_)
405 {
406 }
407
410 {
411 }
412
414 const NetFeed& source() const
415 {
416 assert(ONIXS_CMESTREAMLINEDMDH_NULLPTR != source_);
417
418 return *source_;
419 }
420
422 void
424 const NetFeed& source)
425 {
426 source_ = &source;
427 }
428
430 const Timestamp& receiveTime() const
431 {
432 return receiveTime_;
433 }
434
436 void
438 const Timestamp& receiveTime)
439 {
440 receiveTime_ = receiveTime;
441 }
442
444 void reset()
445 {
448 }
449
451 NetPacket&
452 operator =(
453 const NetPacket& other)
454 {
455 static_cast<Packet&>(*this) =
456 static_cast<const Packet&>(other);
457
458 source_ = other.source_;
459 receiveTime_ = other.receiveTime_;
460
461 return *this;
462 }
463};
464
468
469ONIXS_CMESTREAMLINEDMDH_DATA_PACKING_END
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:169
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition Bootstrap.h:173
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS_DECL(name)
Definition Bootstrap.h:123
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS
Definition Bootstrap.h:111
#define ONIXS_CMESTREAMLINEDMDH_NULLPTR
Definition Compiler.h:167
Iterator over SBE-encoded messages.
Definition Packet.h:38
std::forward_iterator_tag iterator_category
Definition Packet.h:70
BinaryMessage message() const
Gets reference to encoded message.
Definition Packet.h:111
BinaryMessageIterator(const void *dataBegin, const void *dataEnd)
Constructs encoded message iterator from raw data pointers.
Definition Packet.h:92
value_type & reference
Defines reference to a value type.
Definition Packet.h:86
const BinaryMessage value_type
Defines value type.
Definition Packet.h:80
ptrdiff_t difference_type
Establishes instance difference type.
Definition Packet.h:75
value_type * pointer
Defines pointer to a value type.
Definition Packet.h:83
Encapsulates services for manipulating SBE-encoded messages.
Collection of encoded messages stored in single packet.
Definition Packet.h:162
BinaryMessages(const void *messagesBegin, const void *messagesEnd)
Initializes messages container.
Definition Packet.h:169
BinaryMessageIterator begin() const
Returns iterator pointing to first encoded message.
Definition Packet.h:178
BinaryMessageIterator end() const
Returns iterator pointing past last encoded message.
Definition Packet.h:184
Base attributes of market data feed.
Definition NetFeed.h:34
NetPacket(const void *data, size_t size)
Initializes with primary attributes.
Definition Packet.h:387
void source(const NetFeed &source)
Updates packet source attribute.
Definition Packet.h:423
~NetPacket()
Does actually nothing.
Definition Packet.h:409
const Timestamp & receiveTime() const
Data reception time (if applicable).
Definition Packet.h:430
NetPacket()
Initializes as null packet.
Definition Packet.h:381
void reset()
Resets the instances to the blank state.
Definition Packet.h:444
NetPacket(const NetPacket &other)
Initializes as a copy of the other instance.
Definition Packet.h:395
void receiveTime(const Timestamp &receiveTime)
Updates receive time attribute.
Definition Packet.h:437
const NetFeed & source() const
Identifies source of the packet.
Definition Packet.h:414
Represents CME binary packet containing SBE messages.
Definition Packet.h:223
const Timestamp & sendingTime() const
Packet sending time.
Definition Packet.h:305
size_t size() const
Packet size.
Definition Packet.h:291
const void * data() const
Packet bytes.
Definition Packet.h:283
~Packet()
Does actually nothing.
Definition Packet.h:278
void reset(const void *data, size_t size)
Re-initializes the instance to refer to the other content.
Definition Packet.h:334
SequenceNumber seqNumber() const
Packet sequence number.
Definition Packet.h:297
Packet()
Initializes blank instance.
Definition Packet.h:235
Packet(const void *data, size_t size)
Initializes binary packet over given buffer.
Definition Packet.h:245
BinaryMessages messages() const
Returns collection of messages stored by instance.
Definition Packet.h:313
void reset()
Resets the instance to the null state.
Definition Packet.h:325
Packet(const Packet &other)
Initializes as a copy of the other instance.
Definition Packet.h:270
Represents time point without time-zone information.
Definition Time.h:448
ptrdiff_t byteDistance(Left *left, Right *right)
Returns distance in bytes between two pointers.
Definition Memory.h:159
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition Memory.h:121
void throwBadPacket(size_t packetSize, size_t minimalSize)
Raises exception on ill-formed packet.
Definition Packet.h:199
UInt16 MessageSize
Aliases message length type.
UInt32 SequenceNumber
Integral type used to identify packets in a sequence transmitted by MDP.
Definition Packet.h:194
NetPacket PacketArgs
Alias for a type keeping collection of packet-related attributes.
Definition Packet.h:467
void toStr(std::string &str, const Decimal &number)
Definition Decimal.h:502