OnixS C++ B3 BOE Binary Order Entry  1.2.0
API Documentation
SbeMessage.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 <OnixS/B3/BOE/ABI.h>
31 
32 #include <cassert>
33 #include <limits>
34 #include <stdexcept>
35 
37 
38 /// Message type (template) identification.
39 typedef
40 MessageHeader::TemplateId MessageTemplateId;
41 
42 /// \private
43 template<typename Message> inline
44 void checkBinaryLength(const Message&, MessageSize length, MessageSize minimalRequiredLength)
45 {
46  if ONIXS_B3_BOE_UNLIKELY(length < minimalRequiredLength)
47  throwBinaryBlockIsTooSmall(length, minimalRequiredLength, Message::className());
48 }
49 
50 /// \private
51 ONIXS_B3_BOE_LTWT_CLASS BinaryBlockBase
52 {
53 protected:
54  ~BinaryBlockBase() ONIXS_B3_BOE_DEFAULT;
55 };
56 
57 /// Services to access fields stored
58 /// in an SBE-encoded block of fixed-length fields.
59 ///
60 /// The given class represents an abstraction to be used
61 /// by descendants as a base class with static polymorphism.
62 template < class Container, class BlockLength >
63 ONIXS_B3_BOE_LTWT_CLASS BinaryBlock : public BinaryBlockBase
64 {
65  /// \return The block container that provides access to the encoded data.
66  const Container& container() const ONIXS_B3_BOE_NOTHROW
67  {
68  return *static_cast <const Container*> (this);
69  }
70 
71 protected:
72  /// Initializes a blank instance.
74 
76 
77  /// \return the field value.
78  template < class Value > ONIXS_B3_BOE_HOTPATH
79  Value ordinary(BlockLength offset) const ONIXS_B3_BOE_NOTHROW
80  {
81  assert(container().blockLength() >= (offset + size<Value>()) &&
82  "The requested field exceeds provided block boundaries.");
83 
84  const void* const location = advanceByBytes(container().block(), offset);
85  return getValue<Value>(location);
86  }
87 
88  /// \return constant reference to the field value.
89  template < class Value > ONIXS_B3_BOE_HOTPATH
90  const Value& accessOrdinary(BlockLength offset) const ONIXS_B3_BOE_NOTHROW
91  {
92  assert(container().blockLength() >= (offset + size<Value>()) &&
93  "The requested field exceeds provided block boundaries.");
94 
95  const void* location = advanceByBytes(container().block(), offset);
96  const Value* valuePtr = static_cast<const Value*>(location);
97  return *valuePtr;
98  }
99 
100  /// \return reference to the field value.
101  template < class Value > ONIXS_B3_BOE_HOTPATH
102  Value& accessOrdinary(BlockLength offset) ONIXS_B3_BOE_NOTHROW
103  {
104  return const_cast<Value&>(static_cast<const BinaryBlock<Container, BlockLength> &>(*this).accessOrdinary<Value>(offset));
105  }
106 
107  /// Provides access to an optional field value.
108  ///
109  /// \return `true` if the field is present in the field block and its value was copied,
110  /// otherwise - `false`.
111  template <class Value, class NullValue > ONIXS_B3_BOE_HOTPATH
112  bool ordinary(Value& value, BlockLength offset, NullValue null) const ONIXS_B3_BOE_NOTHROW
113  {
114  value = ordinary<Value>(offset);
115 
116  return (null != value);
117  }
118 
119  /// Provides access to an optional field value.
120  ///
121  /// \return `true` if the field is present in the field block and its value was copied,
122  /// otherwise - `false`.
123  template < class Value, class NullValue > ONIXS_B3_BOE_HOTPATH
124  bool ordinary(Value& value, BlockLength offset, NullValue null, SchemaVersion since) const ONIXS_B3_BOE_NOTHROW
125  {
126  return (since <= container().version() && ordinary (value, offset, null ) );
127  }
128 
129  /// \return the field value.
130  template < class Enumeration > ONIXS_B3_BOE_HOTPATH
131  typename Enumeration::Enum enumeration(BlockLength offset) const ONIXS_B3_BOE_NOTHROW
132  {
133  typedef typename Enumeration::Base Base;
134  typedef typename Enumeration::Enum Enum;
135 
136  return static_cast<Enum>(ordinary<Base>(offset));
137  }
138 
139  /// Provides access to an optional field value.
140  template < class Enumeration, class NullValue > ONIXS_B3_BOE_HOTPATH
141  bool enumeration(typename Enumeration::Enum& value, BlockLength offset, NullValue null) const ONIXS_B3_BOE_NOTHROW
142  {
143  typedef typename Enumeration::Base Base;
144  typedef typename Enumeration::Enum Enum;
145 
146  value = static_cast <Enum>(ordinary<Base>(offset));
147  return null != value;
148  }
149 
150  /// Provides access to an optional field value.
151  template < class Enumeration, class NullValue > ONIXS_B3_BOE_HOTPATH
152  bool enumeration(typename Enumeration::Enum& value, BlockLength offset, NullValue null, SchemaVersion since) const ONIXS_B3_BOE_NOTHROW
153  {
154  return (since <= container().version() && enumeration<Enumeration>(value, offset, null) );
155  }
156 
157  /// \return a Decimal field value.
158  template < class Value > ONIXS_B3_BOE_HOTPATH
159  Value decimal(BlockLength offset) const ONIXS_B3_BOE_NOTHROW
160  {
161  return ordinary<Value>(offset);
162  }
163 
164  /// \return an optional Decimal field value.
165  ///
166  /// \return `true` if the field is present in the field block and its value was copied,
167  /// otherwise - `false`.
168  template < class Value, class NullValue > ONIXS_B3_BOE_HOTPATH
169  bool decimal(Value& value, BlockLength offset, NullValue null) const ONIXS_B3_BOE_NOTHROW
170  {
171  value = ordinary<Value>(offset);
172  return null != value;
173  }
174 
175  /// \return an optional Decimal field value.
176  ///
177  /// \return `true` if the field is present in the field block and its value was copied,
178  /// otherwise - `false`.
179  template < class Value, class NullValue > ONIXS_B3_BOE_HOTPATH
180  bool decimal(Value& value, BlockLength offset, NullValue null, SchemaVersion since) const ONIXS_B3_BOE_NOTHROW
181  {
182  return (since <= container().version() && decimal(value, offset, null));
183  }
184 
185  /// Provides access to a string field value.
186  template < BlockLength Length > ONIXS_B3_BOE_HOTPATH
187  StrRef fixedStr(BlockLength offset) const ONIXS_B3_BOE_NOTHROW
188  {
189  assert(container().blockLength() >= (offset + Length) && "The requested field exceeds provided block boundaries.");
190 
191  const Char* const text = reinterpret_cast <const Char*> (advanceByBytes(container().block(), offset));
192 
193  return StrRef(text, strnlen(text, Length));
194  }
195 
196  /// Provides access to an optional string field value.
197  ///
198  /// \return `true` if the field is present in the field block and its value was copied,
199  /// otherwise - `false`.
200  template<BlockLength Length> ONIXS_B3_BOE_HOTPATH
201  bool fixedStr(StrRef& value, BlockLength offset) const ONIXS_B3_BOE_NOTHROW
202  {
203  value = fixedStr<Length>(offset);
204  return !value.empty();
205  }
206 
207  /// Provides access to an optional string field value.
208  ///
209  /// \return `true` if the field is present in the field block and its value was copied,
210  /// otherwise - `false`.
211  template<BlockLength Length> ONIXS_B3_BOE_HOTPATH
212  bool fixedStr(StrRef& value, BlockLength offset, SchemaVersion since) const ONIXS_B3_BOE_NOTHROW
213  {
214  return (since <= container().version() && fixedStr<Length>(value, offset));
215  }
216 };
217 
218 /// Base services to access fields stored in an SBE-encoded block of memory.
219 ///
220 /// This class represents an abstraction to be used
221 /// by descendants as a base class with static polymorphism.
222 template <class Container, class BlockLength >
224 {
225 public:
226  /// \return The block container that provides access to the encoded data.
228  {
229  return *static_cast<Container*>(this);
230  }
231 
232  /// If specified, the extra space is padded at the end of each entry and should be set to zeroes by encoders.
234  void zeroPaddingBytes(BlockLength offset) ONIXS_B3_BOE_NOTHROW
235  {
236  const BlockLength encodedBlockLength = container().blockLength();
237 
238  assert(encodedBlockLength >= offset);
239 
240  const size_t paddingLength = encodedBlockLength - offset;
241  std::memset(advanceByBytes(container().block(), offset), 0, paddingLength);
242  }
243 
244  /// Sets the field value.
245  template<class FieldValue> ONIXS_B3_BOE_HOTPATH
246  void setOrdinary(BlockLength offset, FieldValue value) ONIXS_B3_BOE_NOTHROW
247  {
248  assert(container().blockLength() >= (offset + size<FieldValue>()) && "The requested field exceeds provided block boundaries.");
249 
250  void* const fieldPos = advanceByBytes(container().block(), offset);
251  setValue(fieldPos, value);
252  }
253 
254  /// Sets the field value.
255  template<class FieldValue> ONIXS_B3_BOE_HOTPATH
256  void setOrdinary(BlockLength offset, FieldValue value, SchemaVersion since)
257  {
258  if ONIXS_B3_BOE_UNLIKELY(since > container().version())
259  throwDisallowedField();
260 
261  setOrdinary(offset, value);
262  }
263 
264  /// Sets the field value.
265  template<class Enumeration> ONIXS_B3_BOE_HOTPATH
266  void setEnumeration(BlockLength offset, typename Enumeration::Enum value) ONIXS_B3_BOE_NOTHROW
267  {
268  typedef typename Enumeration::Base Base;
269  setOrdinary<Base>(offset, static_cast<Base>(value));
270  }
271 
272  /// Sets the field value.
273  template<class Enumeration> ONIXS_B3_BOE_HOTPATH
274  void setEnumeration(BlockLength offset, typename Enumeration::Enum value, SchemaVersion since)
275  {
276  typedef typename Enumeration::Base Base;
277  setOrdinary(offset, static_cast<Base>(value), since);
278  }
279 
280  /// Sets the field value.
281  template<BlockLength Size> ONIXS_B3_BOE_HOTPATH
282  void setFixedStr(BlockLength offset, StrRef value) ONIXS_B3_BOE_NOTHROW
283  {
284  assert(container().blockLength() >= (offset + Size) && "The requested field exceeds provided block boundaries.");
285  assert(value.size() <= Size && "The string is truncated.");
286 
287  void* const fieldPos = advanceByBytes(container().block(), offset);
288  const size_t sizeToCopy = (std::min)(Size, static_cast<BlockLength>(value.size()));
289 
290  if(sizeToCopy > 0)
291  std::memcpy(fieldPos, value.data(), sizeToCopy);
292 
293  std::memset(advanceByBytes(fieldPos, sizeToCopy), 0, Size - sizeToCopy);
294  }
295 
296  /// Sets the field value.
297  template<BlockLength Size> ONIXS_B3_BOE_HOTPATH
298  void setFixedStr(BlockLength offset, StrRef value, SchemaVersion since)
299  {
300  if ONIXS_B3_BOE_UNLIKELY(since > container().version())
301  throwDisallowedField();
302 
303  setFixedStr<Size>(offset, value);
304  }
305 
306 protected:
307  /// Initializes a blank instance.
309 
311 };
312 
313 /// Operations over a repeating group instance.
314 template <class BodySizeType>
316 {
317 public:
318  /// Type to present the length of binary data of the repeating group entry.
319  typedef BodySizeType BlockLength;
320 
321  /// Initializes a blank instance.
323  : encoded_(ONIXS_B3_BOE_NULLPTR)
324  , size_(0)
325  , version_(0)
326  {
327  }
328 
329  /// Initializes the instance from the memory block of the encoded message.
331  SbeGroupEntry(void* encoded, BlockLength size, SchemaVersion version)
332  : encoded_(encoded)
333  , size_(size)
334  , version_(version)
335  {
336  assert(encoded);
337  }
338 
339  /// \return `true` if the instance refers to a valid content, otherwise - `false`.
341  {
342  return (encoded_ != ONIXS_B3_BOE_NULLPTR);
343  }
344 
345  /// \return the beginning of the group entry body.
346  const void* encoded() const ONIXS_B3_BOE_NOTHROW
347  {
348  assert(valid());
349 
350  return encoded_;
351  }
352 
353  /// \return the beginning of the group entry body.
355  {
356  assert(valid());
357 
358  return encoded_;
359  }
360 
361  /// \return the pointer to the block containing fixed-length fields.
362  const void* block() const ONIXS_B3_BOE_NOTHROW
363  {
364  assert(valid());
365 
366  return encoded_;
367  }
368 
369  /// \return the pointer to the block containing fixed-length fields.
371  {
372  assert(valid());
373 
374  return encoded_;
375  }
376 
377  /// \return Block length.
378  BlockLength blockLength() const ONIXS_B3_BOE_NOTHROW
379  {
380  return size_;
381  }
382 
383  /// \return SBE Schema version.
385  {
386  return version_;
387  }
388 
389  private:
390  void* encoded_;
391  BodySizeType size_;
392  SchemaVersion version_;
393 };
394 
395 /// Operations over SBE-encoded repeating group entries.
396 template <class EntryType, class BlockLength, class NumInGroup, class Length >
398 {
399 public:
400  /// The length of the binary data occupied by the group entries.
401  typedef Length EncodedLength;
402 
403  /// The type of the repeating group entry.
404  typedef EntryType Entry;
405 
406  /// Number of entries in the collection.
407  typedef NumInGroup Size;
408 
409  /// An iterator over SBE-encoded group entries.
411  {
412  public:
413  typedef EntryType Entry;
414  typedef Entry value_type;
415 
416  typedef Entry* pointer;
417  typedef Entry& reference;
418 
419  typedef ptrdiff_t difference_type;
420 
421  typedef std::random_access_iterator_tag iterator_category;
422 
423  /// Initializes the instance that refers to nothing.
425  : entry_(ONIXS_B3_BOE_NULLPTR)
426  , size_(0)
427  , version_(0)
428  {
429  }
430 
431  /// Initializes the instance to the given repeating group.
433  Iterator(void* entry, EncodedLength size, SchemaVersion version) ONIXS_B3_BOE_NOTHROW
434  : entry_(entry)
435  , size_(size)
436  , version_(version)
437  {
438  assert(valid());
439  }
440 
441  /// \return `true` if the instance is valid, otherwise - `false`.
443  {
444  return (entry_ != ONIXS_B3_BOE_NULLPTR);
445  }
446 
447  /// \return the repeating group entry.
449  Entry get() const
450  {
451  assert(valid());
452 
453  return Entry(entry_, size_, version_);
454  }
455 
456  /// \return the repeating group entry.
457  Entry operator *() const
458  {
459  return get();
460  }
461 
462  /// Compares iterators.
463  bool operator == (const Iterator& other) const ONIXS_B3_BOE_NOTHROW
464  {
465  return entry_ == other.entry_;
466  }
467 
468  /// Compares iterators.
469  bool operator !=(const Iterator& other) const ONIXS_B3_BOE_NOTHROW
470  {
471  return entry_ != other.entry_;
472  }
473 
474  /// Established the order between two iterators.
475  bool operator < (const Iterator& other) const ONIXS_B3_BOE_NOTHROW
476  {
477  return entry_ < other.entry_;
478  }
479 
480  /// Established the order between two iterators.
481  bool operator > (const Iterator& other) const ONIXS_B3_BOE_NOTHROW
482  {
483  return entry_ > other.entry_;
484  }
485 
486  /// Advances the next repeating group entry.
487  Iterator& operator ++()
488  {
489  assert(valid());
490 
491  entry_ = advanceByBytes(entry_, size_);
492 
493  return *this;
494  }
495 
496  /// Advances to the previous repeating group entry.
497  Iterator& operator --()
498  {
499  assert(valid());
500 
501  entry_ = advanceBackByBytes(entry_, size_);
502 
503  return *this;
504  }
505 
506  /// Advances by given number of entries.
508  Iterator operator +(difference_type distance) const
509  {
510  assert(valid());
511 
512  return Iterator(advanceByBytes(entry_, distance * size_), size_, version_);
513  }
514 
515  /// Advances back by given number of entries.
517  Iterator operator - (difference_type distance) const
518  {
519  assert(valid());
520 
521  return Iterator(advanceBackByBytes(entry_, distance * size_), size_, version_);
522  }
523 
524  private:
525  void* entry_;
526  EncodedLength size_;
527  SchemaVersion version_;
528  };
529 
530  /// Initializes a blank instance referencing to nothing.
532  : encoded_(ONIXS_B3_BOE_NULLPTR)
533  , blockLength_(0)
534  , size_(0)
535  , version_(0)
536  {
537  }
538 
539  /// Initializes the instance referencing to data.
540  SbeGroupEntries(void* encoded, BlockLength blockLength, Size groupSize, SchemaVersion version) ONIXS_B3_BOE_NOTHROW
541  : encoded_(encoded)
542  , blockLength_(blockLength)
543  , size_(groupSize)
544  , version_(version)
545  {
546  assert(encoded_);
547  assert(blockLength > 0);
548  assert(version != 0);
549  }
550 
551  /// \return `true` if the instance refers to a valid repeating group, otherwise - `false`.
553  {
554  return (ONIXS_B3_BOE_NULLPTR != encoded_);
555  }
556 
557  /// \return `true` if the referenced repeating group is empty, otherwise - `false`.
559  {
560  return (0 == size_);
561  }
562 
563  /// \return number of blocks.
565  {
566  return size_;
567  }
568 
569  /// \return the iterator pointing to the first repeating group entry.
570  Iterator begin() const
571  {
572  return Iterator(encoded(), blockLength_, version_);
573  }
574 
575  /// Returns the iterator pointing to the entry behind the end of the group.
576  Iterator end() const
577  {
578  return Iterator(advanceByBytes(encoded(), encodedLength()), blockLength_, version_);
579  }
580 
581  /// Provides access to the group entry by its index in the repeating group.
582  ///
583  /// \note Index validness is not checked due to performance considerations.
584  Entry operator [](Size index) const
585  {
586  assert(index < size_);
587  assert(encoded_);
588 
589  return Entry(advanceByBytes(encoded_, static_cast<ptrdiff_t>(index) * blockLength_), blockLength_, version_);
590  }
591 
592  /// \return Binary data occupied by the group entries.
594  {
595  return encoded_;
596  }
597 
598  /// \return the length of the binary data occupied by the group entries.
599  EncodedLength encodedLength() const ONIXS_B3_BOE_NOTHROW
600  {
601  return (static_cast<EncodedLength>(blockLength_) * static_cast<EncodedLength>(size_) );
602  }
603 
604  /// Copy constructor.
605  template<class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength >
607  : encoded_(other.encoded_)
608  , blockLength_(other.blockLength_)
609  , size_(other.size_)
610  , version_(other.version_)
611  {
612  // Dimension types may vary for the different instantiations of the template.
613  // Therefore, truncation of the dimensions must be avoided.
614 
615  assert(blockLength_ == other.blockLength_);
616  assert(size_ == other.size_);
617  }
618 
619  template <class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength>
621  {
622  encoded_ = other.encoded_;
623 
624  blockLength_ = other.blockLength_;
625 
626  assert(blockLength_ == other.blockLength_);
627 
628  size_ = other.size_;
629 
630  assert(size_ == other.size_);
631 
632  version_ = other.version_;
633 
634  return *this;
635  }
636 
637 private:
638  // Allows coping and cloning for different instantiations.
639  template <class OtherEntry, class OtherBlockLength, class OtherNumInGroup, class OtherLength> friend class SbeGroupEntries;
640 
641  void* encoded_;
642  BlockLength blockLength_;
643  NumInGroup size_;
644  SchemaVersion version_;
645 };
646 
647 /// SBE-encoded repeating group.
648 template < class EntryType, class DimensionType, class GroupSizeType >
650 {
651 public:
652  /// Repeating group dimension type.
653  typedef DimensionType Dimension;
654 
655  /// Length of group data.
656  typedef GroupSizeType BinarySize;
657 
658  /// Length of an empty group.
659  enum { EmptySize = Dimension::Size };
660 
661  /// Length of group entry data.
662  typedef typename DimensionType::BlockLength EntrySize;
663 
664  /// Binary group blocks.
666 
667  /// The iterator type for group entries.
668  typedef typename Entries::Iterator Iterator;
669 
670  /// Group entry type.
671  typedef typename Entries::Entry Entry;
672 
673  /// Number of entries in the group.
674  typedef typename Entries::Size Size;
675 
676  /// Initializes a blank instance referencing to nothing.
679  : header_(ONIXS_B3_BOE_NULLPTR)
680  , entries_(ONIXS_B3_BOE_NULLPTR)
681  , version_(0)
682  {
683  }
684 
685  /// Initializes an instance referencing to a valid group of a given message.
687  SbeGroup(void* data, ONIXS_B3_BOE_UNUSED BinarySize size, SchemaVersion version) ONIXS_B3_BOE_NOTHROW
688  : header_(static_cast <Dimension*>(data))
689  , entries_(advanceByBytes(data, Dimension::Size))
690  , version_(version)
691  {
692  ONIXS_B3_BOE_ASSERT(size >= Dimension::Size);
693  assert(header_);
694  assert(entries_);
695 
696  assert(valid());
697  }
698 
699  /// \return `true` if the instance refers to a valid repeating group, otherwise - `false`.
701  {
702  return (entries_ != ONIXS_B3_BOE_NULLPTR);
703  }
704 
705  /// \return `true` if the repeating group is empty, otherwise - `false`.
707  {
708  assert(valid());
709 
710  return 0 == size();
711  }
712 
713  /// \return the number of entries in the repeating group.
716  {
717  assert(valid());
718  assert(header_);
719 
720  const Dimension* const group = static_cast<const Dimension*>(header_);
721 
722  return group->numInGroup();
723  }
724 
725  /// \return an iterator pointing to the first repeating group entry.
727  Iterator begin() const ONIXS_B3_BOE_NOTHROW
728  {
729  assert(valid());
730 
731  return Iterator(entries_, numericCast<EntrySize>(entrySize()), version_);
732  }
733 
734  /// \return an iterator pointing to the entry behind the end of the group.
736  Iterator end() const ONIXS_B3_BOE_NOTHROW
737  {
738  assert(valid());
739 
740  return Iterator(advanceByBytes(binary(), binarySize()), numericCast<EntrySize>(entrySize()), version_);
741  }
742 
743  /// Provides access to a repeating group entry by the given index.
744  ///
745  /// \note Index validness is not checked due to performance considerations.
747  Entry operator [](Size index) const
748  {
749  assert(valid());
750  assert(index < size());
751 
752  return Entry(advanceByBytes(entries_, static_cast<ptrdiff_t>(index) * entrySize()), entrySize(), version_);
753  }
754 
755  /// \return Repeating group entries.
758  {
759  assert(valid());
760  assert(header_);
761 
762  return Entries (entries_, header_->blockLength(), header_->numInGroup(), version_);
763  }
764 
765  /// \return SBE-encoded data that represents the repeating group.
766  const void* encoded() const ONIXS_B3_BOE_NOTHROW
767  {
768  return header_;
769  }
770 
771  /// \return the end of SBE-encoded data that represents the repeating group.
772  const void* tail() const ONIXS_B3_BOE_NOTHROW
773  {
774  return advanceByBytes(toByteBlock(encoded()), binarySize());
775  }
776 
777  /// \return SBE-encoded data that represents the repeating group.
780  {
781  return header_;
782  }
783 
784  /// \return the size of SBE-encoded data that represents the repeating group.
786  BinarySize binarySize() const ONIXS_B3_BOE_NOTHROW
787  {
788  return Dimension::Size + (static_cast<BinarySize>(entrySize()) * static_cast<BinarySize>(size()));
789  }
790 
791  /// \return the size of a single repeating group entry.
793  EntrySize entrySize() const ONIXS_B3_BOE_NOTHROW
794  {
795  assert(valid());
796  assert(header_);
797 
798  Dimension* const group = static_cast<Dimension*>(header_);
799  return group->blockLength();
800  }
801 
802 private:
803  /// Resets the group to the initial state, must be invoked only during the message construction.
804  void init(EntrySize entrySize) ONIXS_B3_BOE_NOTHROW
805  {
806  assert(valid());
807  assert(header_);
808 
809  Dimension* const group = static_cast<Dimension*>(header_);
810  group->setBlockLength(entrySize);
811  group->setNumInGroup(0);
812  }
813 
814  /// Allocates a group.
815  Size allocate(Size entryCount, const void* messageTail, const void* blockEnd)
816  {
817  assert(valid());
818  assert(blockEnd);
819  assert(messageTail);
820 
821  Dimension* const group = static_cast<Dimension*>(header_);
822 
823  const EntrySize entrySize = group->blockLength();
824 
825  if ONIXS_B3_BOE_UNLIKELY(
826  entrySize < EntryType::blockLength(version_))
827  {
828  throwBadBinaryBlock();
829  }
830 
831  const Size oldEntryCount = group->numInGroup();
832 
833  if(oldEntryCount == entryCount)
834  return entryCount;
835 
836  const ptrdiff_t memShift =
837  (entryCount - oldEntryCount) * static_cast<ptrdiff_t>(entrySize);
838 
839  const void* const newMessageTail =
840  advanceByBytes(messageTail, memShift);
841 
842  if ONIXS_B3_BOE_UNLIKELY(byteDistance(blockEnd, newMessageTail) < 0)
843  throwNotEnoughSpace();
844 
845  const void* const oldEndOfGroup =
846  advanceByBytes(entries_, static_cast<ptrdiff_t>(entrySize) * oldEntryCount);
847 
848  void* const newEndGroup =
849  advanceByBytes(entries_, static_cast<ptrdiff_t>(entrySize) * entryCount);
850 
851  std::memmove(
852  newEndGroup,
853  oldEndOfGroup,
854  byteDistance(messageTail, oldEndOfGroup));
855 
856  group->setNumInGroup(entryCount);
857 
858  return oldEntryCount;
859  }
860 
861  /// Sets up the group.
863  void setup(Size entryCount, const void* messageTail, const void* blockEnd)
864  {
865  assert(valid());
866  assert(blockEnd);
867  assert(messageTail);
868 
869  const Size oldEntryCount = allocate(entryCount, messageTail, blockEnd);
870 
871  for(Size index = oldEntryCount; index < entryCount; ++index)
872  zeroPaddingBytes((*this)[index].resetVariableFields());
873  }
874 
875  /// Sets up the group, sets all optional fields to `null`.
877  void construct(Size entryCount, const void* messageTail, const void* blockEnd)
878  {
879  assert(valid());
880  assert(blockEnd);
881  assert(messageTail);
882 
883  const Size oldEntryCount = allocate(entryCount, messageTail, blockEnd);
884 
885  for(Size index = oldEntryCount; index < entryCount; ++index)
886  zeroPaddingBytes((*this)[index].reset());
887  }
888 
890  static void zeroPaddingBytes(Entry& entry)
891  {
892  assert(entry.valid());
893  entry.zeroPaddingBytes(EntryType::minimalBlockLength(entry.version()));
894  }
895 
896 private:
897  Dimension* header_;
898  void* entries_;
899  SchemaVersion version_;
900 
901  friend class SbeMessage;
902 };
903 
904 /// Variable-length fields list.
905 template < class BinarySize >
907 {
908 public:
909  /// Initializes the list over the given memory block.
911  SbeVariableLengthFieldList(void* binary, BinarySize size, SchemaVersion version) ONIXS_B3_BOE_NOTHROW
912  : binary_(binary)
913  , size_(size)
914  , version_(version)
915  {
916  }
917 
918  /// \return `true` if the list is empty, otherwise - `false.
920  {
921  return (0 == size_);
922  }
923 
924  /// \return the head of the list.
925  template<class BinaryVariableLengthFieldType>
926  BinaryVariableLengthFieldType& head() const ONIXS_B3_BOE_NOTHROW
927  {
928  return *static_cast<BinaryVariableLengthFieldType*>(binary_);
929  }
930 
931  /// \return the list of variable-length fields following the head.
932  template<class BinaryVariableLengthFieldType> ONIXS_B3_BOE_HOTPATH
934  {
935  assert(!empty());
936 
937  const BinarySize headSize = head<BinaryVariableLengthFieldType>().binarySize();
938 
939  assert(headSize <= size_);
940 
941  return SbeVariableLengthFieldList(advanceByBytes( binary_, headSize), size_ - headSize, version_);
942  }
943 
944  /// Checks the variable-length field list consistency.
945  ///
946  /// \return the list of fields following the head.
947  template<class BinaryVariableLengthFieldType> ONIXS_B3_BOE_HOTPATH
949  {
950  if ONIXS_B3_BOE_UNLIKELY(empty() || (size_ < BinaryVariableLengthFieldType::Size))
951  {
952  throwBadBinaryBlock();
953  }
954 
955  const BinarySize headSize = head<BinaryVariableLengthFieldType>().binarySize();
956 
957  if ONIXS_B3_BOE_UNLIKELY(headSize > size_)
958  {
959  throwBadBinaryBlock();
960  }
961 
962  return SbeVariableLengthFieldList(advanceByBytes(binary_, headSize), size_ - headSize, version_);
963  }
964 
965  private:
966  void* binary_;
967  BinarySize size_;
968  SchemaVersion version_;
969 
970 };
971 
972 /// Groups list.
973 template <class BinarySize>
975 {
976 public:
977  /// Initializes the list over the memory block.
979  SbeGroupList(void* binary, BinarySize size, SchemaVersion version) ONIXS_B3_BOE_NOTHROW
980  : binary_(binary)
981  , size_(size)
982  , version_(version)
983  {
984  }
985 
986  /// \return `true` if the list is empty, otherwise - `false`.
988  {
989  return (0 == size_);
990  }
991 
992  /// \return the head group.
993  template<class Group> ONIXS_B3_BOE_HOTPATH
995  {
996  assert(!empty());
997 
998  return Group(binary_, size_, version_);
999  }
1000 
1001  /// \return the list of groups that follow the head.
1002  template<class Group> ONIXS_B3_BOE_HOTPATH
1004  {
1005  assert(!empty());
1006 
1007  const BinarySize headSize = head<Group>().binarySize();
1008 
1009  assert(headSize <= size_);
1010 
1011  return SbeGroupList(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1012  }
1013 
1014  /// \return variable length fields.
1015  template <class Group> ONIXS_B3_BOE_HOTPATH
1017  {
1018  assert(!empty());
1019 
1020  const BinarySize headSize = head<Group>().binarySize();
1021 
1022  assert(headSize <= size_);
1023 
1024  return SbeVariableLengthFieldList<BinarySize>(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1025  }
1026 
1027  /// Checks the list consistency.
1028  ///
1029  /// \return the list of groups that follow the head.
1030  template<class Group> ONIXS_B3_BOE_HOTPATH
1032  {
1033  const BinarySize headSize = checkHead<Group>();
1034 
1035  return SbeGroupList(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1036  }
1037 
1038  /// Checks the variable length fields list consistency.
1039  ///
1040  /// \return the list of fields that follow the head.
1041  template <class Group> ONIXS_B3_BOE_HOTPATH
1043  {
1044  const BinarySize headSize = checkHead<Group>();
1045 
1046  return SbeVariableLengthFieldList<BinarySize>(advanceByBytes(binary_, headSize), size_ - headSize, version_);
1047  }
1048 
1049 private:
1050  template<class Group>
1051  BinarySize checkHead() const
1052  {
1053  if ONIXS_B3_BOE_UNLIKELY(size_ < Group::Dimension::Size)
1054  {
1055  throwBadBinaryBlock();
1056  }
1057 
1058  const Group group = head<Group>();
1059 
1060  const BinarySize headSize = group.binarySize();
1061 
1062  if ONIXS_B3_BOE_UNLIKELY(headSize > size_)
1063  {
1064  throwBadBinaryBlock();
1065  }
1066 
1067  if(!group.empty())
1068  {
1069  const BinarySize entrySize = group.entrySize();
1070  const BinarySize expectedEntrySize = Group::Entry::minimalBlockLength(version_);
1071 
1072  if ONIXS_B3_BOE_UNLIKELY(entrySize < expectedEntrySize)
1073  {
1074  throwBadBinaryBlock();
1075  }
1076  }
1077 
1078  return headSize;
1079  }
1080 
1081  void* binary_;
1082  BinarySize size_;
1083  SchemaVersion version_;
1084 };
1085 
1086 /// Checks the compatibility with the provided SBE Schema version.
1087 template<typename Traits>
1089 {
1090  if ONIXS_B3_BOE_UNLIKELY(version < Traits::MinimalVersion)
1091  {
1092  throwBadMessageVersion(version, Traits::MinimalVersion);
1093  }
1094 }
1095 
1096 /// Checks the compatibility with the provided SBE Schema version.
1097 template<typename Traits>
1099 {
1100  checkVersion<Traits>(version);
1101 
1102  if ONIXS_B3_BOE_UNLIKELY(version < since)
1103  {
1104  throwBadMessageVersion(version, since);
1105  }
1106 }
1107 
1108 /// Checks the compatibility with the provided SBE Schema ID.
1109 template<typename Traits>
1111 {
1112  if ONIXS_B3_BOE_UNLIKELY(id != Traits::Id)
1113  {
1114  throwBadSchemaId(Traits::Id, id);
1115  }
1116 }
1117 
1118 /// Checks the compatibility with the provided SBE Schema version.
1119 template<typename Traits>
1121 {
1122  checkSchemaId<Traits>(id);
1123  checkVersion<Traits>(version);
1124 }
1125 
1126 /// SBE-encoded message.
1128 {
1129 public:
1130  /// For tagged constructors
1131  struct NoFieldsInit{};
1132  struct NoInit{};
1133  struct NoCheck{};
1134 
1135  /// Length of the message binary data.
1137 
1138  /// Length of the message body representing a block of fixed-length fields.
1140 
1141  /// Initializes a blank instance.
1143  : header_(ONIXS_B3_BOE_NULLPTR)
1144  , size_(0)
1145  {
1146  }
1147 
1148  /// Initializes the instance over the given memory block.
1150  SbeMessage(void* data, MessageSize size, SchemaVersion version)
1151  : header_(static_cast<MessageHeader*>(data))
1152  , size_(size)
1153  {
1154  assert(data);
1155  assert(size <= MaxB3BOEMessageSize);
1156 
1157  if ONIXS_B3_BOE_UNLIKELY(size < MessageHeader::Size)
1158  throwBinaryBlockIsTooSmall(size, MessageHeader::Size);
1159 
1160  this->version(version);
1161  }
1162 
1163  /// Initializes the instance over the given memory block.
1165  SbeMessage(void* data, MessageSize size)
1166  : header_(static_cast<MessageHeader*>(data))
1167  , size_(size)
1168  {
1169  assert(data);
1170  assert(size <= MaxB3BOEMessageSize);
1171 
1172  if ONIXS_B3_BOE_UNLIKELY(size < MessageHeader::Size)
1173  throwBinaryBlockIsTooSmall(size, MessageHeader::Size);
1174 
1175  // Now it is safe to read header_.
1176  if ONIXS_B3_BOE_UNLIKELY(size < (MessageHeader::Size + header_->blockLength()))
1177  throwBinaryBlockIsTooSmall(size, MessageHeader::Size + header_->blockLength());
1178  }
1179 
1180  /// Initializes the instance over the given memory block.
1181  ///
1182  /// \note Performs no check of the data consistency
1185  : header_(static_cast<MessageHeader*>(data))
1186  , size_(size)
1187  {
1188  assert(data);
1189  assert(size <= MaxB3BOEMessageSize);
1190 
1191  assert(size >= MessageHeader::Size);
1192  assert(size >= MessageHeader::Size + header_->blockLength());
1193  }
1194 
1195  /// Blank the instance.
1197  {
1198  *this = SbeMessage();
1199  assert(!valid());
1200  }
1201 
1202  /// \return `true` if the instance refers to a valid message, otherwise - `false`.
1204  {
1205  return (ONIXS_B3_BOE_NULLPTR != header_);
1206  }
1207 
1208  /// \return SBE Template identifier.
1210  {
1211  assert(valid());
1212 
1213  return header_->templateId();
1214  }
1215 
1216  /// \return SBE Schema version.
1218  {
1219  assert(valid());
1220 
1221  return header_->version();
1222  }
1223 
1224  /// \return SBE Schema ID.
1226  {
1227  assert(valid());
1228 
1229  return header_->schemaId();
1230  }
1231 
1232  /// \return SBE-encoded message content.
1233  const void* binary() const ONIXS_B3_BOE_NOTHROW
1234  {
1235  assert(valid());
1236 
1237  return header_;
1238  }
1239 
1240  /// \return SBE-encoded message content.
1242  {
1243  assert(valid());
1244 
1245  return header_;
1246  }
1247 
1248  // \return the end of the memory block.
1250  {
1251  assert(valid());
1252 
1253  return advanceByBytes(header_, size_);
1254  }
1255 
1256  // \return the end of the memory block.
1257  const void* blockEnd() const ONIXS_B3_BOE_NOTHROW
1258  {
1259  assert(valid());
1260 
1261  return advanceByBytes(header_, size_);
1262  }
1263 
1264  /// \return the size of the message buffer.
1266  {
1267  return size_;
1268  }
1269 
1270  /// \return the beginning of the message body.
1272  {
1273  assert(valid());
1274 
1275  return advanceByBytes(header_, MessageHeader::Size);
1276  }
1277 
1278  /// \return the size of the message body in bytes.
1279  BlockLength blockLength() const ONIXS_B3_BOE_NOTHROW
1280  {
1281  assert(valid());
1282 
1283  return header_->blockLength();
1284  }
1285 
1286  /// \return the beginning of the message body.
1287  const void* block() const ONIXS_B3_BOE_NOTHROW
1288  {
1289  assert(valid());
1290 
1291  return advanceByBytes(header_, MessageHeader::Size);
1292  }
1293 
1294  /// \return the beginning of the message body.
1296  {
1297  assert(valid());
1298 
1299  return advanceByBytes(header_, MessageHeader::Size);
1300  }
1301 
1302 protected:
1303  /// Binary group list instantiation.
1305 
1306  /// Sets the SBE Schema version.
1308  {
1309  assert(valid());
1310 
1311  header_->setVersion(version);
1312 
1313  return *this;
1314  }
1315 
1316  /// \return the list of repeating groups
1319  {
1320  assert(header_);
1321 
1322  void* list = advanceByBytes<void>(body(), blockLength());
1323 
1324  const MessageSize listSize = size_ - MessageHeader::Size - header_->blockLength();
1325 
1326  return GroupList(list, listSize, header_->version());
1327  }
1328 
1329  /// \return the list of repeating groups
1331  GroupList groups() const ONIXS_B3_BOE_NOTHROW
1332  {
1333  assert(header_);
1334 
1335  const void* list = advanceByBytes(block(), blockLength());
1336 
1337  const MessageSize listSize = size_ - MessageHeader::Size - header_->blockLength();
1338 
1339  return GroupList(const_cast<void*>(list), listSize, header_->version());
1340  }
1341 
1342  /// Resets the group to the initial state.
1343  template<typename Group>
1345  void initGroup(Group& group, typename Group::EntrySize entrySize) ONIXS_B3_BOE_NOTHROW
1346  {
1347  assert(group.valid());
1348  group.init(entrySize);
1349  }
1350 
1351  /// Initializes the group header.
1352  template<typename Group>
1354  void setupGroup(Group& group, typename Group::Size entryCount, const void* messageTail)
1355  {
1356  assert(messageTail);
1357  assert(group.valid());
1358  group.setup(entryCount, messageTail, blockEnd());
1359  }
1360 
1361  /// Initializes the group header, sets all optional fields to `null`.
1362  template<typename Group>
1364  void constructGroup(Group& group, typename Group::Size entryCount, const void* messageTail)
1365  {
1366  assert(messageTail);
1367  assert(group.valid());
1368  group.construct(entryCount, messageTail, blockEnd());
1369  }
1370 
1371  /// Sets the variable length field value.
1372  template<typename DATA>
1373  void setVarDataField(DATA& data, StrRef value, const void* oldMessageTail)
1374  {
1375  assert(oldMessageTail);
1376 
1377  const ptrdiff_t lengthChange = static_cast<ptrdiff_t>(value.length() - data.length());
1378 
1379  const void* const newMessageTail = advanceByBytes(oldMessageTail, lengthChange);
1380 
1381  if ONIXS_B3_BOE_UNLIKELY(byteDistance(blockEnd(), newMessageTail) < 0)
1382  throwNotEnoughSpace();
1383 
1384  const void* const oldEndOfData = advanceByBytes(data.varData().data(), data.varData().size());
1385 
1386  void* const newEndOfData = toOpaquePtr(advanceByBytes(&data, value.length() + DATA::Size));
1387 
1388  std::memmove(newEndOfData, oldEndOfData, byteDistance(oldMessageTail, oldEndOfData));
1389 
1390  data.varData(value);
1391  }
1392 
1393  /// Binary group list instantiation.
1395 
1396  /// \return the list of variable-length fields.
1398  VariableLengthFieldList variableLengthFields() ONIXS_B3_BOE_NOTHROW
1399  {
1400  assert(header_);
1401 
1402  void* list = advanceByBytes<void>(body(), blockLength());
1403 
1404  const MessageSize listSize = size_ - MessageHeader::Size - header_->blockLength();
1405 
1406  return VariableLengthFieldList(list, listSize, header_->version());
1407  }
1408 
1409  /// \return the list of variable-length fields.
1411  VariableLengthFieldList variableLengthFields() const ONIXS_B3_BOE_NOTHROW
1412  {
1413  assert(header_);
1414 
1415  const void* list = advanceByBytes(block(), blockLength());
1416 
1417  const MessageSize listSize = size_ - MessageHeader::Size - header_->blockLength();
1418 
1419  return VariableLengthFieldList(const_cast<void*>(list), listSize, header_->version());
1420  }
1421 
1423  void init(
1425  MessageHeader::BlockLength minimalBlockLength,
1426  MessageHeader::BlockLength blockLength,
1428  {
1429  assert(header_);
1430  assert(blockLength >= minimalBlockLength);
1431 
1432  header_->setTemplateId(value);
1433  header_->setBlockLength(blockLength);
1434  header_->setSchemaId(id);
1435 
1436  zeroPaddingBytes(minimalBlockLength);
1437  }
1438 
1441  {
1442  assert(tail);
1443 
1444  const ptrdiff_t distance = byteDistance(tail, binary());
1445 
1446  assert(distance > 0);
1447 
1448  assert(distance <= (std::numeric_limits<MessageSize>::max)());
1449 
1450  const MessageSize size = static_cast<MessageSize>(distance);
1451 
1452  assert(size <= size_);
1453 
1454  return size;
1455  }
1456 
1457  /// Sets the value of the variable length field.
1458  template<class Callable, class Owner>
1459  void setVariableLengthField(Callable callable, StrRef value, Owner& owner)
1460  {
1461  setVarDataField(callable(owner), value, owner.tail());
1462  }
1463 
1464  /// Sets the value of the variable length field.
1465  template<class Callable, class Owner>
1466  void setVariableLengthField(Callable callable, StrRef value, SchemaVersion since, Owner& owner)
1467  {
1468  if ONIXS_B3_BOE_UNLIKELY(since > version())
1469  throwDisallowedField();
1470 
1471  setVariableLengthField(callable, value, owner);
1472  }
1473 
1474  /// \return the value of the variable length field.
1475  template<class Callable, class Owner>
1476  StrRef getVariableLengthField(Callable callable, const Owner& owner) const ONIXS_B3_BOE_NOTHROW
1477  {
1478  ONIXS_B3_BOE_CHECK_NOTHROW(callable(owner));
1479  return callable(owner).varData();
1480  }
1481 
1482  /// \return the value of the variable length field.
1483  template<class Callable, class Owner>
1484  StrRef getVariableLengthField(Callable callable, SchemaVersion since, Owner& owner) const ONIXS_B3_BOE_NOTHROW
1485  {
1486  if ONIXS_B3_BOE_UNLIKELY(since > version())
1487  return StrRef();
1488 
1489  return getVariableLengthField(callable, owner);
1490  }
1491 
1492  /// Resets the variable length field.
1493  template<class Callable, class Owner>
1494  void setVariableLengthFieldToNull(Callable callable, Owner& owner) ONIXS_B3_BOE_NOTHROW
1495  {
1496  ONIXS_B3_BOE_CHECK_NOTHROW(callable(owner));
1497  callable(owner).length(0);
1498  }
1499 
1500  /// Sets the group to the initial state.
1501  template<class Group, class Callable, class Owner>
1502  void resetGroup(Callable callable, Owner& owner) ONIXS_B3_BOE_NOTHROW
1503  {
1504  const typename Group::EntrySize entrySize = Group::Entry::blockLength(version());
1505 
1506  Group grp = callable(owner);
1507 
1508  initGroup(grp, entrySize);
1509  }
1510 
1511  /// Sets the variable length field to `null`.
1512  template<class Callable, class Owner>
1513  void setVariableLengthFieldToNull(Callable callable, SchemaVersion since, Owner& owner) ONIXS_B3_BOE_NOTHROW
1514  {
1515  if ONIXS_B3_BOE_UNLIKELY(since > version())
1516  return;
1517 
1518  setVariableLengthFieldToNull(callable, owner);
1519  }
1520 
1521  /// Resets the repeating group.
1522  template<class Group, class Callable, class Owner>
1523  void resetGroup(Callable callable, SchemaVersion since, Owner& owner)
1524  {
1525  if ONIXS_B3_BOE_UNLIKELY(since > version())
1526  return;
1527 
1528  resetGroup<Group>(callable, owner);
1529  }
1530 
1531  /// \return the repeating group.
1532  template<class Group, class Callable, class Owner>
1533  Group getGroup(Callable callable, Owner& owner) const ONIXS_B3_BOE_NOTHROW
1534  {
1535  ONIXS_B3_BOE_CHECK_NOTHROW(callable(owner));
1536  return callable(owner);
1537  }
1538 
1539  /// \return the repeating group.
1540  template<class Group, class Callable, class Owner>
1541  Group getGroup(Callable callable, SchemaVersion since, Owner& owner) const ONIXS_B3_BOE_NOTHROW
1542  {
1543  if ONIXS_B3_BOE_UNLIKELY(since > version())
1544  return Group();
1545 
1546  return getGroup<Group>(callable, owner);
1547  }
1548 
1549  /// Creates a repeating group with the given number of entries, sets all optional fields of the group entries to null.
1550  template<class Group, class Callable, class Owner>
1551  Group constructGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner& owner)
1552  {
1553  if ONIXS_B3_BOE_UNLIKELY(since > version())
1554  return Group();
1555 
1556  return constructGroup<Group>(callable, length, owner);
1557  }
1558 
1559  /// Creates a repeating group with the given number of entries, sets all optional fields of the group entries to null.
1560  template<class Group, class Callable, class Owner>
1561  Group constructGroup(Callable callable, typename Group::Size length, Owner& owner)
1562  {
1563  Group group = callable(owner);
1564 
1565  constructGroup(group, length, owner.tail());
1566 
1567  return group;
1568  }
1569 
1570  /// Setups the repeating group with the given number of entries.
1571  template<class Group, class Callable, class Owner>
1572  Group setupGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner& owner)
1573  {
1574  if ONIXS_B3_BOE_UNLIKELY(since > version())
1575  return Group();
1576 
1577  return setupGroup<Group>(callable, length, owner);
1578  }
1579 
1580  /// Setups the repeating group with the given number of entries.
1581  template<class Group, class Callable, class Owner>
1582  Group setupGroup(Callable callable, typename Group::Size length, Owner& owner)
1583  {
1584  Group group = callable(owner);
1585 
1586  setupGroup(group, length, owner.tail());
1587 
1588  return group;
1589  }
1590 
1591  /// Maximal message size.
1596  {
1597  return
1599  }
1600 
1601 private:
1602  MessageHeader* header_;
1603  MessageSize size_;
1604 };
1605 
SbeGroupEntries() noexcept
Initializes a blank instance referencing to nothing.
Definition: SbeMessage.h:531
StrRef fixedStr(BlockLength offset) const noexcept
Provides access to a string field value.
Definition: SbeMessage.h:187
EntrySize entrySize() const noexcept
Definition: SbeMessage.h:793
#define ONIXS_B3_BOE_MESSAGING_NAMESPACE_END
Definition: ABI.h:144
Operations over SBE-encoded repeating group entries.
Definition: SbeMessage.h:397
Operations over a repeating group instance.
Definition: SbeMessage.h:315
MessageSize calculateBinarySize(const void *tail) const noexcept
Definition: SbeMessage.h:1440
SbeGroupEntries(void *encoded, BlockLength blockLength, Size groupSize, SchemaVersion version) noexcept
Initializes the instance referencing to data.
Definition: SbeMessage.h:540
bool decimal(Value &value, BlockLength offset, NullValue null) const noexcept
Definition: SbeMessage.h:169
const void * encoded() const noexcept
Definition: SbeMessage.h:346
SbeGroupList tail() const noexcept
Definition: SbeMessage.h:1003
BodySizeType BlockLength
Type to present the length of binary data of the repeating group entry.
Definition: SbeMessage.h:319
#define ONIXS_B3_BOE_NULLPTR
Definition: Compiler.h:188
SbeVariableLengthFieldList< MessageSize > VariableLengthFieldList
Binary group list instantiation.
Definition: SbeMessage.h:1394
Value ordinary(BlockLength offset) const noexcept
Definition: SbeMessage.h:79
SchemaVersion version() const noexcept
Definition: SbeMessage.h:384
BinarySize binarySize() const noexcept
Definition: SbeMessage.h:786
Enumeration::Enum enumeration(BlockLength offset) const noexcept
Definition: SbeMessage.h:131
void setVariableLengthFieldToNull(Callable callable, SchemaVersion since, Owner &owner) noexcept
Sets the variable length field to null.
Definition: SbeMessage.h:1513
bool ordinary(Value &value, BlockLength offset, NullValue null) const noexcept
Provides access to an optional field value.
Definition: SbeMessage.h:112
SbeGroupList(void *binary, BinarySize size, SchemaVersion version) noexcept
Initializes the list over the memory block.
Definition: SbeMessage.h:979
Size size() const noexcept
Definition: SbeMessage.h:715
MessageSize BlockLength
Length of the message body representing a block of fixed-length fields.
Definition: SbeMessage.h:1139
MessageHeader::Version SchemaVersion
SBE-encoded data version type.
Definition: SchemaTraits.h:30
#define ONIXS_B3_BOE_NOTHROW
Definition: Compiler.h:182
Group getGroup(Callable callable, SchemaVersion since, Owner &owner) const noexcept
Definition: SbeMessage.h:1541
TimeSpan operator-(const TimeSpan &timeSpan) noexcept
Changes the sign of the Timestamp.
Definition: Time.h:377
BinaryVariableLengthFieldType & head() const noexcept
Definition: SbeMessage.h:926
#define ONIXS_B3_BOE_HOTPATH
Definition: Compiler.h:193
Group getGroup(Callable callable, Owner &owner) const noexcept
Definition: SbeMessage.h:1533
Value decimal(BlockLength offset) const noexcept
Definition: SbeMessage.h:159
SbeMessage(void *data, MessageSize size, NoCheck) noexcept
Initializes the instance over the given memory block.
Definition: SbeMessage.h:1184
void init(MessageHeader::TemplateId value, MessageHeader::BlockLength minimalBlockLength, MessageHeader::BlockLength blockLength, SchemaId id) noexcept
Definition: SbeMessage.h:1423
SBE-encoded repeating group.
Definition: SbeMessage.h:649
SchemaVersion version() const noexcept
Definition: SbeMessage.h:1217
Timestamp operator+(const Timestamp &timestamp, const TimeSpan &timeSpan) noexcept
Adds the time interval.
Definition: Time.h:727
SbeVariableLengthFieldList tail() const noexcept
Definition: SbeMessage.h:933
bool empty() const noexcept
Definition: SbeMessage.h:706
void checkSchema(SchemaId id, SchemaVersion version)
Checks the compatibility with the provided SBE Schema version.
Definition: SbeMessage.h:1120
bool fixedStr(StrRef &value, BlockLength offset, SchemaVersion since) const noexcept
Provides access to an optional string field value.
Definition: SbeMessage.h:212
SbeGroup() noexcept
Initializes a blank instance referencing to nothing.
Definition: SbeMessage.h:677
MessageTemplateId templateId() const noexcept
Definition: SbeMessage.h:1209
GroupSizeType BinarySize
Length of group data.
Definition: SbeMessage.h:656
SbeVariableLengthFieldList< BinarySize > checkVariableLengthFields() const
Checks the variable length fields list consistency.
Definition: SbeMessage.h:1042
SbeMessage(void *data, MessageSize size)
Initializes the instance over the given memory block.
Definition: SbeMessage.h:1165
Entries entries() const noexcept
Definition: SbeMessage.h:757
const void * block() const noexcept
Definition: SbeMessage.h:362
SbeGroupEntry()
Initializes a blank instance.
Definition: SbeMessage.h:322
void setOrdinary(BlockLength offset, FieldValue value) noexcept
Sets the field value.
Definition: SbeMessage.h:246
#define ONIXS_B3_BOE_CONSTEXPR
Definition: Compiler.h:185
void resetGroup(Callable callable, Owner &owner) noexcept
Sets the group to the initial state.
Definition: SbeMessage.h:1502
Container & container() noexcept
Definition: SbeMessage.h:227
void checkVersion(SchemaVersion since, SchemaVersion version)
Checks the compatibility with the provided SBE Schema version.
Definition: SbeMessage.h:1098
UInt16 MessageSize
Message length type.
Definition: Aliases.h:29
bool decimal(Value &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Definition: SbeMessage.h:180
Iterator end() const noexcept
Definition: SbeMessage.h:736
Group setupGroup(Callable callable, typename Group::Size length, Owner &owner)
Setups the repeating group with the given number of entries.
Definition: SbeMessage.h:1582
const void * encoded() const noexcept
Definition: SbeMessage.h:766
Group constructGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner &owner)
Creates a repeating group with the given number of entries, sets all optional fields of the group ent...
Definition: SbeMessage.h:1551
Value & accessOrdinary(BlockLength offset) noexcept
Definition: SbeMessage.h:102
#define ONIXS_B3_BOE_NODISCARD
Definition: Compiler.h:191
static constexpr MessageSize getMaxMessageSize() noexcept
Maximal message size.
Definition: SbeMessage.h:1595
SchemaId schemaId() const noexcept
Definition: SbeMessage.h:1225
EncodedLength encodedLength() const noexcept
Definition: SbeMessage.h:599
DimensionType Dimension
Repeating group dimension type.
Definition: SbeMessage.h:653
SbeVariableLengthFieldList checkTail() const
Checks the variable-length field list consistency.
Definition: SbeMessage.h:948
const void * tail() const noexcept
Definition: SbeMessage.h:772
SbeMessage() noexcept
Initializes a blank instance.
Definition: SbeMessage.h:1142
Iterator() noexcept
Initializes the instance that refers to nothing.
Definition: SbeMessage.h:424
Iterator(void *entry, EncodedLength size, SchemaVersion version) noexcept
Initializes the instance to the given repeating group.
Definition: SbeMessage.h:433
SbeGroup(void *data, BinarySize size, SchemaVersion version) noexcept
Initializes an instance referencing to a valid group of a given message.
Definition: SbeMessage.h:687
MessageSize bufferSize() const noexcept
Definition: SbeMessage.h:1265
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Provides access to an optional field value.
Definition: SbeMessage.h:152
Entries::Size Size
Number of entries in the group.
Definition: SbeMessage.h:674
void setVariableLengthField(Callable callable, StrRef value, SchemaVersion since, Owner &owner)
Sets the value of the variable length field.
Definition: SbeMessage.h:1466
constexpr UInt16 MaxB3BOEMessageSize
Maximum supported message size.
std::random_access_iterator_tag iterator_category
Definition: SbeMessage.h:421
UInt16 BlockLength
Length of the root of the FIX message contained before repeating groups or variable/conditions fields...
Definition: Composites.h:40
void clear() noexcept
Blank the instance.
Definition: SbeMessage.h:1196
#define ONIXS_B3_BOE_MESSAGING_NAMESPACE_BEGIN
Definition: ABI.h:140
void constructGroup(Group &group, typename Group::Size entryCount, const void *messageTail)
Initializes the group header, sets all optional fields to null.
Definition: SbeMessage.h:1364
SbeGroupList< MessageSize > GroupList
Binary group list instantiation.
Definition: SbeMessage.h:1304
StrRef getVariableLengthField(Callable callable, SchemaVersion since, Owner &owner) const noexcept
Definition: SbeMessage.h:1484
SbeGroupEntries< EntryType, typename Dimension::BlockLength, typename Dimension::NumInGroup, GroupSizeType > Entries
Binary group blocks.
Definition: SbeMessage.h:665
VariableLengthFieldList variableLengthFields() noexcept
Definition: SbeMessage.h:1398
VariableLengthFieldList variableLengthFields() const noexcept
Definition: SbeMessage.h:1411
#define ONIXS_B3_BOE_LTWT_CLASS
Definition: ABI.h:84
BlockLength blockLength() const noexcept
Definition: SbeMessage.h:378
Iterator begin() const noexcept
Definition: SbeMessage.h:727
SbeGroupEntry(void *encoded, BlockLength size, SchemaVersion version)
Initializes the instance from the memory block of the encoded message.
Definition: SbeMessage.h:331
const void * binary() const noexcept
Definition: SbeMessage.h:1233
NumInGroup Size
Number of entries in the collection.
Definition: SbeMessage.h:407
Group setupGroup(Callable callable, typename Group::Size length, SchemaVersion since, Owner &owner)
Setups the repeating group with the given number of entries.
Definition: SbeMessage.h:1572
Length EncodedLength
The length of the binary data occupied by the group entries.
Definition: SbeMessage.h:401
std::basic_string_view< Char > StrRef
Definition: StrRef.h:46
Entries::Entry Entry
Group entry type.
Definition: SbeMessage.h:671
GroupList groups() const noexcept
Definition: SbeMessage.h:1331
void setVariableLengthField(Callable callable, StrRef value, Owner &owner)
Sets the value of the variable length field.
Definition: SbeMessage.h:1459
Group constructGroup(Callable callable, typename Group::Size length, Owner &owner)
Creates a repeating group with the given number of entries, sets all optional fields of the group ent...
Definition: SbeMessage.h:1561
void checkSchemaId(SchemaId id)
Checks the compatibility with the provided SBE Schema ID.
Definition: SbeMessage.h:1110
void setupGroup(Group &group, typename Group::Size entryCount, const void *messageTail)
Initializes the group header.
Definition: SbeMessage.h:1354
SbeMessage(void *data, MessageSize size, SchemaVersion version)
Initializes the instance over the given memory block.
Definition: SbeMessage.h:1150
Message identifiers and length of message root.
Definition: Composites.h:33
const void * blockEnd() noexcept
Definition: SbeMessage.h:1249
#define ONIXS_B3_BOE_DEFAULT
Definition: Compiler.h:208
SbeVariableLengthFieldList(void *binary, BinarySize size, SchemaVersion version) noexcept
Initializes the list over the given memory block.
Definition: SbeMessage.h:911
SbeGroupEntries(const SbeGroupEntries< OtherEntry, OtherBlockLength, OtherNumInGroup, OtherLength > &other) noexcept
Copy constructor.
Definition: SbeMessage.h:606
char Char
Character type alias.
Definition: String.h:30
bool ordinary(Value &value, BlockLength offset, NullValue null, SchemaVersion since) const noexcept
Provides access to an optional field value.
Definition: SbeMessage.h:124
An iterator over SBE-encoded group entries.
Definition: SbeMessage.h:410
MessageSize EncodedLength
Length of the message binary data.
Definition: SbeMessage.h:1136
void zeroPaddingBytes(BlockLength offset) noexcept
If specified, the extra space is padded at the end of each entry and should be set to zeroes by encod...
Definition: SbeMessage.h:234
SbeGroupList checkTail() const
Checks the list consistency.
Definition: SbeMessage.h:1031
void setFixedStr(BlockLength offset, StrRef value) noexcept
Sets the field value.
Definition: SbeMessage.h:282
void resetGroup(Callable callable, SchemaVersion since, Owner &owner)
Resets the repeating group.
Definition: SbeMessage.h:1523
const Value & accessOrdinary(BlockLength offset) const noexcept
Definition: SbeMessage.h:90
Base services to access fields stored in an SBE-encoded block of memory.
Definition: SbeMessage.h:223
bool valid() const noexcept
Definition: SbeMessage.h:700
void setVarDataField(DATA &data, StrRef value, const void *oldMessageTail)
Sets the variable length field value.
Definition: SbeMessage.h:1373
void setOrdinary(BlockLength offset, FieldValue value, SchemaVersion since)
Sets the field value.
Definition: SbeMessage.h:256
void setFixedStr(BlockLength offset, StrRef value, SchemaVersion since)
Sets the field value.
Definition: SbeMessage.h:298
UInt16 TemplateId
Template ID used to encode the message.
Definition: Composites.h:43
MessageHeader::SchemaId SchemaId
Definition: SchemaTraits.h:34
#define ONIXS_B3_BOE_LTWT_EXPORTED
Definition: ABI.h:92
DimensionType::BlockLength EntrySize
Length of group entry data.
Definition: SbeMessage.h:662
bool enumeration(typename Enumeration::Enum &value, BlockLength offset, NullValue null) const noexcept
Provides access to an optional field value.
Definition: SbeMessage.h:141
void setEnumeration(BlockLength offset, typename Enumeration::Enum value, SchemaVersion since)
Sets the field value.
Definition: SbeMessage.h:274
void * binary() const noexcept
Definition: SbeMessage.h:779
void setEnumeration(BlockLength offset, typename Enumeration::Enum value) noexcept
Sets the field value.
Definition: SbeMessage.h:266
bool fixedStr(StrRef &value, BlockLength offset) const noexcept
Provides access to an optional string field value.
Definition: SbeMessage.h:201
SbeVariableLengthFieldList< BinarySize > variableLengthFields() const noexcept
Definition: SbeMessage.h:1016
Entries::Iterator Iterator
The iterator type for group entries.
Definition: SbeMessage.h:668
EntryType Entry
The type of the repeating group entry.
Definition: SbeMessage.h:404
MessageHeader::TemplateId MessageTemplateId
Message type (template) identification.
const void * block() const noexcept
Definition: SbeMessage.h:1287
Services to access fields stored in an SBE-encoded block of fixed-length fields.
Definition: SbeMessage.h:63
SbeMessage & version(SchemaVersion version) noexcept
Sets the SBE Schema version.
Definition: SbeMessage.h:1307
StrRef getVariableLengthField(Callable callable, const Owner &owner) const noexcept
Definition: SbeMessage.h:1476
void initGroup(Group &group, typename Group::EntrySize entrySize) noexcept
Resets the group to the initial state.
Definition: SbeMessage.h:1345
Iterator end() const
Returns the iterator pointing to the entry behind the end of the group.
Definition: SbeMessage.h:576
BlockLength blockLength() const noexcept
Definition: SbeMessage.h:1279
void setVariableLengthFieldToNull(Callable callable, Owner &owner) noexcept
Resets the variable length field.
Definition: SbeMessage.h:1494
#define ONIXS_B3_BOE_UNUSED
Definition: Compiler.h:207
const void * blockEnd() const noexcept
Definition: SbeMessage.h:1257