OnixS C++ CME MDP Premium Market Data Handler  5.8.3
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 <class Container, class BlockLength>
43 {
44 protected:
45  /// Initializes the blank instance.
47 
48  /// Ends life of the instance.
50 
51  /// Returns value of a field by its offset.
52  template <class Value>
53  Value ordinary(BlockLength offset) const
54  {
55  const size_t sizeOfValue = sizeof(Value);
56 
57  assert((offset + sizeOfValue) <= container().blockLength());
58 
59  const void* const location = advanceByBytes(container().block(), offset);
60 
61  Value result;
62 
63  memcpy(&result, location, sizeOfValue);
64 
65  return result;
66  }
67 
68  /// Provides access to a value of
69  /// an optional field by its offset.
70  ///
71  /// Returned result indicates whether field is
72  /// present in given field block and its value
73  /// was copied into a given parameter-variable.
74  template <class Value, class NullValue>
75  bool ordinary(Value& value, BlockLength offset, const NullValue& null) const
76  {
77  const Value optional = ordinary<Value>(offset);
78 
79  if (null != optional)
80  {
81  value = optional;
82 
83  return true;
84  }
85 
86  return false;
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  ///
96  /// Field may not be present in earlier versions
97  /// of binary message and thus its value may not be
98  /// available. For this reason, parameter indicating
99  /// version of data assumed is required to access
100  /// the field.
101  template <class Value, class NullValue>
102  bool ordinary(Value& value, BlockLength offset, const NullValue& null, SchemaVersion since) const
103  {
104  return (since <= container().version() && ordinary(value, offset, null));
105  }
106 
107  /// Returns value of a field by its offset.
108  ///
109  /// Given function serves as specialization of
110  /// general case for fields of enumeration type.
111  template <class Enumeration>
112  typename Enumeration::Enum enumeration(BlockLength offset) const
113  {
114  typedef typename Enumeration::Base Base;
115 
116  typedef typename Enumeration::Enum Enum;
117 
118  return static_cast<Enum>(ordinary<Base>(offset));
119  }
120 
121  /// Provides access to value of
122  /// an optional field by its offset.
123  ///
124  /// Given function serves as specialization of
125  /// general case for fields of enumeration type.
126  template <class Enumeration, class NullValue>
127  bool enumeration(typename Enumeration::Enum& value, BlockLength offset, const NullValue& null) const
128  {
129  typedef typename Enumeration::Base Base;
130 
131  typedef typename Enumeration::Enum Enum;
132 
133  const Base optional = ordinary<Base>(offset);
134 
135  if (null != optional)
136  {
137  value = static_cast<Enum>(optional);
138 
139  return true;
140  }
141 
142  return false;
143  }
144 
145  /// Provides access to value of
146  /// an optional field by its offset.
147  ///
148  /// Given function serves as specialization of
149  /// general case for fields of enumeration type.
150  template <class Enumeration, class NullValue>
151  bool
152  enumeration(typename Enumeration::Enum& value, BlockLength offset, const NullValue& null, SchemaVersion since) const
153  {
154  return (since <= container().version() && enumeration<Enumeration, NullValue>(value, offset, null));
155  }
156 
157  /// Returns value of a field by its
158  /// offset converted into a decimal.
159  template <class Value>
160  Decimal decimal(BlockLength offset) const
161  {
162  return Decimal(ordinary<Value>(offset));
163  }
164 
165  /// Provides access to a value of
166  /// an optional field by its offset.
167  /// The result is converted into decimal.
168  ///
169  /// Returned result indicates whether field is
170  /// present in given field block and its value
171  /// was copied into a given parameter-variable.
172  template <class NullValue>
173  bool decimal(Decimal& value, BlockLength offset, const NullValue& null) const
174  {
175  typedef typename NullValue::Value Value;
176 
177  const Value optional = ordinary<Value>(offset);
178 
179  if (null != optional)
180  {
181  value = optional;
182 
183  return true;
184  }
185 
186  return false;
187  }
188 
189  /// Provides access to a value of
190  /// an optional field by its offset.
191  /// The result is converted into decimal.
192  ///
193  /// Returned result indicates whether field is
194  /// present in given field block and its value
195  /// was copied into a given parameter-variable.
196  ///
197  /// Field may not be present in earlier versions
198  /// of binary message and thus its value may not be
199  /// available. For this reason, parameter indicating
200  /// version of data assumed is required to access
201  /// the field.
202  template <class NullValue>
203  bool decimal(Decimal& value, BlockLength offset, const NullValue& null, SchemaVersion since) const
204  {
205  return (since <= container().version() && decimal(value, offset, null));
206  }
207 
208  /// Provides access to string field by its offset.
209  ///
210  /// Given function serves as specialization
211  /// of general case for fields of string type.
212  template <BlockLength Length>
213  StrRef fixedStr(BlockLength offset) const
214  {
215  assert((offset + Length) <= container().blockLength());
216 
217  const Char* const text = reinterpret_cast<const Char*>(advanceByBytes(container().block(), offset));
218 
219  return StrRef(text, strnlen(text, Length));
220  }
221 
222  /// Provides access to an optional
223  /// field of string type by its offset.
224  ///
225  /// Given function serves as specialization
226  /// of general case for fields of string type.
227  template <BlockLength Length>
228  StrRef fixedStr(BlockLength offset, SchemaVersion since) const
229  {
230  return (since <= container().version() ? fixedStr<Length>(offset) : StrRef());
231  }
232 
233 private:
234  /// The block container providing
235  /// actual access to the encoded data.
236  const Container& container() const
237  {
238  return *static_cast<const Container*>(this);
239  }
240 
241 };
242 
243 /// Throws exception on bad repeating group entry.
245 void throwBadBinaryData(const Char* className);
246 
247 /// Encapsulates operations over SBE-encoded
248 /// repeating group entry instance.
249 template <class Length>
250 class BinaryGroupEntry : public BinaryBlock<BinaryGroupEntry<Length>, Length>
251 {
252 public:
253  /// Represents the length of binary data
254  /// occupied by the given group entry.
255  typedef Length EncodedLength;
256 
257  /// Represents the length of binary block storing
258  /// fixed-length fields of the group entry.
259  typedef Length BlockLength;
260 
261  /// Initializes instance referring to nothing.
263  : encoded_(ONIXS_CMEMDH_NULLPTR)
264  , length_(0)
265  , version_(0)
266  {
267  }
268 
269  /// Initializes instance from memory
270  /// block of given SBE-encoded message.
271  BinaryGroupEntry(const void* encoded, BlockLength length, SchemaVersion version)
272  : encoded_(encoded)
273  , length_(length)
274  , version_(version)
275  {
276  assert(ONIXS_CMEMDH_NULLPTR != encoded);
277 
278  assert(version >= SchemaTraits::minimalVersion());
279  }
280 
281  /// Initializes instance as a copy of the other one.
283  : encoded_(other.encoded_)
284  , length_(other.length_)
285  , version_(other.version_)
286  {
287  }
288 
289  /// Indicates whether instance refers to a valid content.
290  operator bool() const
291  {
292  return (ONIXS_CMEMDH_NULLPTR != encoded_);
293  }
294 
295  /// Pointer to the binary data
296  /// referring to the given entry.
297  const void* encoded() const
298  {
299  return encoded_;
300  }
301 
302  /// Length of the SBE-encoded data
303  /// referring to the given entry.
304  EncodedLength encodedLength() const
305  {
306  return length_;
307  }
308 
309  /// Returns pointer to the block containing
310  /// fixed-length fields of the given entry.
311  const void* block() const
312  {
313  return encoded_;
314  }
315 
316  /// Returns length of the block containing
317  /// fixed-length fields of the given entry.
318  BlockLength blockLength() const
319  {
320  return length_;
321  }
322 
323  /// Version of message containing
324  /// given repeating group instance.
326  {
327  return version_;
328  }
329 
330  /// Re-initializes instance as a copy of the other one.
332  {
333  encoded_ = other.encoded_;
334  length_ = other.length_;
335 
336  version_ = other.version_;
337 
338  return *this;
339  }
340 
341 private:
342  const void* encoded_;
343  Length length_;
344 
345  SchemaVersion version_;
346 };
347 
348 /// Encapsulates operations over SBE-encoded repeating group entries.
349 template <class EntryType, class BlockLength, class NumInGroup, class Length>
351 {
352 public:
353  /// Represents the length of binary data
354  /// occupied by the given group entries.
355  typedef Length EncodedLength;
356 
357  /// The type of repeating group entry.
358  typedef EntryType Entry;
359 
360  /// Number of entries in the collection.
361  typedef NumInGroup Size;
362 
363  /// Provides iterating facilities
364  /// over SBE-encoded group entries.
365  class Iterator
366  {
367  public:
368  /// Aliases entry for STL conformance.
369  typedef const Entry value_type;
370 
371  /// Aliases pointer to entry for STL conformance.
372  typedef const Entry* pointer;
373 
374  /// Aliases entry reference for STL conformance.
375  typedef const Entry& reference;
376 
377  /// Iterator difference type.
378  typedef ptrdiff_t difference_type;
379 
380  /// Identifies iterator category.
381  typedef std::random_access_iterator_tag iterator_category;
382 
383  /// Initializes instance referring to nothing.
385  : encoded_(ONIXS_CMEMDH_NULLPTR)
386  , length_(0)
387  , version_(0)
388  {
389  }
390 
391  /// Initializes instance for given repeating group.
392  Iterator(const void* block, BlockLength length, SchemaVersion version)
393  : encoded_(block)
394  , length_(length)
395  , version_(version)
396  {
397  }
398 
399  /// Initializes instance as copy of the other one.
400  Iterator(const Iterator& other)
401  : encoded_(other.encoded_)
402  , length_(other.length_)
403  , version_(other.version_)
404  {
405  }
406 
407  /// Repeating group entry referenced by the instance.
408  const Entry get() const
409  {
410  assert(ONIXS_CMEMDH_NULLPTR != encoded_);
411 
412  return Entry(encoded_, length_, version_);
413  }
414 
415  /// Repeating group block referenced by the iterator.
416  const Entry operator*() const
417  {
418  return get();
419  }
420 
421  /// Compares the given iterator with the other instance.
422  bool operator==(const Iterator& other) const
423  {
424  return encoded_ == other.encoded_;
425  }
426 
427  /// Compares the given iterator with the other instance.
428  bool operator!=(const Iterator& other) const
429  {
430  return encoded_ != other.encoded_;
431  }
432 
433  /// Established order between two iterators.
434  bool operator<(const Iterator& other) const
435  {
436  return encoded_ < other.encoded_;
437  }
438 
439  /// Established order between two iterators.
440  bool operator>(const Iterator& other) const
441  {
442  return encoded_ > other.encoded_;
443  }
444 
445  /// Advances instance to the next repeating group entry.
447  {
448  encoded_ = advanceByBytes(encoded_, length_);
449 
450  return *this;
451  }
452 
453  /// Advances instance to the next repeating group entry.
455  {
456  encoded_ = advanceBackByBytes(encoded_, length_);
457 
458  return *this;
459  }
460 
461  /// Advances instance by given number of entries.
462  Iterator operator+(difference_type distance) const
463  {
464  return Iterator(
465  advanceByBytes(encoded_, distance * static_cast<difference_type>(length_)), length_, version_
466  );
467  }
468 
469  /// Advances instance by given number of entries.
470  Iterator operator-(difference_type distance) const
471  {
472  return Iterator(
473  advanceBackByBytes(encoded_, distance * static_cast<difference_type>(length_)), length_, version_
474  );
475  }
476 
477  /// Re-initializes instance as copy of the other one.
478  Iterator& operator=(const Iterator& other)
479  {
480  encoded_ = other.encoded_;
481  length_ = other.length_;
482  version_ = other.version_;
483 
484  return *this;
485  }
486 
487  private:
488  const void* encoded_;
489  BlockLength length_;
490 
491  SchemaVersion version_;
492  };
493 
494  /// Initializes blank instance referencing to nothing.
496  : encoded_(ONIXS_CMEMDH_NULLPTR)
497  , blockLength_(0)
498  , size_(0)
499  , version_(0)
500  {
501  }
502 
503  /// Initializes the instance referencing to a real data.
504  BinaryGroupEntries(const void* encoded, BlockLength blockLength, Size groupSize, SchemaVersion version)
505  : encoded_(encoded)
506  , blockLength_(blockLength)
507  , size_(groupSize)
508  , version_(version)
509  {
510  }
511 
512  /// Initializes instance as a copy of the other one.
513  template <class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength>
515  : encoded_(other.encoded_)
516  , blockLength_(other.blockLength_)
517  , size_(other.size_)
518  , version_(other.version_)
519  {
520  // Dimension types may vary for the different
521  // instantiations of the template. Therefore,
522  // truncation of the dimensions must be avoided.
523 
524  assert(blockLength_ == other.blockLength_);
525 
526  assert(size_ == other.size_);
527  }
528 
529  /// Indicates whether given instance
530  /// refers to a valid repeating group.
531  operator bool() const
532  {
533  return (ONIXS_CMEMDH_NULLPTR != encoded_);
534  }
535 
536  /// Indicates whether a repeating
537  /// group being referenced is empty.
538  bool empty() const
539  {
540  return (0 == size_);
541  }
542 
543  /// Returns number of blocks.
544  Size size() const
545  {
546  return size_;
547  }
548 
549  /// Returns iterator pointing to the first repeating group entry.
550  Iterator begin() const
551  {
552  return Iterator(encoded_, blockLength_, version_);
553  }
554 
555  /// Returns iterator pointing to the entry behind the end of the group.
556  Iterator end() const
557  {
558  return Iterator(
559  advanceByBytes(encoded_, static_cast<ptrdiff_t>(blockLength_) * static_cast<ptrdiff_t>(size_)),
560  blockLength_,
561  version_
562  );
563  }
564 
565  /// Provides access to the group
566  /// entry by its index in the group.
567  ///
568  /// Index validness is not checked
569  /// due to performance considerations.
570  const Entry operator[](Size index) const
571  {
572  assert(index < size_);
573 
574  return Entry(
575  advanceByBytes(encoded_, static_cast<ptrdiff_t>(blockLength_) * static_cast<ptrdiff_t>(index)),
576  blockLength_,
577  version_
578  );
579  }
580 
581  /// Binary data occupied by the given group entries.
582  const void* encoded() const
583  {
584  return encoded_;
585  }
586 
587  /// Length of the binary data occupied
588  /// by the given collection of entries.
589  EncodedLength encodedLength() const
590  {
591  return (static_cast<EncodedLength>(blockLength_) * static_cast<EncodedLength>(size_));
592  }
593 
594  /// Re-initializes instance as copy of the other one.
595  /// Initializes instance as a copy of the other one.
596  template <class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength>
599  {
600  encoded_ = other.encoded_;
601 
602  blockLength_ = other.blockLength_;
603 
604  assert(blockLength_ == other.blockLength_);
605 
606  size_ = other.size_;
607 
608  assert(size_ == other.size_);
609 
610  version_ = other.version_;
611 
612  return *this;
613  }
614 
615 private:
616  // Allows coping and cloning
617  // for different instantiations.
618  template <class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength>
619  friend class BinaryGroupEntries;
620 
621  // Actual parameters.
622 
623  const void* encoded_;
624 
625  BlockLength blockLength_;
626  NumInGroup size_;
627 
628  SchemaVersion version_;
629 };
630 
631 /// Throws exception on bad repeating group.
633 void throwBadBinaryGroup();
634 
635 /// Encapsulates operations over SBE-encoded repeating group.
636 template <class EntryType, class DimensionType, class LengthType>
638 {
639 public:
640  /// Binary group dimensions (actual
641  /// length, number of entries, etc).
642  typedef DimensionType Dimension;
643 
644  /// Binary group blocks.
647 
648  /// Defines type of iterator for group entries.
649  typedef typename Entries::Iterator Iterator;
650 
651  /// Aliases type of the group entry.
652  typedef typename Entries::Entry Entry;
653 
654  /// Type representing a number of entries in the group.
655  typedef typename Entries::Size Size;
656 
657  /// Measures binary length of the group.
658  typedef LengthType EncodedLength;
659 
660  /// Initializes blank instance referencing to nothing.
662  : header_(ONIXS_CMEMDH_NULLPTR)
663  {
664  }
665 
666  /// Initializes instance referencing
667  /// to a valid group of a given message.
668  BinaryGroup(const void* encoded, EncodedLength length, SchemaVersion version)
669  : header_(static_cast<const Dimension*>(encoded))
670  {
671  if (length < Dimension::Size)
672  {
674  }
675  else
676  {
677  entries_ = Entries(
678  advanceByBytes(header_, Dimension::Size), header_->blockLength(), header_->numInGroup(), version
679  );
680 
681  if (length < encodedLength())
682  {
684  }
685  }
686  }
687 
688  /// Initializes instance as a copy of the other one.
689  BinaryGroup(const BinaryGroup& other)
690  : header_(other.header_)
691  , entries_(other.entries_)
692  {
693  }
694 
695  /// Indicates whether given instance
696  /// refers to a valid repeating group.
697  operator bool() const
698  {
699  return (ONIXS_CMEMDH_NULLPTR != header_);
700  }
701 
702  /// Indicates whether a repeating
703  /// group being referenced is empty.
704  bool empty() const
705  {
706  return (0 == size());
707  }
708 
709  /// Returns number of entries in a
710  /// repeating group being referenced.
711  Size size() const
712  {
713  return entries_.size();
714  }
715 
716  /// Returns iterator pointing to
717  /// the first repeating group entry.
718  Iterator begin() const
719  {
720  return entries_.begin();
721  }
722 
723  /// Returns iterator pointing to the
724  /// entry behind the end of the group.
725  Iterator end() const
726  {
727  return entries_.end();
728  }
729 
730  /// Provides access to the repeating
731  /// group entry by its index in the group.
732  ///
733  /// Index validness is not checked due
734  /// to performance considerations.
735  Entry operator[](Size index) const
736  {
737  return entries_[index];
738  }
739 
740  /// Location of repeating group entries.
741  const Entries& entries() const
742  {
743  return entries_;
744  }
745 
746  /// SBE-encoded data representing
747  /// the given repeating group.
748  const void* encoded() const
749  {
750  return header_;
751  }
752 
753  /// Length of the SBE-encoded data
754  /// representing the given group.
755  EncodedLength encodedLength() const
756  {
757  return (Dimension::Size + entries_.encodedLength());
758  }
759 
760  /// Re-initializes instance as copy of the other one.
762  {
763  header_ = other.header_;
764  entries_ = other.entries_;
765 
766  return *this;
767  }
768 
769 private:
770  const Dimension* header_;
771  Entries entries_;
772 };
773 
774 /// Encapsulates services for manipulating SBE-encoded
775 /// groups stored sequentially in SBE-encoded message.
776 template <class Length>
778 {
779 public:
780  /// Represents the length of binary data
781  /// occupied by the given list of groups.
782  typedef Length EncodedLength;
783 
784  /// Initializes empty list.
786  : encoded_(ONIXS_CMEMDH_NULLPTR)
787  , length_(0)
788  , version_(0)
789  {
790  }
791 
792  /// Initializes list over memory block,
793  /// where given message is stored.
794  BinaryGroups(const void* encoded, EncodedLength length, SchemaVersion version)
795  : encoded_(encoded)
796  , length_(length)
797  , version_(version)
798  {
799  }
800 
801  /// Initializes as copy of other list.
803  : encoded_(other.encoded_)
804  , length_(other.length_)
805  , version_(other.version_)
806  {
807  }
808 
809  /// Indicates whether group list is empty.
810  bool empty() const
811  {
812  return (0 == length_);
813  }
814 
815  /// Provides access to the head group of the list.
816  template <class Group>
817  Group head() const
818  {
819  return Group(encoded_, length_, version_);
820  }
821 
822  /// Returns the groups following the head.
823  template <class Group>
825  {
826  const EncodedLength headLength = head<Group>().encodedLength();
827 
828  assert(length_ >= headLength);
829 
830  return BinaryGroups(advanceByBytes(encoded_, headLength), length_ - headLength, version_);
831  }
832 
833  /// SBE-encoded content referenced by the list.
834  const void* encoded() const
835  {
836  return encoded_;
837  }
838 
839  /// Length of SBE-encoded content
840  /// referenced by the given group list.
841  EncodedLength encodedLength() const
842  {
843  return length_;
844  }
845 
846  /// Re-initializes instance as copy of the other one.
848  {
849  encoded_ = other.encoded_;
850  length_ = other.length_;
851 
852  version_ = other.version_;
853 
854  return *this;
855  }
856 
857 private:
858  const void* encoded_;
859 
860  Length length_;
861 
862  SchemaVersion version_;
863 };
864 
865 /// Raises exception on bad binary message.
867 {
868  throw std::runtime_error("Cannot construct message instance. Memory "
869  "block is too small to access SBE message header. ");
870 }
871 
872 /// Raises exception on bad message version.
875 
876 /// Aliases message type (template) identification.
878 
879 /// Aliases message length type.
881 
882 /// Encapsulates services for manipulating SBE-encoded messages.
883 class ONIXS_CMEMDH_LTWT BinaryMessage : public BinaryBlock<BinaryMessage, MessageSize>
884 {
885 public:
886  /// Length of message binary data.
888 
889  /// Length of message body representing
890  /// a block of fixed-length fields.
892 
893  /// Repeating groups.
895 
896  /// Initializes the instance referencing to nothing.
898  : header_(ONIXS_CMEMDH_NULLPTR)
899  , length_(0)
900  {
901  }
902 
903  /// Initializes instance over the given encoded data.
904  BinaryMessage(const void* encoded, EncodedLength length)
905  : header_(static_cast<const MessageHeader*>(encoded))
906  , length_(length)
907  {
908  assert(ONIXS_CMEMDH_NULLPTR != encoded);
909 
910  if (length < MessageHeader::Size || length < (MessageHeader::Size + header_->blockLength()))
911  {
913  }
914  }
915 
916  /// Initializes instance as copy of the other one.
918  : header_(other.header_)
919  , length_(other.length_)
920  {
921  }
922 
923  /// Indicates whether instance refers to a valid message.
924  operator bool() const
925  {
926  return (ONIXS_CMEMDH_NULLPTR != header_);
927  }
928 
929  /// Template identifier of message being referenced.
931  {
932  assert(ONIXS_CMEMDH_NULLPTR != header_);
933 
934  return header_->templateId();
935  }
936 
937  /// Version of message being referenced.
939  {
940  assert(ONIXS_CMEMDH_NULLPTR != header_);
941 
942  return header_->version();
943  }
944 
945  /// SBE-encoded message content.
946  const void* encoded() const
947  {
948  return header_;
949  }
950 
951  /// Size of SBE-encoded message.
952  EncodedLength encodedLength() const
953  {
954  return length_;
955  }
956 
957  /// Indicates beginning of message body.
958  const void* block() const
959  {
960  assert(ONIXS_CMEMDH_NULLPTR != header_);
961 
962  return advanceByBytes(header_, MessageHeader::Size);
963  }
964 
965  /// Length of the message body (
966  /// block of fixed-length fields).
967  BlockLength blockLength() const
968  {
969  assert(ONIXS_CMEMDH_NULLPTR != header_);
970 
971  return header_->blockLength();
972  }
973 
974  /// Collection of repeating groups
975  /// of the message being referenced.
976  Groups groups() const
977  {
978  assert(ONIXS_CMEMDH_NULLPTR != header_);
979 
980  return Groups(
981  advanceByBytes(block(), blockLength()),
982  length_ - MessageHeader::Size - header_->blockLength(),
983  header_->version()
984  );
985  }
986 
987  /// Re-initializes instance as a copy of the other one.
989  {
990  header_ = other.header_;
991  length_ = other.length_;
992 
993  return *this;
994  }
995 
996 private:
998 
999  const MessageHeader* header_;
1000  MessageSize length_;
1001 };
1002 
Iterator()
Initializes instance referring to nothing.
BinaryGroups(const BinaryGroups &other)
Initializes as copy of other list.
bool operator>(const Iterator &other) const
Established order between two iterators.
~BinaryBlock()
Ends life of the instance.
Definition: BinaryMessage.h:49
Iterator end() const
Returns iterator pointing to the entry behind the end of the group.
ptrdiff_t difference_type
Iterator difference type.
StrRef fixedStr(BlockLength offset) const
Provides access to string field by its offset.
bool empty() const
Indicates whether group list is empty.
BlockLength blockLength() const
Length of the message body ( block of fixed-length fields).
Encapsulates services for manipulating SBE-encoded groups stored sequentially in SBE-encoded message...
BinaryMessage & operator=(const BinaryMessage &other)
Re-initializes instance as a copy of the other one.
BinaryGroupEntries & operator=(const BinaryGroupEntries< OtherEntry, OtherBlockLength, OtherNumInGroup, OtherLength > &other)
Re-initializes instance as copy of the other one.
const Entry * pointer
Aliases pointer to entry for STL conformance.
Provides iterating facilities over SBE-encoded group entries.
Iterator end() const
Returns iterator pointing to the entry behind the end of the group.
EncodedLength encodedLength() const
Length of SBE-encoded content referenced by the given group list.
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.
BinaryGroupEntries< EntryType, typename Dimension::BlockLength, typename Dimension::NumInGroup, LengthType > Entries
Binary group blocks.
#define ONIXS_CMEMDH_NULLPTR
Definition: Compiler.h:145
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, const NullValue &null) const
Provides access to value of an optional field by its offset.
Decimal decimal(BlockLength offset) const
Returns value of a field by its offset converted into a decimal.
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:53
Iterator & operator--()
Advances instance to the next repeating group entry.
Iterator(const Iterator &other)
Initializes instance as copy of the other one.
BinaryGroup & operator=(const BinaryGroup &other)
Re-initializes instance as copy of the other one.
BinaryMessage()
Initializes the instance referencing to nothing.
MessageSize BlockLength
Length of message body representing a block of fixed-length fields.
Length EncodedLength
Represents the length of binary data occupied by the given group entry.
BinaryGroupEntry()
Initializes instance referring to nothing.
BinaryGroups< MessageSize > Groups
Repeating groups.
const Entry & reference
Aliases entry reference for STL conformance.
bool operator!=(const Iterator &other) const
Compares the given iterator with the other instance.
EncodedLength encodedLength() const
Length of the SBE-encoded data referring to the given entry.
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)
Initializes instance referencing to a valid group of a given message.
#define ONIXS_CMEMDH_LTWT
Definition: Bootstrap.h:46
bool decimal(Decimal &value, BlockLength offset, const NullValue &null) const
Provides access to a value of an optional field by its offset.
Enumeration::Enum enumeration(BlockLength offset) const
Returns value of a field by its offset.
bool ordinary(Value &value, BlockLength offset, const NullValue &null, SchemaVersion since) const
Provides access to a value of an optional field by its offset.
BinaryGroupEntries()
Initializes blank instance referencing to nothing.
bool operator<(const Iterator &other) const
Established order between two iterators.
const void * encoded() const
Pointer to the binary data referring to the given entry.
BinaryGroupEntry(const BinaryGroupEntry &other)
Initializes instance as a copy of the other one.
BinaryGroupEntry(const void *encoded, BlockLength length, SchemaVersion version)
Initializes instance from memory block of given SBE-encoded message.
std::random_access_iterator_tag iterator_category
Identifies iterator category.
Encapsulates operations over SBE-encoded repeating group entry instance.
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)
Finds a tag-value entry in the given collection by the given tag and returns its value component tran...
SchemaVersion version() const
Version of message containing given repeating group instance.
const void * encoded() const
SBE-encoded data representing the given repeating group.
const void * block() const
Returns pointer to the block containing fixed-length fields of the given entry.
Iterator & operator=(const Iterator &other)
Re-initializes instance as copy of the other one.
EntryType Entry
The type of repeating group entry.
Exposes base services to access fields stored in a SBE-encoded block of fixed-length fields...
Definition: BinaryMessage.h:42
BinaryGroups tail() const
Returns the groups following the head.
Iterator operator-(difference_type distance) const
Advances instance by given number of entries.
Iterator(const void *block, BlockLength length, SchemaVersion version)
Initializes instance for given repeating group.
void throwBadMessageVersion(const Char *, SchemaVersion, SchemaVersion)
Raises exception on bad message version.
MessageTemplateId templateId() const
Template identifier of message being referenced.
void throwBadBinaryGroup()
Throws exception on bad repeating group.
Provides efficient way of accessing text-based values without copying content of the text being refer...
Definition: String.h:41
Iterator & operator++()
Advances instance to the next repeating group entry.
MessageHeader::Version SchemaVersion
Aliases SBE-encoded data version type.
Definition: SchemaTraits.h:28
StrRef fixedStr(BlockLength offset, SchemaVersion since) const
Provides access to an optional field of string type by its offset.
EncodedLength encodedLength() const
Length of the binary data occupied by the given collection of entries.
A real number with floating exponent.
Definition: Decimal.h:136
Entries::Iterator Iterator
Defines type of iterator for group entries.
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:67
BinaryGroupEntry & operator=(const BinaryGroupEntry &other)
Re-initializes instance as a copy of the other one.
UInt16 TemplateId
templateId type.
Definition: Composites.h:380
BinaryGroup()
Initializes blank instance referencing to nothing.
BlockLength blockLength() const
Returns length of the block containing fixed-length fields of the given entry.
Type * advanceByBytes(Type *pointer, ptrdiff_t distance)
Advances given pointer to a given offset (distance) in bytes.
Definition: Memory.h:75
Length EncodedLength
Represents the length of binary data occupied by the given group entries.
Groups groups() const
Collection of repeating groups of the message being referenced.
Encapsulates services for manipulating SBE-encoded messages.
#define ONIXS_CMEMDH_EXPORTED
Definition: Compiler.h:135
const Entry operator[](Size index) const
Provides access to the group entry by its index in the group.
Length EncodedLength
Represents the length of binary data occupied by the given list of groups.
const Entry operator*() const
Repeating group block referenced by the iterator.
EncodedLength encodedLength() const
Size of SBE-encoded message.
Length BlockLength
Represents the length of binary block storing fixed-length fields of the group entry.
Encapsulates operations over SBE-encoded repeating group.
Template ID and length of message root.
Definition: Composites.h:367
void throwBadBinaryData(const Char *className)
Throws exception on bad repeating group entry.
const Entries & entries() const
Location of repeating group entries.
EncodedLength encodedLength() const
Length of the SBE-encoded data representing the given group.
DimensionType Dimension
Binary group dimensions (actual length, number of entries, etc).
Iterator begin() const
Returns iterator pointing to the first repeating group entry.
Entry operator[](Size index) const
Provides access to the repeating group entry by its index in the group.
UInt16 UInt16
uInt16 optional.
Definition: Fields.h:189
Type * advanceBackByBytes(Type *pointer, ptrdiff_t distance)
Returns pointer which is lower than given one to a given number of bytes.
Definition: Memory.h:83
BinaryGroups & operator=(const BinaryGroups &other)
Re-initializes instance as copy of the other one.
bool empty() const
Indicates whether a repeating group being referenced is empty.
BinaryGroups(const void *encoded, EncodedLength length, SchemaVersion version)
Initializes list over memory block, where given message is stored.
Iterator begin() const
Returns iterator pointing to the first repeating group entry.
MDEntryType type.
Definition: Fields.h:294
const void * block() const
Indicates beginning of message body.
LengthType EncodedLength
Measures binary length of the group.
Iterator operator+(difference_type distance) const
Advances instance by given number of entries.
Size size() const
Returns number of entries in a repeating group being referenced.
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, const NullValue &null, SchemaVersion since) const
Provides access to value of an optional field by its offset.
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
Provides access to a value of an optional field by its offset.
Definition: BinaryMessage.h:75
MessageHeader::TemplateId MessageTemplateId
Aliases message type (template) identification.
bool empty() const
Indicates whether a repeating group being referenced is empty.
BinaryBlock()
Initializes the blank instance.
Definition: BinaryMessage.h:46
Size size() const
Returns number of blocks.
bool operator==(const Iterator &other) const
Compares the given iterator with the other instance.
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
Provides access to a value of an optional field by its offset.
void throwBadBinaryMessage()
Raises exception on bad binary message.
const Entry value_type
Aliases entry for STL conformance.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:68