OnixS C++ CME MDP Premium Market Data Handler 5.10.2
Users' manual and API documentation
Loading...
Searching...
No Matches
Message.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
26
27#include <cstdlib>
28
30
34{
36 virtual Field field(const BinaryBlockBase&, Tag) const noexcept = 0;
37
39 virtual void setField(BinaryBlockBase&, Tag, const Field&) const = 0;
40
42 virtual void resetField(BinaryBlockBase&, Tag) const = 0;
43
45 virtual void reset(BinaryBlockBase&) const noexcept = 0;
46
47protected:
48 ~FieldAccessor() = default;
49};
50
53{
55 explicit operator bool() const noexcept
56 {
57 return (nullptr != accessor_);
58 }
59
66 FieldSet& reset() noexcept
67 {
68 accessor_->reset(binary_);
69
70 return *this;
71 }
72
80 {
81 assert(accessor_);
82
83 return accessor_->field(binary_, tag);
84 }
85
91 {
92 assert(accessor_);
93 assert(field);
94
95 accessor_->setField(binary_, tag, field);
96
97 return *this;
98 }
99
110 {
111 assert(accessor_);
112
113 accessor_->resetField(binary_, tag);
114
115 return *this;
116 }
117
129 {
130 return this->field(tag);
131 }
132
140 ONIXS_CMEMDH_NODISCARD bool contain(Tag tag) const noexcept;
141
152
163
174
185
196
207
218
229
240
251
262
273
284
294 template <typename Enumeration>
295 ONIXS_CMEMDH_NODISCARD typename Enumeration::Enum getEnumeration(Tag tag) const
296 {
297 return field(tag).cast<Enumeration>();
298 }
299
309 template <typename BitSet>
311 {
312 return BitSet(field(tag).cast<typename BitSet::Bits>());
313 }
314
319 FieldSet& set(Tag tag, const Field& field)
320 {
321 return setField(tag, field);
322 }
323
328 template <typename BitSet>
329 FieldSet& set(Tag tag, BitSet value, typename BitSet::Bits* = nullptr)
330 {
331 return set(tag, value.bits());
332 }
333
339
350
361
372
383
394
405
416
427
437 FieldSet& set(Tag tag, const Decimal& value);
438
449
460
471
472 ~FieldSet() = default;
473
474protected:
477 : binary_(binary)
478 , accessor_(accessor)
479 {
480 }
481
483 const FieldAccessor* accessor() const noexcept
484 {
485 return accessor_;
486 }
487
489 void setAccessor(const FieldAccessor* obj) noexcept
490 {
491 accessor_ = obj;
492 }
493
494private:
495 BinaryBlockBase& binary_;
496 const FieldAccessor* accessor_;
497};
498
500
507
510class GroupEntry : public FieldSet
511{
512public:
515 GroupEntry() noexcept
516 : FieldSet(binary_, nullptr)
517 , binary_()
518 {
519 }
520
523 GroupEntry(const GroupEntry& r) noexcept
524 : FieldSet(binary_, r.accessor())
525 , binary_(r.binary_)
526 {
527 }
528
531 GroupEntry& operator=(const GroupEntry& r) noexcept
532 {
533 setAccessor(r.accessor());
534 this->binary_ = r.binary_;
535
536 return *this;
537 }
538
539protected:
541
545 : FieldSet(binary_, &accessor)
546 , binary_(binary)
547 {
548 }
549
550private:
551 GroupEntrySource binary_;
552};
553
555
558class Group
559{
560public:
563
567 : accessor_(nullptr)
568 {
569 }
570
573 explicit operator bool() const noexcept
574 {
575 return (nullptr != accessor_);
576 }
577
580 Size size() const noexcept
581 {
582 return binary_.size();
583 }
584
588 {
589 assert(accessor_);
590 assert(binary_.valid());
591
592 return GroupEntry(binary_[index], *accessor_);
593 }
594
595protected:
597 Group(const GroupEntriesSource& binary, const GroupEntryAccessor& accessor) noexcept
598 : binary_(binary)
599 , accessor_(&accessor)
600 {
601 }
602
603private:
604 GroupEntriesSource binary_;
605 const GroupEntryAccessor* accessor_;
606};
607
611{
613 virtual StrRef type() const noexcept = 0;
614
616 virtual Group group(const SbeMessage&, Tag) const noexcept = 0;
617
619 virtual Group group(SbeMessage&, Tag, MessageSize) const = 0;
620
622 virtual MessageSize calculateBinarySize(const SbeMessage&) const noexcept = 0;
623
626 virtual void toFix(std::string&, const SbeMessage&) const = 0;
627
629 std::string toFix(const SbeMessage&, Char delimiter) const;
630
631 ~MessageAccessor() = default;
632};
633
636class Message : public FieldSet
637{
638public:
641 Message() noexcept
642 : FieldSet(binary_, nullptr)
643 , binary_()
644 {
645 }
646
648 Message(const Message& r) noexcept
649 : FieldSet(binary_, r.accessor())
650 , binary_(r.binary_)
651 {
652 }
653
655 Message& operator=(const Message& r) noexcept
656 {
657 setAccessor(r.accessor());
658 this->binary_ = r.binary_;
659
660 return *this;
661 }
662
664 StrRef type() const noexcept
665 {
666 return accessor()->type();
667 }
668
673 Group group(Tag tag) const noexcept
674 {
675 assert(binary_.valid());
676
677 return accessor()->group(binary_, tag);
678 }
679
686 {
687 assert(binary_.valid());
688
689 return accessor()->group(binary_, tag, size);
690 }
691
702 {
703 return field(tag).cast<StrRef>();
704 }
705
716 {
717 set(tag, value);
718
719 return *this;
720 }
721
729 {
730 assert(binary_.valid());
731
732 return accessor()->calculateBinarySize(binary_);
733 }
734
736 void toFix(std::string& str) const
737 {
738 accessor()->toFix(str, binary_);
739 }
740
742 ONIXS_CMEMDH_NODISCARD std::string toFix(Char delimiter = '\x1') const
743 {
744 return accessor()->toFix(binary_, delimiter);
745 }
746
749 {
750 return accessor()->toFix(binary_, '|');
751 }
752
760 {
761 assert(accessor());
762 assert(binary_.valid());
763
764 return binary_.version();
765 }
766
774 {
775 assert(accessor());
776 assert(binary_.valid());
777
778 return binary_.templateId();
779 }
780
781 ~Message() = default;
782
783protected:
785 Message(SbeMessage binary, const MessageAccessor& accessor) noexcept
786 : FieldSet(binary_, &accessor)
787 , binary_(binary)
788 {
789 }
790
791private:
792 const MessageAccessor* accessor() const noexcept
793 {
794 const FieldAccessor* const parentAccessor = FieldSet::accessor();
795
796 assert(parentAccessor);
797 assert(dynamic_cast<const MessageAccessor*>(parentAccessor));
798
799 return static_cast<const MessageAccessor*>(parentAccessor);
800 }
801
802private:
803 SbeMessage binary_;
804};
805
807inline void toStr(std::string& str, const Message& message)
808{
809 message.toFix(str);
810}
811
813inline std::string toStr(const Message& message)
814{
815 std::string str;
816
817 toStr(str, message);
818
819 return str;
820}
821
823inline std::ostream& operator<<(std::ostream& stream, const Message& msg)
824{
825 return stream << msg.toString();
826}
827
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition Bootstrap.h:48
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_BEGIN
Definition Bootstrap.h:60
#define ONIXS_CMEMDH_MESSAGING_TAGBASED_NAMESPACE_END
Definition Bootstrap.h:61
#define ONIXS_CMEMDH_EXPORTED
Definition Compiler.h:148
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:150
A field in a tag-based message.
Definition Field.h:30
GroupEntry(const GroupEntry &r) noexcept
Definition Message.h:523
GroupEntry(const GroupEntrySource &binary, const GroupEntryAccessor &accessor) noexcept
Definition Message.h:544
GroupEntry & operator=(const GroupEntry &r) noexcept
Definition Message.h:531
Group(const GroupEntriesSource &binary, const GroupEntryAccessor &accessor) noexcept
Initializes the instance over the binary data.
Definition Message.h:597
GroupEntry operator[](Size index) const
Definition Message.h:587
GroupEntriesSource::Size Size
Number of repeating group entries.
Definition Message.h:562
std::string toFix(Char delimiter='\x1') const
Definition Message.h:742
Message & operator=(const Message &r) noexcept
Re-initializes as the copy of the given instance.
Definition Message.h:655
std::string toString() const
Builds a human-readable tag=value representation.
Definition Message.h:748
Message(SbeMessage binary, const MessageAccessor &accessor) noexcept
Initializes the instance from an SBE-encoded message.
Definition Message.h:785
Group group(Tag tag, MessageSize size)
Definition Message.h:685
Message & setVarData(Tag tag, StrRef value)
Definition Message.h:715
MessageTemplateId templateId() const
Definition Message.h:773
MessageSize calculateBinarySize() const noexcept
Definition Message.h:728
void toFix(std::string &str) const
Builds a tag=value representation.
Definition Message.h:736
Group group(Tag tag) const noexcept
Definition Message.h:673
Message(const Message &r) noexcept
Initializes the instance as the copy of the given one.
Definition Message.h:648
Operations over SBE-encoded repeating group entries.
Definition SbeMessage.h:435
Operations over a repeating group instance.
Definition SbeMessage.h:346
The time point without the time-zone information.
Definition Time.h:425
std::ostream & operator<<(std::ostream &stream, const Field &field)
Serializes into the given stream.
Definition Field.h:365
void toStr(std::string &str, const Message &message)
Serializes into a tag=value format.
Definition Message.h:807
SbeGroupEntry< MessageSize > GroupEntrySource
Definition Message.h:499
SbeGroupEntries< GroupEntrySource, MessageSize, MessageSize, MessageSize > GroupEntriesSource
Definition Message.h:554
bool value(Number &number, const MultiContainer &container, Tag tag)
std::uint32_t UInt32
uInt32.
Definition Integral.h:35
std::int8_t Int8
int8.
Definition Integral.h:30
MessageHeader::Version SchemaVersion
Aliases SBE-encoded data version type.
char Char
Character type alias.
Definition String.h:30
std::uint16_t UInt16
uInt16.
Definition Integral.h:33
UInt16 MessageSize
Message length type.
Definition Aliases.h:29
std::int32_t Int32
int32.
Definition Integral.h:34
std::basic_string_view< Char > StrRef
Definition StrRef.h:46
FloatingPointDecimal< DecimalMantissa, DecimalExponent > Decimal
Universal decimal type.
std::uint64_t UInt64
uInt64.
Definition Integral.h:37
std::uint8_t UInt8
uInt8.
Definition Integral.h:31
std::int16_t Int16
int16.
Definition Integral.h:32
MessageHeader::TemplateId MessageTemplateId
Message type (template) identification.
virtual Field field(const BinaryBlockBase &, Tag) const noexcept=0
virtual void setField(BinaryBlockBase &, Tag, const Field &) const =0
Sets a field value by its tag.
virtual void resetField(BinaryBlockBase &, Tag) const =0
Resets a field value by its tag.
virtual void reset(BinaryBlockBase &) const noexcept=0
Resets all variable-length and optional fields.
Timestamp getTimestamp(Tag tag) const
FieldSet & set(Tag tag, Int16 value)
FieldSet & set(Tag tag, const Field &field)
Definition Message.h:319
Enumeration::Enum getEnumeration(Tag tag) const
Definition Message.h:295
FieldSet & setField(Tag tag, const Field &field)
Definition Message.h:90
FieldSet & set(Tag tag, const MaturityMonthYear &value)
MaturityMonthYear getMaturityMonthYear(Tag tag) const
FieldSet(BinaryBlockBase &binary, const FieldAccessor *accessor) noexcept
Initializes the instance over the binary data.
Definition Message.h:476
FieldSet & set(Tag tag, UInt64 value)
Field operator[](Tag tag) const noexcept
Definition Message.h:128
FieldSet & set(Tag tag, UInt32 value)
FieldSet & set(Tag tag, Int32 value)
FieldSet & set(Tag tag, Char value)
FieldSet & set(Tag tag, Int64 value)
const FieldAccessor * accessor() const noexcept
Definition Message.h:483
FieldSet & set(Tag tag, Int8 value)
FieldSet & set(Tag tag, BitSet value, typename BitSet::Bits *=nullptr)
Definition Message.h:329
void setAccessor(const FieldAccessor *obj) noexcept
Sets the FieldAccessor.
Definition Message.h:489
FieldSet & set(Tag tag, Timestamp value)
FieldSet & set(Tag tag, StrRef value)
bool contain(Tag tag) const noexcept
FieldSet & set(Tag tag, UInt16 value)
FieldSet & set(Tag tag, UInt8 value)
Field field(Tag tag) const noexcept
Definition Message.h:79
FieldSet & set(Tag tag, const Decimal &value)
virtual StrRef type() const noexcept=0
virtual MessageSize calculateBinarySize(const SbeMessage &) const noexcept=0
virtual void toFix(std::string &, const SbeMessage &) const =0
virtual Group group(const SbeMessage &, Tag) const noexcept=0