seqeron 0.18.0
Loading...
Searching...
No Matches
Payload.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4
6#include "org_limitless_seqeron_sbe_frame/MessageHeader.h"
7
9
10class Payload;
11
17{
18 std::int32_t sourceId;
19 std::int32_t connectionId;
20 std::uint16_t groupMask;
21};
22
23namespace detail {
24template<typename Dispatch>
25class Session;
26
27Payload makePayload(const protocol::SequencedEvent& event);
28} // namespace detail
29
46{
47 public:
48 // Cluster-wide monotone sequence number; along this queue it increases, but not by one (spec F-6).
49 [[nodiscard]] std::int64_t clusterSeqNo() const noexcept
50 {
51 return m_event.clusterSeqNo;
52 }
53
54 // This frame's place on this instance's queue, increasing by exactly one per frame.
55 [[nodiscard]] std::int64_t groupSeqNo() const noexcept
56 {
57 return m_event.groupSeqNo;
58 }
59
60 // The producer that submitted this frame (spec §5).
61 [[nodiscard]] std::int32_t sourceId() const noexcept
62 {
63 return m_event.sourceId;
64 }
65
66 // The producer's connection this frame belongs to, or -1 for a producer-scoped one.
67 [[nodiscard]] std::int32_t connectionId() const noexcept
68 {
69 return m_event.connectionId;
70 }
71
72 // The groups whose queues carry it; a reply to it takes this mask (spec A-2, A-9).
73 [[nodiscard]] std::uint16_t groupMask() const noexcept
74 {
75 return m_event.groupMask;
76 }
77
78 // The address a later Application::reply takes; unlike this payload, it outlives the callback.
79 [[nodiscard]] ReplyAddress replyAddress() const noexcept
80 {
81 return { m_event.sourceId, m_event.connectionId, m_event.groupMask };
82 }
83
84 // The cluster session it was submitted on; a gateway pair shares its sourceId but not this.
85 [[nodiscard]] std::int64_t sourceSessionId() const noexcept
86 {
87 return m_event.sourceSessionId;
88 }
89
90 // The Raft consensus timestamp, identical on every node.
91 [[nodiscard]] std::int64_t clusterTimestampNs() const noexcept
92 {
93 return m_event.clusterTimestampNs;
94 }
95
96 // When this process read it — a delivery stamp, not the frame's.
97 [[nodiscard]] std::int64_t receiveTimeNs() const noexcept
98 {
99 return m_event.receiveTimeNs;
100 }
101
102 // Where this frame's first byte sits in the node's recording — a delivery stamp too, and what a
103 // consumer that replays that recording itself (a FIX gateway serving its own resend) anchors on.
104 [[nodiscard]] std::int64_t position() const noexcept
105 {
106 return m_event.position;
107 }
108
109 // Which protocol the body speaks (spec §13).
110 [[nodiscard]] std::uint16_t payloadId() const noexcept
111 {
112 return m_event.payloadId;
113 }
114
115 // The body's own template within that protocol.
116 [[nodiscard]] std::uint16_t templateId() const noexcept
117 {
118 return m_event.templateId;
119 }
120
121 // For the decoder's wrap, from the payload's own messageHeader.
122 [[nodiscard]] std::uint16_t blockLength() const noexcept
123 {
124 return m_event.blockLength;
125 }
126
127 // For the decoder's wrap, from the payload's own messageHeader.
128 [[nodiscard]] std::uint16_t version() const noexcept
129 {
130 return m_event.version;
131 }
132
133 // The payload's first byte: its own messageHeader included if it has one.
134 [[nodiscard]] const char* payload() const noexcept
135 {
136 return m_event.payload;
137 }
138
139 [[nodiscard]] std::uint64_t payloadLength() const noexcept
140 {
141 return m_event.payloadLength;
142 }
143
144 // Where the body starts: past the payload's own messageHeader, which is where a decoder wraps.
145 [[nodiscard]] const char* body() const noexcept
146 {
147 return m_event.payload + sbe::frame::MessageHeader::encodedLength();
148 }
149
150 [[nodiscard]] std::uint64_t bodyLength() const noexcept
151 {
152 return m_event.payloadLength - sbe::frame::MessageHeader::encodedLength();
153 }
154
155 // The payload's own decoder, wrapped past its messageHeader with the block length and version that
156 // header declares. The Java twin has no equivalent because a Java decoder's wrap() already takes the
157 // four accessors above in one call; here they would each have to be passed.
158 template<typename Decoder>
159 [[nodiscard]] Decoder decode() const
160 {
161 return protocol::decodeSequenced<Decoder>(m_event.payload, m_event.payloadLength, m_event.blockLength,
162 m_event.version);
163 }
164
165 private:
166 template<typename Dispatch>
167 friend class detail::Session;
169
170 explicit Payload(const protocol::SequencedEvent& event) : m_event{ event }
171 {}
172
173 const protocol::SequencedEvent& m_event;
174};
175
176namespace detail {
177
184inline Payload makePayload(const protocol::SequencedEvent& event)
185{
186 return Payload{ event };
187}
188
189} // namespace detail
190
191} // namespace org::limitless::seqeron::app
One application payload delivered in order, with the frame layer off it: the envelope is stripped,...
Definition Payload.hpp:46
std::int64_t sourceSessionId() const noexcept
Definition Payload.hpp:85
Decoder decode() const
Definition Payload.hpp:159
std::int32_t connectionId() const noexcept
Definition Payload.hpp:67
ReplyAddress replyAddress() const noexcept
Definition Payload.hpp:79
std::int64_t clusterSeqNo() const noexcept
Definition Payload.hpp:49
const char * body() const noexcept
Definition Payload.hpp:145
friend Payload detail::makePayload(const protocol::SequencedEvent &event)
std::int32_t sourceId() const noexcept
Definition Payload.hpp:61
std::int64_t clusterTimestampNs() const noexcept
Definition Payload.hpp:91
std::int64_t position() const noexcept
Definition Payload.hpp:104
friend class detail::Session
Definition Payload.hpp:167
std::uint16_t payloadId() const noexcept
Definition Payload.hpp:110
std::uint64_t payloadLength() const noexcept
Definition Payload.hpp:139
std::int64_t groupSeqNo() const noexcept
Definition Payload.hpp:55
std::uint64_t bodyLength() const noexcept
Definition Payload.hpp:150
std::int64_t receiveTimeNs() const noexcept
Definition Payload.hpp:97
std::uint16_t templateId() const noexcept
Definition Payload.hpp:116
std::uint16_t version() const noexcept
Definition Payload.hpp:128
std::uint16_t groupMask() const noexcept
Definition Payload.hpp:73
const char * payload() const noexcept
Definition Payload.hpp:134
std::uint16_t blockLength() const noexcept
Definition Payload.hpp:122
Definition ClusterError.hpp:5
What a reply needs of the request it answers: the requester's sourceId, connectionId and groupMask.
Definition Payload.hpp:17
std::int32_t sourceId
Definition Payload.hpp:18
std::uint16_t groupMask
Definition Payload.hpp:20
std::int32_t connectionId
Definition Payload.hpp:19
Carries one message from the cluster stream.
Definition SequencedFrame.hpp:175
std::uint16_t blockLength
payload messageHeader blockLength; 0 on a system frame (see decodeSystem)
Definition SequencedFrame.hpp:188
std::int32_t sourceId
Fixed constant identifying the submitting producer process (header.sourceId)
Definition SequencedFrame.hpp:178
std::uint16_t templateId
the message's messageHeader templateId; picks the specific decode
Definition SequencedFrame.hpp:187
std::int64_t sourceSessionId
Aeron Cluster client session id (header.sessionId)
Definition SequencedFrame.hpp:181
std::uint16_t version
payload messageHeader version; 0 on a system frame
Definition SequencedFrame.hpp:189
std::int64_t groupSeqNo
this frame's place on its queue: 1 for the first, then one per frame (F-6)
Definition SequencedFrame.hpp:177
std::uint64_t payloadLength
total byte count
Definition SequencedFrame.hpp:192
std::int64_t receiveTimeNs
wall-clock ns at receipt by this client
Definition SequencedFrame.hpp:183
std::int64_t clusterTimestampNs
cluster consensus time (epoch ns) when message was committed
Definition SequencedFrame.hpp:182
std::int64_t position
recording/stream position of this frame's first byte; pass to ReplayParams::position() to replay from...
Definition SequencedFrame.hpp:193
const char * payload
the payload's own bytes, its 8-byte messageHeader included; on a system frame, the message with no fr...
Definition SequencedFrame.hpp:190
std::uint16_t payloadId
which protocol templateId belongs to; 0 on a system frame
Definition SequencedFrame.hpp:185
std::int32_t connectionId
Connection id at that producer; routes the reply (header.connectionId)
Definition SequencedFrame.hpp:179
std::uint16_t groupMask
the groups whose queues carry it (header.groupMask); 0 on a system frame
Definition SequencedFrame.hpp:180
std::int64_t clusterSeqNo
Definition SequencedFrame.hpp:176