OnixS C++ CME Streamlined Market Data Handler  1.0.0.4
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  /// Provides access to a value of
120  /// an optional field by its offset.
121  ///
122  /// Returned result indicates whether field is
123  /// present in given field block and its value
124  /// was copied into a given parameter-variable.
125  ///
126  /// Field may not be present in earlier versions
127  /// of binary message and thus its value may not be
128  /// available. For this reason, parameter indicating
129  /// version of data assumed is required to access
130  /// the field.
131  template
132  <
133  class FieldValue,
134  class NullValue
135  >
136  bool
138  FieldValue& value,
139  BlockSize offset,
140  const NullValue& null,
141  SchemaVersion since) const
142  {
143  return (
144  since <= block().version()
145  &&
146  ordinary(value, offset, null)
147  );
148  }
149 
150  /// Returns value of a field by its offset.
151  ///
152  /// Given function serves as specialization of
153  /// general case for fields of enumeration type.
154  template
155  <
156  class Enumeration
157  >
158  typename
159  Enumeration::Enum
161  BlockSize offset) const
162  {
163  typedef
164  typename
165  Enumeration::Base
166  Base;
167 
168  typedef
169  typename
170  Enumeration::Enum
171  Enum;
172 
173  return
174  static_cast<Enum>(
175  ordinary<Base>(offset));
176  }
177 
178  /// Provides access to value of
179  /// an optional field by its offset.
180  ///
181  /// Given function serves as specialization of
182  /// general case for fields of enumeration type.
183  template
184  <
185  class Enumeration,
186  class NullValue
187  >
188  bool
190  typename
191  Enumeration::Enum& value,
192  BlockSize offset,
193  const NullValue& null) const
194  {
195  typedef
196  typename
197  Enumeration::Base
198  Base;
199 
200  typedef
201  typename
202  Enumeration::Enum
203  Enum;
204 
205  const Base& fieldValue =
206  ordinary<Base>(offset);
207 
208  if (null != fieldValue)
209  {
210  value = static_cast<Enum>(fieldValue);
211 
212  return true;
213  }
214 
215  return false;
216  }
217 
218  /// Provides access to value of
219  /// an optional field by its offset.
220  ///
221  /// Given function serves as specialization of
222  /// general case for fields of enumeration type.
223  template
224  <
225  class Enumeration,
226  class NullValue
227  >
228  bool
230  typename
231  Enumeration::Enum& value,
232  BlockSize offset,
233  const NullValue& null,
234  SchemaVersion since) const
235  {
236  return (
237  since <= block().version()
238  &&
239  enumeration(value, offset, null)
240  );
241  }
242 
243  /// Provides access to string field by its offset.
244  ///
245  /// Given function serves as specialization
246  /// of general case for fields of string type.
247  template
248  <
249  BlockSize Size
250  >
251  StrRef
253  BlockSize offset) const
254  {
255  typedef Char Str[Size];
256 
257  const Str& str =
258  ordinary<Str>(offset);
259 
260  return
261  StrRef
262  (
263  str,
264  strnlen(str, Size)
265  );
266  }
267 
268  /// Provides access to an optional
269  /// field of string type by its offset.
270  ///
271  /// Given function serves as specialization
272  /// of general case for fields of string type.
273  template
274  <
275  BlockSize Size
276  >
277  StrRef
279  BlockSize offset,
280  SchemaVersion since) const
281  {
282  return (
283  since >=
284  block().version()
285 
286  ? fixedStr<Size>(offset)
287  : StrRef()
288  );
289  }
290 
291  /// Provides access to an optional
292  /// field of string type by its offset.
293  ///
294  /// Given function serves as specialization
295  /// of general case for fields of string type.
296  template
297  <
298  BlockSize Size
299  >
300  bool
302  StrRef& value,
303  BlockSize offset) const
304  {
305  typedef Char Str[Size];
306 
307  const Str& str =
308  ordinary<Str>(offset);
309 
310  if (str[0])
311  {
312  value = fixedStr<Size>(offset);
313  return true;
314  }
315  else
316  {
317  return false;
318  }
319  }
320 };
321 
322 /// Throws exception on bad repeating group entry.
323 ONIXS_CMESTREAMLINEDMDH_EXPORTED
324 void
326  const Char* className);
327 
328 /// Throws exception on bad repeating group.
329 ONIXS_CMESTREAMLINEDMDH_EXPORTED
330 void
332 
333 /// Encapsulates operations over SBE-encoded repeating group.
334 template
335 <
336  class EntryType,
337  class DimensionType,
338  class GroupSizeType
339 >
341 {
342 public:
343  /// Aliases type of repeating group entry.
344  typedef EntryType Entry;
345 
346  /// Aliases repeating group dimension type.
347  typedef DimensionType Dimension;
348 
349  /// Length of group data.
350  typedef GroupSizeType BinarySize;
351 
352  /// Length of group entry data.
353  typedef
354  typename
355  DimensionType::BlockLength
357 
358 
359  /// Size of group (number of entries).
360  typedef
361  typename
362  Dimension::NumInGroup
364 
365  /// Provides iterating facilities
366  /// over SBE-encoded group entries.
367  class Iterator
368  {
369  const void* entry_;
370  EntrySize size_;
371 
372  SchemaVersion version_;
373 
374  public:
375  /// Aliases type of object referenced by iterator.
376  typedef EntryType Entry;
377 
378  /// Aliases entry for STL conformance.
379  typedef const Entry value_type;
380 
381  /// Aliases pointer to entry for STL conformance.
382  typedef const Entry* pointer;
383 
384  /// Aliases entry reference for STL conformance.
385  typedef const Entry& reference;
386 
387  /// Iterator difference type.
388  typedef ptrdiff_t difference_type;
389 
390  /// Identifies iterator category.
391  typedef
392  std::random_access_iterator_tag
394 
395  /// Initializes instance referring to nothing.
397  : entry_(NULL)
398  , size_(0)
399  , version_(0)
400  {
401  }
402 
403  /// Initializes instance for given repeating group.
405  const void* entry,
406  EntrySize size,
407  SchemaVersion version)
408  : entry_(entry)
409  , size_(size)
410  , version_(version)
411  {
412  }
413 
414  /// Initializes instance as copy of the other one.
416  const Iterator& other)
417  : entry_(
418  other.entry_)
419  , size_(
420  other.size_)
421  , version_(
422  other.version_)
423  {
424  }
425 
426  /// Repeating group entry referenced by the instance.
427  const Entry get() const
428  {
429  assert(NULL != entry_);
430 
431  return
432  Entry(
433  entry_,
434  size_,
435  version_);
436  }
437 
438  /// Repeating group entry referenced by the instance.
439  const Entry operator *() const
440  {
441  return get();
442  }
443 
444  /// Compares given iterator with the other instance.
445  bool
447  const Iterator& other) const
448  {
449  return entry_ == other.entry_;
450  }
451 
452  /// Compares given iterator with the other instance.
453  bool
455  const Iterator& other) const
456  {
457  return entry_ != other.entry_;
458  }
459 
460  /// Established order between two iterators.
461  bool
463  const Iterator& other) const
464  {
465  return entry_ < other.entry_;
466  }
467 
468  /// Established order between two iterators.
469  bool
471  const Iterator& other) const
472  {
473  return entry_ > other.entry_;
474  }
475 
476  /// Advances instance to the next repeating group entry.
477  Iterator&
478  operator ++()
479  {
480  entry_ =
482  entry_, size_);
483 
484  return *this;
485  }
486 
487  /// Advances instance to the next repeating group entry.
488  Iterator&
489  operator --()
490  {
491  entry_ =
493  entry_,
494  size_);
495 
496  return *this;
497  }
498 
499  /// Advances instance by given number of entries.
500  Iterator
502  difference_type distance) const
503  {
504  return
505  Iterator(
507  entry_,
508  distance * size_),
509  size_,
510  version_);
511  }
512 
513  /// Advances instance by given number of entries.
514  Iterator
516  difference_type distance) const
517  {
518  return
519  Iterator(
521  entry_,
522  distance * size_),
523  size_,
524  version_);
525  }
526 
527  /// Re-initializes instance as copy of the other one.
528  Iterator&
529  operator =(
530  const Iterator& other)
531  {
532  entry_ = other.entry_;
533  size_ = other.size_;
534 
535  version_ = other.version_;
536 
537  return *this;
538  }
539  };
540 
541  /// Initializes blank instance referencing to nothing.
543  : entries_(NULL)
544  , entrySize_(0)
545  , entryCount_(0)
546  , version_(0)
547  , size_(0)
548  {
549  }
550 
551  /// Initializes instance referencing
552  /// to a valid group of a given message.
554  const void* data,
555  BinarySize size,
556  SchemaVersion version)
557  : entries_(
559  data,
560  Dimension::Size))
561  , entrySize_(0)
562  , entryCount_(0)
563  , version_(version)
564  , size_(Dimension::Size)
565  {
566  if (size < size_)
568 
569  const
570  Dimension*
571  group =
572  static_cast
573  <const Dimension*>
574  (data);
575 
576  entrySize_ =
577  group->blockLength();
578 
579  entryCount_ =
580  group->numInGroup();
581 
582  size_ +=
583  (
584  static_cast
585  <BinarySize>
586  (entrySize_) *
587  static_cast
588  <BinarySize>
589  (entryCount_)
590  );
591 
592  if (size < size_)
594  }
595 
596  /// Initializes instance as a copy of the other one.
598  const BinaryGroup& other)
599  : entries_(
600  other.entries_)
601  , entrySize_(
602  other.entrySize_)
603  , entryCount_(
604  other.entryCount_)
605  , version_(
606  other.version_)
607  , size_(
608  other.size_)
609  {
610  }
611 
612  /// Indicates whether given instance
613  /// refers to a valid repeating group.
614  operator bool() const
615  {
616  return (NULL != entries_);
617  }
618 
619  /// Indicates whether a repeating
620  /// group being referenced is empty.
621  bool empty() const
622  {
623  return 0 == size();
624  }
625 
626  /// Returns number of entries in a
627  /// repeating group being referenced.
628  Size size() const
629  {
630  return entryCount_;
631  }
632 
633  /// Returns iterator pointing to the first repeating group entry.
634  Iterator begin() const
635  {
636  return
637  Iterator(
638  entries_,
639  entrySize_,
640  version_);
641  }
642 
643  /// Returns iterator pointing to the entry behind the end of the group.
644  Iterator end() const
645  {
646  return
647  Iterator(
649  binary(),
650  binarySize()),
651  entrySize_,
652  version_);
653  }
654 
655  /// Provides access to a repeating group entry by index.
656  /// Index validness is not checked due to performance considerations.
657  Entry operator [](Size index) const
658  {
659  assert(index < size());
660 
661  return
662  Entry(
664  entries(),
665  index * entrySize_),
666  entrySize_,
667  version_);
668  }
669 
670  /// SBE-encoded data representing repeating group.
671  const void* binary() const
672  {
673  return
674  entries_
676  entries_, Dimension::Size)
677  : NULL;
678  }
679 
680  /// Size of SBE-encoded data representing repeating group.
681  BinarySize binarySize() const
682  {
683  return size_;
684  }
685 
686  /// Location of repeating group entries.
687  const void* entries() const
688  {
689  return entries_;
690  }
691 
692  /// Size in bytes of single repeating group entry.
694  {
695  return entrySize_;
696  }
697 
698  /// Re-initializes instance as copy of the other one.
699  BinaryGroup&
700  operator =(
701  const BinaryGroup& other)
702  {
703  entries_ = other.entries_;
704 
705  entrySize_ = other.entrySize_;
706  entryCount_ = other.entryCount_;
707 
708  version_ = other.version_;
709  size_ = other.size_;
710 
711  return *this;
712  }
713 
714 private:
715  const void* entries_;
716 
717  EntrySize entrySize_;
718  Size entryCount_;
719 
720  SchemaVersion version_;
721  BinarySize size_;
722 };
723 
724 /// Encapsulates operations over SBE-encoded repeating group.
725 template
726 <
727  class EntryType,
728  class DimensionType,
729  class GroupSizeType
730 >
732 {
733 public:
734  /// Aliases type of repeating group entry.
735  typedef EntryType Entry;
736 
737  /// Aliases repeating group dimension type.
738  typedef DimensionType Dimension;
739 
740  /// Length of group data.
741  typedef GroupSizeType BinarySize;
742 
743  /// Length of group entry data.
744  typedef
745  typename
746  DimensionType::BlockLength
748 
749 
750  /// Size of group (number of entries).
751  typedef
752  typename
753  Dimension::NumInGroup
755 
756  /// Provides iterating facilities
757  /// over SBE-encoded group entries.
758  class Iterator
759  {
760  const void* entry_;
761  EntrySize size_;
762 
763  SchemaVersion version_;
764 
765  public:
766  /// Aliases type of object referenced by iterator.
767  typedef EntryType Entry;
768 
769  /// Aliases entry for STL conformance.
770  typedef const Entry value_type;
771 
772  /// Aliases pointer to entry for STL conformance.
773  typedef const Entry* pointer;
774 
775  /// Aliases entry reference for STL conformance.
776  typedef const Entry& reference;
777 
778  /// Iterator difference type.
779  typedef ptrdiff_t difference_type;
780 
781  /// Identifies iterator category.
782  typedef
783  std::forward_iterator_tag
785 
786  /// Initializes instance referring to nothing.
788  : entry_(NULL)
789  , size_(0)
790  , version_(0)
791  {
792  }
793 
794  /// Initializes instance for given repeating group.
796  const void* entry,
797  EntrySize size,
798  SchemaVersion version)
799  : entry_(entry)
800  , size_(size)
801  , version_(version)
802  {
803  }
804 
805  /// Initializes instance as copy of the other one.
807  const Iterator& other)
808  : entry_(
809  other.entry_)
810  , size_(
811  other.size_)
812  , version_(
813  other.version_)
814  {
815  }
816 
817  /// Repeating group entry referenced by the instance.
818  const Entry get() const
819  {
820  assert(NULL != entry_);
821 
822  return
823  Entry(
824  entry_,
825  size_,
826  version_);
827  }
828 
829  /// Repeating group entry referenced by the instance.
830  const Entry operator *() const
831  {
832  return get();
833  }
834 
835  /// Compares given iterator with the other instance.
836  bool
838  const Iterator& other) const
839  {
840  return entry_ == other.entry_;
841  }
842 
843  /// Compares given iterator with the other instance.
844  bool
846  const Iterator& other) const
847  {
848  return entry_ != other.entry_;
849  }
850 
851  /// Established order between two iterators.
852  bool
854  const Iterator& other) const
855  {
856  return entry_ < other.entry_;
857  }
858 
859  /// Established order between two iterators.
860  bool
862  const Iterator& other) const
863  {
864  return entry_ > other.entry_;
865  }
866 
867  /// Advances instance to the next repeating group entry.
868  Iterator&
869  operator ++()
870  {
871  advance(1);
872  return *this;
873  }
874 
875  /// Advances instance by given number of entries.
876  Iterator
878  difference_type distance) const
879  {
880  Iterator result(*this);
881  result.advance(distance);
882  return result;
883  }
884 
885  /// Re-initializes instance as copy of the other one.
886  Iterator&
887  operator =(
888  const Iterator& other)
889  {
890  entry_ = other.entry_;
891  size_ = other.size_;
892 
893  version_ = other.version_;
894 
895  return *this;
896  }
897  private:
898  void advance(difference_type count)
899  {
900  const void* rawEntry = entry_;
901  for (difference_type i = 0; i < count; ++i)
902  {
903  // Query the last position of last repeating group at the entry.
904  // Here we need to has EntryType::next() method.
905  Entry e(rawEntry, size_, version_);
906  // Move entry over nested groups
907  rawEntry = e.next(version_).body();
908  }
909  entry_ = rawEntry;
910  }
911  };
912 
913  /// Initializes blank instance referencing to nothing.
915  : entries_(NULL)
916  , entrySize_(0)
917  , entryCount_(0)
918  , version_(0)
919  , size_(0)
920  {
921  }
922 
923  /// Initializes instance referencing
924  /// to a valid group of a given message.
926  const void* data,
927  BinarySize size,
928  SchemaVersion version)
929  : entries_(
931  data,
932  Dimension::Size))
933  , entrySize_(0)
934  , entryCount_(0)
935  , version_(version)
936  , size_(Dimension::Size)
937  {
938  if (size < size_)
940 
941  const
942  Dimension*
943  group =
944  static_cast
945  <const Dimension*>
946  (data);
947 
948  entrySize_ =
949  group->blockLength();
950 
951  entryCount_ =
952  group->numInGroup();
953 
954  size_ += (static_cast<BinarySize>(entrySize_) * static_cast<BinarySize>(entryCount_));
955 
956  if (size < size_)
958  }
959 
960  /// Initializes instance as a copy of the other one.
962  const BinaryGroupWithNested& other)
963  : entries_(
964  other.entries_)
965  , entrySize_(
966  other.entrySize_)
967  , entryCount_(
968  other.entryCount_)
969  , version_(
970  other.version_)
971  , size_(
972  other.size_)
973  {
974  }
975 
976  /// Indicates whether given instance
977  /// refers to a valid repeating group.
978  operator bool() const
979  {
980  return (NULL != entries_);
981  }
982 
983  /// Indicates whether a repeating
984  /// group being referenced is empty.
985  bool empty() const
986  {
987  return 0 == size();
988  }
989 
990  /// Returns number of entries in a
991  /// repeating group being referenced.
992  Size size() const
993  {
994  return entryCount_;
995  }
996 
997  /// Returns iterator pointing to the first repeating group entry.
998  Iterator begin() const
999  {
1000  return
1001  Iterator(
1002  entries_,
1003  entrySize_,
1004  version_);
1005  }
1006 
1007  /// Returns iterator pointing to the entry behind the end of the group.
1008  Iterator end() const
1009  {
1010  return begin() + size();
1011  }
1012 
1013  /// SBE-encoded data representing repeating group.
1014  const void* binary() const
1015  {
1016  return
1017  entries_
1019  entries_, Dimension::Size)
1020  : NULL;
1021  }
1022 
1023  /// Size of SBE-encoded data representing repeating group.
1024  BinarySize binarySize() const
1025  {
1026  return size_;
1027  }
1028 
1029  /// Location of repeating group entries.
1030  const void* entries() const
1031  {
1032  return entries_;
1033  }
1034 
1035  /// Size in bytes of single repeating group entry.
1037  {
1038  return entrySize_;
1039  }
1040 
1041  /// Re-initializes instance as copy of the other one.
1043  operator =(
1044  const BinaryGroupWithNested& other)
1045  {
1046  entries_ = other.entries_;
1047 
1048  entrySize_ = other.entrySize_;
1049  entryCount_ = other.entryCount_;
1050 
1051  version_ = other.version_;
1052  size_ = other.size_;
1053 
1054  return *this;
1055  }
1056 
1057 private:
1058  const void* entries_;
1059 
1060  EntrySize entrySize_;
1061  Size entryCount_;
1062 
1063  SchemaVersion version_;
1064  BinarySize size_;
1065 };
1066 
1067 /// Encapsulates services for manipulating SBE-encoded
1068 /// groups stored sequentially in SBE-encoded message.
1069 template
1070 <
1071  class BinarySize
1072 >
1074 {
1075  const void* binary_;
1076  BinarySize size_;
1077  SchemaVersion version_;
1078 
1079 public:
1080  /// Initializes empty list.
1082  : binary_(NULL)
1083  , size_(0)
1084  , version_(0)
1085  {
1086  }
1087 
1088  /// Initializes list over memory block,
1089  /// where given message is stored.
1091  const void* binary,
1092  BinarySize size,
1093  SchemaVersion version)
1094  : binary_(binary)
1095  , size_(size)
1096  , version_(version)
1097  {
1098  }
1099 
1100  /// Initializes as copy of other list.
1102  const BinaryGroupList& other)
1103  : binary_(
1104  other.binary_)
1105  , size_(
1106  other.size_)
1107  , version_(
1108  other.version_)
1109  {
1110  }
1111 
1112  /// Indicates whether group list is empty.
1113  bool empty() const
1114  {
1115  return (0 == size_);
1116  }
1117 
1118  /// Provides access to the head group of the list.
1119  template
1120  <
1121  class Group
1122  >
1123  Group head() const
1124  {
1125  return
1126  Group(
1127  binary_,
1128  size_,
1129  version_);
1130  }
1131 
1132  /// Returns list of groups following the head.
1133  template
1134  <
1135  class Group
1136  >
1138  {
1139  const
1140  BinarySize
1141  headSize =
1142  head<Group>().
1143  binarySize();
1144 
1145  assert(headSize <= size_);
1146 
1147  // TODO: Move the calculation to the group itslef,
1148  // to support nested groups.
1149  return
1152  binary_, headSize),
1153  size_ - headSize,
1154  version_);
1155  }
1156 
1157  /// SBE-encoded content referenced by given list.
1158  const void* binary() const
1159  {
1160  return binary_;
1161  }
1162 
1163  /// Size of SBE-encoded content referenced by the list.
1164  BinarySize binarySize() const
1165  {
1166  return size_;
1167  }
1168 
1169  /// Re-initializes instance as copy of the other one.
1171  operator =(
1172  const BinaryGroupList& other)
1173  {
1174  binary_ = other.binary_;
1175  size_ = other.size_;
1176 
1177  version_ = other.version_;
1178 
1179  return *this;
1180  }
1181 };
1182 
1183 
1184 
1185 
1186 /// Raises exception on bad binary message.
1187 inline
1188 void
1190 {
1191  throw std::runtime_error(
1192  "Cannot construct message instance. Memory "
1193  "block is too small to access SBE message header. ");
1194 }
1195 
1196 /// Aliases message length type.
1198 
1199 /// Encapsulates operations over SBE-encoded
1200 /// repeating group entry instance.
1201 template
1202 <
1203  class BodySizeType
1204 >
1205 class
1207  : public BinaryFields
1208  <
1210  <
1211  BodySizeType
1212  >,
1213  BodySizeType
1214  >
1215 {
1216  const void* body_;
1217  BodySizeType size_;
1218 
1219  SchemaVersion version_;
1220 
1221 protected:
1222  /// Binary group list instantiation.
1223  typedef
1226 
1227  /// Returns list of repeating groups
1228  /// of a entry being referenced.
1230  {
1231  const void*
1232  const list =
1234  body(), bodySize());
1235 
1236  //const
1237  // MessageSize
1238  // listSize =
1239  // size_ - entrySize;
1240 
1241  return
1242  GroupList(
1243  list,
1244  10000,
1245  version_);
1246  }
1247 
1248 public:
1249  /// Type to present length of binary
1250  /// data of given repeating group entry.
1251  typedef
1252  BodySizeType
1254 
1255  /// Initializes instance referring to nothing.
1257  : body_(NULL)
1258  , size_(0)
1259  , version_(0)
1260  {
1261  }
1262 
1263  /// Initializes instance from memory
1264  /// block of given SBE-encoded message.
1266  const void* body,
1267  BodySize size,
1268  SchemaVersion version)
1269  : body_(body)
1270  , size_(size)
1271  , version_(version)
1272  {
1273  assert(NULL != body);
1274 
1275  assert(
1276  version >=
1277  SchemaTraits::
1278  minimalVersion());
1279  }
1280 
1281  /// Initializes instance as a copy of the other one.
1283  const BinaryGroupEntry& other)
1284  : body_(
1285  other.body_)
1286  , size_(
1287  other.size_)
1288  , version_(
1289  other.version_)
1290  {
1291  }
1292 
1293  /// Indicates whether instance refers to a valid content.
1294  operator bool() const
1295  {
1296  return (NULL != body_);
1297  }
1298 
1299  /// Indicates beginning of group entry body.
1300  const void* body() const
1301  {
1302  return body_;
1303  }
1304 
1305  /// Indicates end of group entry body.
1307  {
1308  return size_;
1309  }
1310 
1311  /// Version of message containing
1312  /// given repeating group instance.
1314  {
1315  return version_;
1316  }
1317 
1318  /// Re-initializes instance as a copy of the other one.
1320  operator =(
1321  const BinaryGroupEntry& other)
1322  {
1323  body_ = other.body_;
1324  size_ = other.size_;
1325 
1326  version_ = other.version_;
1327 
1328  return *this;
1329  }
1330 };
1331 
1332 
1333 /// Raises exception on bad message version.
1334 ONIXS_CMESTREAMLINEDMDH_EXPORTED
1335 void
1337  SchemaVersion messageVersion);
1338 
1339 /// Aliases message type (template) identification.
1340 typedef
1343 
1344 /// Encapsulates services for manipulating SBE-encoded messages.
1347 : public BinaryFields
1348 <
1349  BinaryMessage,
1350  MessageSize
1351 >
1352 {
1353  const MessageHeader* header_;
1354  MessageSize size_;
1355 
1356 protected:
1357  /// Binary group list instantiation.
1358  typedef
1361 
1362  /// Returns list of repeating groups
1363  /// of a message being referenced.
1365  {
1366  assert(NULL != header_);
1367 
1368  const void*
1369  const list =
1371  body(), bodySize());
1372 
1373  const
1374  MessageSize
1375  listSize =
1376  size_ -
1377  MessageHeader::Size -
1378  header_->blockLength();
1379 
1380  return
1381  GroupList(
1382  list,
1383  listSize,
1384  header_->version());
1385  }
1386 
1387 public:
1388  /// Length of message binary data.
1390 
1391  /// Length of message body without repeating groups.
1392  typedef
1395 
1396  /// Initializes blank instance referencing to nothing.
1398  : header_(NULL)
1399  , size_(0)
1400  {
1401  }
1402 
1403  /// Initializes instance over given memory block.
1405  const void* data,
1406  MessageSize size)
1407  : header_(
1408  static_cast
1409  <const MessageHeader*>
1410  (data))
1411  , size_(size)
1412  {
1413  assert(NULL != data);
1414 
1415  if (size <
1416  MessageHeader::Size
1417  ||
1418  size <
1419  (MessageHeader::Size +
1420  header_->blockLength()))
1421  {
1423  }
1424 
1425  const
1426  SchemaVersion
1427  version = this->version();
1428 
1429  if (version <
1430  SchemaTraits::minimalVersion())
1431  {
1432  throwBadMessageVersion(version);
1433  }
1434  }
1435 
1436  /// Initializes instance as copy of the other one.
1438  const BinaryMessage& other)
1439  : header_(other.header_)
1440  , size_(other.size_)
1441  {
1442  }
1443 
1444  /// Indicates whether instance refers to a valid message.
1445  operator bool() const
1446  {
1447  return (NULL != header_);
1448  }
1449 
1450  /// Template identifier of message being referenced.
1452  {
1453  assert(NULL != header_);
1454 
1455  return header_->templateId();
1456  }
1457 
1458  /// Version of message being referenced.
1460  {
1461  assert(NULL != header_);
1462 
1463  return header_->version();
1464  }
1465 
1466  /// SBE-encoded message content.
1467  const void* binary() const
1468  {
1469  return header_;
1470  }
1471 
1472  /// Size of SBE-encoded message.
1474  {
1475  return size_;
1476  }
1477 
1478  /// Indicates beginning of message body.
1479  const void* body() const
1480  {
1481  assert(NULL != header_);
1482 
1483  return
1485  header_,
1486  MessageHeader::Size);
1487  }
1488 
1489  /// Size of message body in bytes.
1491  {
1492  assert(NULL != header_);
1493 
1494  return header_->blockLength();
1495  }
1496 
1497  /// Re-initializes instance as a copy of the other one.
1498  BinaryMessage&
1499  operator =(
1500  const BinaryMessage& other)
1501  {
1502  header_ = other.header_;
1503  size_ = other.size_;
1504 
1505  return *this;
1506  }
1507 };
1508 
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:253
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:239
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:326
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
ONIXS_CMESTREAMLINEDMDH_EXPORTED bool operator>(const Decimal &l, const Decimal &r)
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:319
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)
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.
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:344
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:338
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:356
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
ONIXS_CMESTREAMLINEDMDH_EXPORTED bool operator<(const Decimal &l, const Decimal &r)
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