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