OnixS C++ CME Streamlined Market Data Handler  1.1.0.5
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 
23 #include <cassert>
24 #include <stdexcept>
25 
28 
31 
33 
34 /// Exposes base services to access fields stored in
35 /// SBE-encoded block of memory. Class represents an
36 /// abstraction, instance construction available through
37 /// descendants implementing actual access to encoded data.
38 template
39 <
40  class Block,
41  class BlockSize
42 >
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  /// Initializes blank instance.
55  {
56  }
57 
58  /// Cleans everything up.
60  {
61  }
62 
63  /// Returns value of a field by its offset.
64  template
65  <
66  class FieldValue
67  >
68  const
69  FieldValue&
71  BlockSize offset) const
72  {
73  assert(
74  block().bodySize() >=
75  (offset + sizeof(FieldValue)));
76 
77  const void*
78  const fieldValue =
80  block().body(),
81  offset);
82 
83  return
84  *static_cast
85  <const FieldValue*>
86  (fieldValue);
87  }
88 
89  /// Provides access to a value of
90  /// an optional field by its offset.
91  ///
92  /// Returned result indicates whether field is
93  /// present in given field block and its value
94  /// was copied into a given parameter-variable.
95  template
96  <
97  class FieldValue,
98  class NullValue
99  >
100  bool
102  FieldValue& value,
103  BlockSize offset,
104  const NullValue& null) const
105  {
106  const FieldValue& fieldValue =
107  ordinary<FieldValue>(offset);
108 
109  if (null != fieldValue)
110  {
111  value = fieldValue;
112 
113  return true;
114  }
115 
116  return false;
117  }
118 
119  /// Returns value of a field by its
120  /// offset converted into a decimal.
121  template
122  <
123  class Value
124  >
125  Decimal
126  decimal(BlockSize offset) const
127  {
128  return Decimal
129  (
130  ordinary<Value>(offset)
131  );
132  }
133 
134  /// Provides access to a value of
135  /// an optional field by its offset.
136  /// The result is converted into decimal.
137  ///
138  /// Returned result indicates whether field is
139  /// present in given field block and its value
140  /// was copied into a given parameter-variable.
141  template
142  <
143  class NullValue
144  >
145  bool
147  Decimal& value,
148  BlockSize offset,
149  const NullValue& null) const
150  {
151  typedef
152  typename
153  NullValue::Value
154  Value;
155 
156  const Value& optional =
157  ordinary<Value>(offset);
158 
159  if (null != optional)
160  {
161  value = optional;
162 
163  return true;
164  }
165 
166  return false;
167  }
168 
169 
170  /// Provides access to a value of
171  /// an optional field by its offset.
172  ///
173  /// Returned result indicates whether field is
174  /// present in given field block and its value
175  /// was copied into a given parameter-variable.
176  ///
177  /// Field may not be present in earlier versions
178  /// of binary message and thus its value may not be
179  /// available. For this reason, parameter indicating
180  /// version of data assumed is required to access
181  /// the field.
182  template
183  <
184  class FieldValue,
185  class NullValue
186  >
187  bool
189  FieldValue& value,
190  BlockSize offset,
191  const NullValue& null,
192  SchemaVersion since) const
193  {
194  return (
195  since <= block().version()
196  &&
197  ordinary(value, offset, null)
198  );
199  }
200 
201 
202  /// Returns value of a field by its offset.
203  ///
204  /// Given function serves as specialization of
205  /// general case for fields of enumeration type.
206  template
207  <
208  class Enumeration
209  >
210  typename
211  Enumeration::Enum
213  BlockSize offset) const
214  {
215  typedef
216  typename
217  Enumeration::Base
218  Base;
219 
220  typedef
221  typename
222  Enumeration::Enum
223  Enum;
224 
225  return
226  static_cast<Enum>(
227  ordinary<Base>(offset));
228  }
229 
230  /// Provides access to value of
231  /// an optional field by its offset.
232  ///
233  /// Given function serves as specialization of
234  /// general case for fields of enumeration type.
235  template
236  <
237  class Enumeration,
238  class NullValue
239  >
240  bool
242  typename
243  Enumeration::Enum& value,
244  BlockSize offset,
245  const NullValue& null) const
246  {
247  typedef
248  typename
249  Enumeration::Base
250  Base;
251 
252  typedef
253  typename
254  Enumeration::Enum
255  Enum;
256 
257  const Base& fieldValue =
258  ordinary<Base>(offset);
259 
260  if (null != fieldValue)
261  {
262  value = static_cast<Enum>(fieldValue);
263 
264  return true;
265  }
266 
267  return false;
268  }
269 
270  /// Provides access to value of
271  /// an optional field by its offset.
272  ///
273  /// Given function serves as specialization of
274  /// general case for fields of enumeration type.
275  template
276  <
277  class Enumeration,
278  class NullValue
279  >
280  bool
282  typename
283  Enumeration::Enum& value,
284  BlockSize offset,
285  const NullValue& null,
286  SchemaVersion since) const
287  {
288  return (
289  since <= block().version()
290  &&
291  enumeration(value, offset, null)
292  );
293  }
294 
295  /// Provides access to string field by its offset.
296  ///
297  /// Given function serves as specialization
298  /// of general case for fields of string type.
299  template
300  <
301  BlockSize Size
302  >
303  StrRef
305  BlockSize offset) const
306  {
307  typedef Char Str[Size];
308 
309  const Str& str =
310  ordinary<Str>(offset);
311 
312  return
313  StrRef
314  (
315  str,
316  strnlen(str, Size)
317  );
318  }
319 
320  /// Provides access to an optional
321  /// field of string type by its offset.
322  ///
323  /// Given function serves as specialization
324  /// of general case for fields of string type.
325  template
326  <
327  BlockSize Size
328  >
329  StrRef
331  BlockSize offset,
332  SchemaVersion since) const
333  {
334  return (
335  since >=
336  block().version()
337 
338  ? fixedStr<Size>(offset)
339  : StrRef()
340  );
341  }
342 
343  /// Provides access to an optional
344  /// field of string type by its offset.
345  ///
346  /// Given function serves as specialization
347  /// of general case for fields of string type.
348  template
349  <
350  BlockSize Size
351  >
352  bool
354  StrRef& value,
355  BlockSize offset) const
356  {
357  typedef Char Str[Size];
358 
359  const Str& str =
360  ordinary<Str>(offset);
361 
362  if (str[0])
363  {
364  value = fixedStr<Size>(offset);
365  return true;
366  }
367  else
368  {
369  return false;
370  }
371  }
372 };
373 
374 /// Throws exception on bad repeating group entry.
375 ONIXS_CMESTREAMLINEDMDH_EXPORTED
376 void
378  const Char* className);
379 
380 /// Throws exception on bad repeating group.
381 ONIXS_CMESTREAMLINEDMDH_EXPORTED
382 void
384 
385 /// Encapsulates operations over SBE-encoded repeating group.
386 template
387 <
388  class EntryType,
389  class DimensionType,
390  class GroupSizeType
391 >
393 {
394 public:
395  /// Aliases type of repeating group entry.
396  typedef EntryType Entry;
397 
398  /// Aliases repeating group dimension type.
399  typedef DimensionType Dimension;
400 
401  /// Length of group data.
402  typedef GroupSizeType BinarySize;
403 
404  /// Length of group entry data.
405  typedef
406  typename
409 
410 
411  /// Size of group (number of entries).
412  typedef
413  typename
414  Dimension::NumInGroup
416 
417  /// Provides iterating facilities
418  /// over SBE-encoded group entries.
419  class Iterator
420  {
421  const void* entry_;
422  EntrySize size_;
423 
424  SchemaVersion version_;
425 
426  public:
427  /// Aliases type of object referenced by iterator.
428  typedef EntryType Entry;
429 
430  /// Aliases entry for STL conformance.
431  typedef const Entry value_type;
432 
433  /// Aliases pointer to entry for STL conformance.
434  typedef const Entry* pointer;
435 
436  /// Aliases entry reference for STL conformance.
437  typedef const Entry& reference;
438 
439  /// Iterator difference type.
440  typedef ptrdiff_t difference_type;
441 
442  /// Identifies iterator category.
443  typedef
444  std::random_access_iterator_tag
446 
447  /// Initializes instance referring to nothing.
449  : entry_(NULL)
450  , size_(0)
451  , version_(0)
452  {
453  }
454 
455  /// Initializes instance for given repeating group.
457  const void* entry,
458  EntrySize size,
459  SchemaVersion version)
460  : entry_(entry)
461  , size_(size)
462  , version_(version)
463  {
464  }
465 
466  /// Initializes instance as copy of the other one.
468  const Iterator& other)
469  : entry_(
470  other.entry_)
471  , size_(
472  other.size_)
473  , version_(
474  other.version_)
475  {
476  }
477 
478  /// Repeating group entry referenced by the instance.
479  const Entry get() const
480  {
481  assert(NULL != entry_);
482 
483  return
484  Entry(
485  entry_,
486  size_,
487  version_);
488  }
489 
490  /// Repeating group entry referenced by the instance.
491  const Entry operator *() const
492  {
493  return get();
494  }
495 
496  /// Compares given iterator with the other instance.
497  bool
499  const Iterator& other) const
500  {
501  return entry_ == other.entry_;
502  }
503 
504  /// Compares given iterator with the other instance.
505  bool
507  const Iterator& other) const
508  {
509  return entry_ != other.entry_;
510  }
511 
512  /// Established order between two iterators.
513  bool
515  const Iterator& other) const
516  {
517  return entry_ < other.entry_;
518  }
519 
520  /// Established order between two iterators.
521  bool
523  const Iterator& other) const
524  {
525  return entry_ > other.entry_;
526  }
527 
528  /// Advances instance to the next repeating group entry.
529  Iterator&
530  operator ++()
531  {
532  entry_ =
534  entry_, size_);
535 
536  return *this;
537  }
538 
539  /// Advances instance to the next repeating group entry.
540  Iterator&
541  operator --()
542  {
543  entry_ =
545  entry_,
546  size_);
547 
548  return *this;
549  }
550 
551  /// Advances instance by given number of entries.
552  Iterator
554  difference_type distance) const
555  {
556  return
557  Iterator(
559  entry_,
560  distance * size_),
561  size_,
562  version_);
563  }
564 
565  /// Advances instance by given number of entries.
566  Iterator
568  difference_type distance) const
569  {
570  return
571  Iterator(
573  entry_,
574  distance * size_),
575  size_,
576  version_);
577  }
578 
579  /// Re-initializes instance as copy of the other one.
580  Iterator&
581  operator =(
582  const Iterator& other)
583  {
584  entry_ = other.entry_;
585  size_ = other.size_;
586 
587  version_ = other.version_;
588 
589  return *this;
590  }
591  };
592 
593  /// Initializes blank instance referencing to nothing.
595  : entries_(NULL)
596  , entrySize_(0)
597  , entryCount_(0)
598  , version_(0)
599  , size_(0)
600  {
601  }
602 
603  /// Initializes instance referencing
604  /// to a valid group of a given message.
606  const void* data,
607  BinarySize size,
608  SchemaVersion version)
609  : entries_(
611  data,
612  Dimension::Size))
613  , entrySize_(0)
614  , entryCount_(0)
615  , version_(version)
616  , size_(Dimension::Size)
617  {
618  if (size < size_)
620 
621  const
622  Dimension*
623  group =
624  static_cast
625  <const Dimension*>
626  (data);
627 
628  entrySize_ =
629  group->blockLength();
630 
631  entryCount_ =
632  group->numInGroup();
633 
634  size_ +=
635  (
636  static_cast
637  <BinarySize>
638  (entrySize_) *
639  static_cast
640  <BinarySize>
641  (entryCount_)
642  );
643 
644  if (size < size_)
646  }
647 
648  /// Initializes instance as a copy of the other one.
650  const BinaryGroup& other)
651  : entries_(
652  other.entries_)
653  , entrySize_(
654  other.entrySize_)
655  , entryCount_(
656  other.entryCount_)
657  , version_(
658  other.version_)
659  , size_(
660  other.size_)
661  {
662  }
663 
664  /// Indicates whether given instance
665  /// refers to a valid repeating group.
666  operator bool() const
667  {
668  return (NULL != entries_);
669  }
670 
671  /// Indicates whether a repeating
672  /// group being referenced is empty.
673  bool empty() const
674  {
675  return 0 == size();
676  }
677 
678  /// Returns number of entries in a
679  /// repeating group being referenced.
680  Size size() const
681  {
682  return entryCount_;
683  }
684 
685  /// Returns iterator pointing to the first repeating group entry.
686  Iterator begin() const
687  {
688  return
689  Iterator(
690  entries_,
691  entrySize_,
692  version_);
693  }
694 
695  /// Returns iterator pointing to the entry behind the end of the group.
696  Iterator end() const
697  {
698  return
699  Iterator(
701  binary(),
702  binarySize()),
703  entrySize_,
704  version_);
705  }
706 
707  /// Provides access to a repeating group entry by index.
708  /// Index validness is not checked due to performance considerations.
709  Entry operator [](Size index) const
710  {
711  assert(index < size());
712 
713  return
714  Entry(
716  entries(),
717  index * entrySize_),
718  entrySize_,
719  version_);
720  }
721 
722  /// SBE-encoded data representing repeating group.
723  const void* binary() const
724  {
725  return
726  entries_
728  entries_, Dimension::Size)
729  : NULL;
730  }
731 
732  /// Size of SBE-encoded data representing repeating group.
733  BinarySize binarySize() const
734  {
735  return size_;
736  }
737 
738  /// Location of repeating group entries.
739  const void* entries() const
740  {
741  return entries_;
742  }
743 
744  /// Size in bytes of single repeating group entry.
746  {
747  return entrySize_;
748  }
749 
750  /// Re-initializes instance as copy of the other one.
751  BinaryGroup&
752  operator =(
753  const BinaryGroup& other)
754  {
755  entries_ = other.entries_;
756 
757  entrySize_ = other.entrySize_;
758  entryCount_ = other.entryCount_;
759 
760  version_ = other.version_;
761  size_ = other.size_;
762 
763  return *this;
764  }
765 
766 private:
767  const void* entries_;
768 
769  EntrySize entrySize_;
770  Size entryCount_;
771 
772  SchemaVersion version_;
773  BinarySize size_;
774 };
775 
776 /// Encapsulates operations over SBE-encoded repeating group.
777 template
778 <
779  class EntryType,
780  class DimensionType,
781  class GroupSizeType
782 >
784 {
785 public:
786  /// Aliases type of repeating group entry.
787  typedef EntryType Entry;
788 
789  /// Aliases repeating group dimension type.
790  typedef DimensionType Dimension;
791 
792  /// Length of group data.
793  typedef GroupSizeType BinarySize;
794 
795  /// Length of group entry data.
796  typedef
797  typename
800 
801 
802  /// Size of group (number of entries).
803  typedef
804  typename
805  Dimension::NumInGroup
807 
808  /// Provides iterating facilities
809  /// over SBE-encoded group entries.
810  class Iterator
811  {
812  const void* entry_;
813  EntrySize size_;
814 
815  SchemaVersion version_;
816 
817  public:
818  /// Aliases type of object referenced by iterator.
819  typedef EntryType Entry;
820 
821  /// Aliases entry for STL conformance.
822  typedef const Entry value_type;
823 
824  /// Aliases pointer to entry for STL conformance.
825  typedef const Entry* pointer;
826 
827  /// Aliases entry reference for STL conformance.
828  typedef const Entry& reference;
829 
830  /// Iterator difference type.
831  typedef ptrdiff_t difference_type;
832 
833  /// Identifies iterator category.
834  typedef
835  std::forward_iterator_tag
837 
838  /// Initializes instance referring to nothing.
840  : entry_(NULL)
841  , size_(0)
842  , version_(0)
843  {
844  }
845 
846  /// Initializes instance for given repeating group.
848  const void* entry,
849  EntrySize size,
850  SchemaVersion version)
851  : entry_(entry)
852  , size_(size)
853  , version_(version)
854  {
855  }
856 
857  /// Initializes instance as copy of the other one.
859  const Iterator& other)
860  : entry_(
861  other.entry_)
862  , size_(
863  other.size_)
864  , version_(
865  other.version_)
866  {
867  }
868 
869  /// Repeating group entry referenced by the instance.
870  const Entry get() const
871  {
872  assert(NULL != entry_);
873 
874  return
875  Entry(
876  entry_,
877  size_,
878  version_);
879  }
880 
881  /// Repeating group entry referenced by the instance.
882  const Entry operator *() const
883  {
884  return get();
885  }
886 
887  /// Compares given iterator with the other instance.
888  bool
890  const Iterator& other) const
891  {
892  return entry_ == other.entry_;
893  }
894 
895  /// Compares given iterator with the other instance.
896  bool
898  const Iterator& other) const
899  {
900  return entry_ != other.entry_;
901  }
902 
903  /// Established order between two iterators.
904  bool
906  const Iterator& other) const
907  {
908  return entry_ < other.entry_;
909  }
910 
911  /// Established order between two iterators.
912  bool
914  const Iterator& other) const
915  {
916  return entry_ > other.entry_;
917  }
918 
919  /// Advances instance to the next repeating group entry.
920  Iterator&
921  operator ++()
922  {
923  advance(1);
924  return *this;
925  }
926 
927  /// Advances instance by given number of entries.
928  Iterator
930  difference_type distance) const
931  {
932  Iterator result(*this);
933  result.advance(distance);
934  return result;
935  }
936 
937  /// Re-initializes instance as copy of the other one.
938  Iterator&
939  operator =(
940  const Iterator& other)
941  {
942  entry_ = other.entry_;
943  size_ = other.size_;
944 
945  version_ = other.version_;
946 
947  return *this;
948  }
949  private:
950  void advance(difference_type count)
951  {
952  const void* rawEntry = entry_;
953  for (difference_type i = 0; i < count; ++i)
954  {
955  // Query the last position of last repeating group at the entry.
956  // Here we need to has EntryType::next() method.
957  Entry e(rawEntry, size_, version_);
958  // Move entry over nested groups
959  rawEntry = e.next(version_).body();
960  }
961  entry_ = rawEntry;
962  }
963  };
964 
965  /// Initializes blank instance referencing to nothing.
967  : entries_(NULL)
968  , entrySize_(0)
969  , entryCount_(0)
970  , version_(0)
971  , size_(0)
972  {
973  }
974 
975  /// Initializes instance referencing
976  /// to a valid group of a given message.
978  const void* data,
979  BinarySize size,
980  SchemaVersion version)
981  : entries_(
983  data,
984  Dimension::Size))
985  , entrySize_(0)
986  , entryCount_(0)
987  , version_(version)
988  , size_(Dimension::Size)
989  {
990  if (size < size_)
992 
993  const
994  Dimension*
995  group =
996  static_cast
997  <const Dimension*>
998  (data);
999 
1000  entrySize_ =
1001  group->blockLength();
1002 
1003  entryCount_ =
1004  group->numInGroup();
1005 
1006  size_ += (static_cast<BinarySize>(entrySize_) * static_cast<BinarySize>(entryCount_));
1007 
1008  if (size < size_)
1010  }
1011 
1012  /// Initializes instance as a copy of the other one.
1014  const BinaryGroupWithNested& other)
1015  : entries_(
1016  other.entries_)
1017  , entrySize_(
1018  other.entrySize_)
1019  , entryCount_(
1020  other.entryCount_)
1021  , version_(
1022  other.version_)
1023  , size_(
1024  other.size_)
1025  {
1026  }
1027 
1028  /// Indicates whether given instance
1029  /// refers to a valid repeating group.
1030  operator bool() const
1031  {
1032  return (NULL != entries_);
1033  }
1034 
1035  /// Indicates whether a repeating
1036  /// group being referenced is empty.
1037  bool empty() const
1038  {
1039  return 0 == size();
1040  }
1041 
1042  /// Returns number of entries in a
1043  /// repeating group being referenced.
1044  Size size() const
1045  {
1046  return entryCount_;
1047  }
1048 
1049  /// Returns iterator pointing to the first repeating group entry.
1050  Iterator begin() const
1051  {
1052  return
1053  Iterator(
1054  entries_,
1055  entrySize_,
1056  version_);
1057  }
1058 
1059  /// Returns iterator pointing to the entry behind the end of the group.
1060  Iterator end() const
1061  {
1062  return begin() + size();
1063  }
1064 
1065  /// SBE-encoded data representing repeating group.
1066  const void* binary() const
1067  {
1068  return
1069  entries_
1071  entries_, Dimension::Size)
1072  : NULL;
1073  }
1074 
1075  /// Size of SBE-encoded data representing repeating group.
1076  BinarySize binarySize() const
1077  {
1078  return size_;
1079  }
1080 
1081  /// Location of repeating group entries.
1082  const void* entries() const
1083  {
1084  return entries_;
1085  }
1086 
1087  /// Size in bytes of single repeating group entry.
1089  {
1090  return entrySize_;
1091  }
1092 
1093  /// Re-initializes instance as copy of the other one.
1095  operator =(
1096  const BinaryGroupWithNested& other)
1097  {
1098  entries_ = other.entries_;
1099 
1100  entrySize_ = other.entrySize_;
1101  entryCount_ = other.entryCount_;
1102 
1103  version_ = other.version_;
1104  size_ = other.size_;
1105 
1106  return *this;
1107  }
1108 
1109 private:
1110  const void* entries_;
1111 
1112  EntrySize entrySize_;
1113  Size entryCount_;
1114 
1115  SchemaVersion version_;
1116  BinarySize size_;
1117 };
1118 
1119 /// Encapsulates services for manipulating SBE-encoded
1120 /// groups stored sequentially in SBE-encoded message.
1121 template
1122 <
1123  class BinarySize
1124 >
1126 {
1127  const void* binary_;
1128  BinarySize size_;
1129  SchemaVersion version_;
1130 
1131 public:
1132  /// Initializes empty list.
1134  : binary_(NULL)
1135  , size_(0)
1136  , version_(0)
1137  {
1138  }
1139 
1140  /// Initializes list over memory block,
1141  /// where given message is stored.
1143  const void* binary,
1144  BinarySize size,
1145  SchemaVersion version)
1146  : binary_(binary)
1147  , size_(size)
1148  , version_(version)
1149  {
1150  }
1151 
1152  /// Initializes as copy of other list.
1154  const BinaryGroupList& other)
1155  : binary_(
1156  other.binary_)
1157  , size_(
1158  other.size_)
1159  , version_(
1160  other.version_)
1161  {
1162  }
1163 
1164  /// Indicates whether group list is empty.
1165  bool empty() const
1166  {
1167  return (0 == size_);
1168  }
1169 
1170  /// Provides access to the head group of the list.
1171  template
1172  <
1173  class Group
1174  >
1175  Group head() const
1176  {
1177  return
1178  Group(
1179  binary_,
1180  size_,
1181  version_);
1182  }
1183 
1184  /// Returns list of groups following the head.
1185  template
1186  <
1187  class Group
1188  >
1190  {
1191  const
1192  BinarySize
1193  headSize =
1194  head<Group>().
1195  binarySize();
1196 
1197  assert(headSize <= size_);
1198 
1199  // TODO: Move the calculation to the group itslef,
1200  // to support nested groups.
1201  return
1204  binary_, headSize),
1205  size_ - headSize,
1206  version_);
1207  }
1208 
1209  /// SBE-encoded content referenced by given list.
1210  const void* binary() const
1211  {
1212  return binary_;
1213  }
1214 
1215  /// Size of SBE-encoded content referenced by the list.
1216  BinarySize binarySize() const
1217  {
1218  return size_;
1219  }
1220 
1221  /// Re-initializes instance as copy of the other one.
1223  operator =(
1224  const BinaryGroupList& other)
1225  {
1226  binary_ = other.binary_;
1227  size_ = other.size_;
1228 
1229  version_ = other.version_;
1230 
1231  return *this;
1232  }
1233 };
1234 
1235 
1236 
1237 
1238 /// Raises exception on bad binary message.
1239 inline
1240 void
1242 {
1243  throw std::runtime_error(
1244  "Cannot construct message instance. Memory "
1245  "block is too small to access SBE message header. ");
1246 }
1247 
1248 /// Aliases message length type.
1250 
1251 /// Length of message binary data.
1253 
1254 /// Length of message body representing
1255 /// a block of fixed-length fields.
1257 
1258 /// Encapsulates operations over SBE-encoded
1259 /// repeating group entry instance.
1260 template
1261 <
1262  class BodySizeType
1263 >
1264 class
1266  : public BinaryFields
1267  <
1269  <
1270  BodySizeType
1271  >,
1272  BodySizeType
1273  >
1274 {
1275  const void* body_;
1276  BodySizeType size_;
1277 
1278  SchemaVersion version_;
1279 
1280 protected:
1281  /// Binary group list instantiation.
1282  typedef
1285 
1286  /// Returns list of repeating groups
1287  /// of a entry being referenced.
1289  {
1290  const void*
1291  const list =
1293  body(), bodySize());
1294 
1295  //const
1296  // MessageSize
1297  // listSize =
1298  // size_ - entrySize;
1299 
1300  return
1301  GroupList(
1302  list,
1303  10000,
1304  version_);
1305  }
1306 
1307 public:
1308  /// Type to present length of binary
1309  /// data of given repeating group entry.
1310  typedef
1311  BodySizeType
1313 
1314  /// Initializes instance referring to nothing.
1316  : body_(NULL)
1317  , size_(0)
1318  , version_(0)
1319  {
1320  }
1321 
1322  /// Initializes instance from memory
1323  /// block of given SBE-encoded message.
1325  const void* body,
1326  BodySize size,
1327  SchemaVersion version)
1328  : body_(body)
1329  , size_(size)
1330  , version_(version)
1331  {
1332  assert(NULL != body);
1333 
1334  assert(
1335  version >=
1336  SchemaTraits::
1337  minimalVersion());
1338  }
1339 
1340  /// Initializes instance as a copy of the other one.
1342  const BinaryGroupEntry& other)
1343  : body_(
1344  other.body_)
1345  , size_(
1346  other.size_)
1347  , version_(
1348  other.version_)
1349  {
1350  }
1351 
1352  /// Indicates whether instance refers to a valid content.
1353  operator bool() const
1354  {
1355  return (NULL != body_);
1356  }
1357 
1358  /// Indicates beginning of group entry body.
1359  const void* body() const
1360  {
1361  return body_;
1362  }
1363 
1364  /// Indicates end of group entry body.
1366  {
1367  return size_;
1368  }
1369 
1370  /// Version of message containing
1371  /// given repeating group instance.
1373  {
1374  return version_;
1375  }
1376 
1377  /// Re-initializes instance as a copy of the other one.
1379  operator =(
1380  const BinaryGroupEntry& other)
1381  {
1382  body_ = other.body_;
1383  size_ = other.size_;
1384 
1385  version_ = other.version_;
1386 
1387  return *this;
1388  }
1389 };
1390 
1391 
1392 /// Raises exception on bad message version.
1393 ONIXS_CMESTREAMLINEDMDH_EXPORTED
1394 void
1396  SchemaVersion messageVersion);
1397 
1398 /// Aliases message type (template) identification.
1399 typedef
1402 
1403 /// Encapsulates services for manipulating SBE-encoded messages.
1406 : public BinaryFields
1407 <
1408  BinaryMessage,
1409  MessageSize
1410 >
1411 {
1412  const MessageHeader* header_;
1413  MessageSize size_;
1414 
1415 protected:
1416  /// Binary group list instantiation.
1417  typedef
1420 
1421  /// Returns list of repeating groups
1422  /// of a message being referenced.
1424  {
1425  assert(NULL != header_);
1426 
1427  const void*
1428  const list =
1430  body(), bodySize());
1431 
1432  const
1433  MessageSize
1434  listSize =
1435  size_ -
1436  MessageHeader::Size -
1437  header_->blockLength();
1438 
1439  return
1440  GroupList(
1441  list,
1442  listSize,
1443  header_->version());
1444  }
1445 
1446 public:
1447  /// Length of message binary data.
1449 
1450  /// Length of message body without repeating groups.
1451  typedef
1454 
1455  /// Initializes blank instance referencing to nothing.
1457  : header_(NULL)
1458  , size_(0)
1459  {
1460  }
1461 
1462  /// Initializes instance over given memory block.
1464  const void* data,
1465  MessageSize size)
1466  : header_(
1467  static_cast
1468  <const MessageHeader*>
1469  (data))
1470  , size_(size)
1471  {
1472  assert(NULL != data);
1473 
1474  if (size <
1475  MessageHeader::Size
1476  ||
1477  size <
1478  (MessageHeader::Size +
1479  header_->blockLength()))
1480  {
1482  }
1483 
1484  const
1485  SchemaVersion
1486  version = this->version();
1487 
1488  if (version <
1489  SchemaTraits::minimalVersion())
1490  {
1491  throwBadMessageVersion(version);
1492  }
1493  }
1494 
1495  /// Initializes instance as copy of the other one.
1497  const BinaryMessage& other)
1498  : header_(other.header_)
1499  , size_(other.size_)
1500  {
1501  }
1502 
1503  /// Indicates whether instance refers to a valid message.
1504  operator bool() const
1505  {
1506  return (NULL != header_);
1507  }
1508 
1509  /// Template identifier of message being referenced.
1511  {
1512  assert(NULL != header_);
1513 
1514  return header_->templateId();
1515  }
1516 
1517  /// Version of message being referenced.
1519  {
1520  assert(NULL != header_);
1521 
1522  return header_->version();
1523  }
1524 
1525  /// SBE-encoded message content.
1526  const void* binary() const
1527  {
1528  return header_;
1529  }
1530 
1531  /// Size of SBE-encoded message.
1533  {
1534  return size_;
1535  }
1536 
1537  /// Indicates beginning of message body.
1538  const void* body() const
1539  {
1540  assert(NULL != header_);
1541 
1542  return
1544  header_,
1545  MessageHeader::Size);
1546  }
1547 
1548  /// Size of message body in bytes.
1550  {
1551  assert(NULL != header_);
1552 
1553  return header_->blockLength();
1554  }
1555 
1556  /// Re-initializes instance as a copy of the other one.
1557  BinaryMessage&
1558  operator =(
1559  const BinaryMessage& other)
1560  {
1561  header_ = other.header_;
1562  size_ = other.size_;
1563 
1564  return *this;
1565  }
1566 };
1567 
BinaryGroup(const BinaryGroup &other)
Initializes instance as a copy of the other one.
Timestamp operator-(const Timestamp &timestamp, const TimeSpan &timeSpan)
Subtracts time interval from given time point.
Definition: Time.h:743
Dimension::NumInGroup Size
Size of group (number of entries).
Encapsulates services for manipulating SBE-encoded messages.
BinaryGroupList(const void *binary, BinarySize size, SchemaVersion version)
BinaryGroupWithNested(const BinaryGroupWithNested &other)
Initializes instance as a copy of the other one.
const Entry * pointer
Aliases pointer to entry for STL conformance.
BinaryGroupList< MessageSize > GroupList
Binary group list instantiation.
bool operator!=(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:134
BinaryGroupEntry(const BinaryGroupEntry &other)
Initializes instance as a copy of the other one.
Iterator(const Iterator &other)
Initializes instance as copy of the other one.
Encapsulates operations over SBE-encoded repeating group.
StrRef fixedStr(BlockSize offset) const
bool operator==(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:116
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:121
UInt16 BlockLength
blockLength type.
Definition: Composites.h:461
bool enumeration(typename Enumeration::Enum &value, BlockSize offset, const NullValue &null) const
EntryType Entry
Aliases type of object referenced by iterator.
Encapsulates operations over SBE-encoded repeating group.
BinarySize binarySize() const
Size of SBE-encoded data representing repeating group.
Group head() const
Provides access to the head group of the list.
const void * body() const
Indicates beginning of message body.
void throwBadBinaryMessage()
Raises exception on bad binary message.
bool enumeration(typename Enumeration::Enum &value, BlockSize offset, const NullValue &null, SchemaVersion since) const
BinaryGroupWithNested()
Initializes blank instance referencing to nothing.
MessageSize BinarySize
Length of message binary data.
UInt16 UInt16
uInt16.
Definition: Fields.h:179
EntryType Entry
Aliases type of repeating group entry.
MessageHeader::TemplateId MessageTemplateId
Aliases message type (template) identification.
MessageHeader::Version SchemaVersion
Aliases SBE-encoded data version type.
Definition: SchemaTraits.h:30
BinaryMessage()
Initializes blank instance referencing to nothing.
Enumeration::Enum enumeration(BlockSize offset) const
const Entry & reference
Aliases entry reference for STL conformance.
GroupSizeType BinarySize
Length of group data.
BinaryGroup(const void *data, BinarySize size, SchemaVersion version)
Iterator end() const
Returns iterator pointing to the entry behind the end of the group.
GroupSizeType BinarySize
Length of group data.
EntryType Entry
Aliases type of object referenced by iterator.
ONIXS_CMESTREAMLINEDMDH_EXPORTED void throwBadBinaryGroup()
Throws exception on bad repeating group.
MessageTemplateId templateId() const
Template identifier of message being referenced.
StrRef fixedStr(BlockSize offset, SchemaVersion since) const
BodySize bodySize() const
Indicates end of group entry body.
DimensionType::BlockLength EntrySize
Length of group entry data.
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Definition: Memory.h:140
BinaryFields()
Initializes blank instance.
Definition: BinaryMessage.h:54
BinaryMessage(const void *data, MessageSize size)
Initializes instance over given memory block.
BinaryGroup()
Initializes blank instance referencing to nothing.
std::random_access_iterator_tag iterator_category
Identifies iterator category.
Template ID and length of message root.
Definition: Composites.h:454
Attributes of SBE message schema.
Definition: SchemaTraits.h:33
Dimension::NumInGroup Size
Size of group (number of entries).
BinaryGroupWithNested(const void *data, BinarySize size, SchemaVersion version)
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_END
Definition: Bootstrap.h:172
#define ONIXS_CMESTREAMLINEDMDH_LTWT_CLASS
Definition: Bootstrap.h:110
char Char
Character type alias.
Definition: String.h:36
bool fixedStr(StrRef &value, BlockSize offset) const
MessageHeader::BlockLength BodySize
Length of message body without repeating groups.
Iterator begin() const
Returns iterator pointing to the first repeating group entry.
BinaryGroupEntry(const void *body, BodySize size, SchemaVersion version)
bool decimal(Decimal &value, BlockSize offset, const NullValue &null) const
Iterator()
Initializes instance referring to nothing.
bool ordinary(FieldValue &value, BlockSize offset, const NullValue &null) const
const void * binary() const
SBE-encoded content referenced by given list.
UInt16 MessageSize
Aliases message length type.
BodySize bodySize() const
Size of message body in bytes.
const void * binary() const
SBE-encoded data representing repeating group.
DimensionType::BlockLength EntrySize
Length of group entry data.
const Entry & reference
Aliases entry reference for STL conformance.
const Entry value_type
Aliases entry for STL conformance.
BinaryGroupList tail() const
Returns list of groups following the head.
BinaryGroupList(const BinaryGroupList &other)
Initializes as copy of other list.
Iterator(const void *entry, EntrySize size, SchemaVersion version)
Initializes instance for given repeating group.
bool empty() const
Indicates whether group list is empty.
const void * entries() const
Location of repeating group entries.
Iterator end() const
Returns iterator pointing to the entry behind the end of the group.
ptrdiff_t difference_type
Iterator difference type.
DimensionType Dimension
Aliases repeating group dimension type.
bool operator<(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:152
const void * binary() const
SBE-encoded message content.
SchemaVersion version() const
Version of message being referenced.
Iterator begin() const
Returns iterator pointing to the first repeating group entry.
TemplateId templateId() const
templateId field.
Definition: Composites.h:490
ONIXS_CMESTREAMLINEDMDH_EXPORTED void throwBadMessageVersion(SchemaVersion messageVersion)
Raises exception on bad message version.
MessageSize binarySize() const
Size of SBE-encoded message.
const void * body() const
Indicates beginning of group entry body.
std::forward_iterator_tag iterator_category
Identifies iterator category.
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:39
EntryType Entry
Aliases type of repeating group entry.
BlockLength blockLength() const
blockLength field.
Definition: Composites.h:484
A real number with floating exponent.
Definition: Decimal.h:224
const void * entries() const
Location of repeating group entries.
Iterator()
Initializes instance referring to nothing.
BinarySize binarySize() const
Size of SBE-encoded content referenced by the list.
BinaryGroupList< MessageSize > GroupList
Binary group list instantiation.
Version version() const
version field.
Definition: Composites.h:502
DimensionType Dimension
Aliases repeating group dimension type.
EntrySize entrySize() const
Size in bytes of single repeating group entry.
BinaryMessage(const BinaryMessage &other)
Initializes instance as copy of the other one.
ONIXS_CMESTREAMLINEDMDH_EXPORTED void throwBadBinaryData(const Char *className)
Throws exception on bad repeating group entry.
const void * binary() const
SBE-encoded data representing repeating group.
const Entry value_type
Aliases entry for STL conformance.
BinarySize binarySize() const
Size of SBE-encoded data representing repeating group.
const FieldValue & ordinary(BlockSize offset) const
Returns value of a field by its offset.
Definition: BinaryMessage.h:70
Decimal decimal(BlockSize offset) const
bool operator>(const FixedPointDecimal< Mantissa, Exponent > &left, const FixedPointDecimal< Mantissa, Exponent > &right)
Compares two fixed-point decimals.
Definition: Decimal.h:170
MessageSize EncodedLength
Length of message binary data.
bool ordinary(FieldValue &value, BlockSize offset, const NullValue &null, SchemaVersion since) const
BinaryGroupEntry()
Initializes instance referring to nothing.
Iterator(const Iterator &other)
Initializes instance as copy of the other one.
Iterator(const void *entry, EntrySize size, SchemaVersion version)
Initializes instance for given repeating group.
Timestamp operator+(const Timestamp &timestamp, const TimeSpan &timeSpan)
Adds time interval to given time point.
Definition: Time.h:729
EntrySize entrySize() const
Size in bytes of single repeating group entry.
const Entry * pointer
Aliases pointer to entry for STL conformance.
#define ONIXS_CMESTREAMLINEDMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:168