OnixS C++ Tradeweb Approved Publication Arrangement (APA) Handler  1.2.2.18
API documentation
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 
26 
27 #include <cassert>
28 
29 namespace OnixS
30 {
31  namespace Tradeweb
32  {
33  namespace MarketData
34  {
35  namespace Apa
36  {
37 
38  /// Exposes base services to access fields stored in
39  /// little Endian block of memory. Class represents an
40  /// abstraction, instance construction available through
41  /// descendants implementing actual access to encoded data.
42  template <class Block, class BlockSize>
44  {
45  /// Instance of block providing
46  /// actual access to encoded data.
47  const Block& block() const
48  {
49  return *static_cast<const Block*>(this);
50  }
51 
52  protected:
53  /// Returns sub message.
54  template <class SubMessage>
55  const SubMessage submessage(BlockSize offset, BlockSize size) const
56  {
57  assert(static_cast<size_t>(block().binarySize()) >= (offset + size));
58 
59  const void* const data = advanceByBytes(block().binary(), offset);
60 
61  return SubMessage(data, size);
62  }
63 
64  /// Returns value of a field by its offset.
65  template <class FieldValue>
66  const FieldValue& ordinary(BlockSize offset) const
67  {
68  assert(static_cast<size_t>(block().binarySize()) >= (offset + sizeof(FieldValue)));
69 
70  const void* const fieldValue = advanceByBytes(block().binary(), offset);
71 
72  return *static_cast <const FieldValue*>(fieldValue);
73  }
74 
75  /// Returns value of a field by its offset.
76  ///
77  /// Given function serves as specialization of
78  /// general case for fields of enumeration type.
79  template <class Enumeration>
80  typename Enumeration::Enum enumeration(BlockSize offset) const
81  {
82  typedef typename Enumeration::Base Base;
83 
84  typedef typename Enumeration::Enum Enum;
85 
86  return static_cast<Enum>( ordinary<Base>(offset));
87  }
88 
89  /// Provides access to string field by its offset.
90  ///
91  /// Given function serves as specialization
92  /// of general case for fields of string type.
93  template <BlockSize Size>
94  StrRef fixedStr(BlockSize offset) const
95  {
96  typedef Char Str[Size];
97 
98  const Str& str = ordinary<Str>(offset);
99 
100  return StrRef(str, strnlen(str, Size));
101  }
102  };
103 
104  /// Aliases message length type.
106 
107  /// Encapsulates services for manipulating little endian encoded messages.
108  class ONIXS_TRADEWEB_APA_API BinaryMessage : public BinaryFields<BinaryMessage, MessageSize>
109  {
110  const void* data_;
111  MessageSize size_;
112 
113  public:
114  /// Length of message binary data.
115  typedef MessageSize BinarySize;
116 
117  /// Initializes blank instance referencing to nothing.
119  : data_(NULL)
120  , size_(0)
121  {
122  }
123 
124  /// Initializes instance over given memory block.
126  const void* data,
127  MessageSize size)
128  : data_(data)
129  , size_(size)
130  {
131  assert(NULL != data);
132  }
133 
134  /// Initializes instance as copy of the other one.
136  const BinaryMessage& other)
137  : data_(other.data_)
138  , size_(other.size_)
139  {
140  }
141 
142  /// Indicates whether instance refers to a valid message.
143  operator bool() const
144  {
145  return (NULL != data_);
146  }
147 
148  /// Message content.
149  const void* binary() const
150  {
151  return data_;
152  }
153 
154  /// Size of message.
155  MessageSize binarySize() const
156  {
157  return size_;
158  }
159 
160  /// Re-initializes instance as a copy of the other one.
162  operator =(
163  const BinaryMessage& other)
164  {
165  data_ = other.data_;
166  size_ = other.size_;
167 
168  return *this;
169  }
170  };
171 
172  /// conversion to UInt32
173  ONIXS_TRADEWEB_APA_API
174  UInt32 toUInt32(StrRef);
175 
176  /// conversion to UInt64
177  ONIXS_TRADEWEB_APA_API
178  UInt64 toUInt64(StrRef);
179  }
180  }
181  }
182 }
BinaryMessage()
Initializes blank instance referencing to nothing.
MessageSize BinarySize
Length of message binary data.
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:125
char Char
Character type alias.
Definition: String.h:40
StrRef fixedStr(BlockSize offset) const
Definition: BinaryMessage.h:94
ONIXS_TRADEWEB_APA_API UInt32 toUInt32(StrRef)
conversion to UInt32
Enumeration::Enum enumeration(BlockSize offset) const
Definition: BinaryMessage.h:80
BinaryMessage(const void *data, MessageSize size)
Initializes instance over given memory block.
Encapsulates services for manipulating little endian encoded messages.
const void * binary() const
Message content.
Integer2 MessageSize
Aliases message length type.
const SubMessage submessage(BlockSize offset, BlockSize size) const
Returns sub message.
Definition: BinaryMessage.h:55
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:43
ONIXS_TRADEWEB_APA_API UInt64 toUInt64(StrRef)
conversion to UInt64
const FieldValue & ordinary(BlockSize offset) const
Returns value of a field by its offset.
Definition: BinaryMessage.h:66
BinaryMessage(const BinaryMessage &other)
Initializes instance as copy of the other one.
MessageSize binarySize() const
Size of message.