ORE Studio 0.0.4
Loading...
Searching...
No Matches
subscription_protocol.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_COMMS_MESSAGING_SUBSCRIPTION_PROTOCOL_HPP
21#define ORES_COMMS_MESSAGING_SUBSCRIPTION_PROTOCOL_HPP
22
23#include <span>
24#include <chrono>
25#include <iosfwd>
26#include <vector>
27#include <cstdint>
28#include <expected>
29#include <string>
30#include "ores.comms/messaging/message_types.hpp"
31#include "ores.comms/messaging/message_traits.hpp"
32#include "ores.eventing/domain/event_channel_info.hpp"
33
34namespace ores::comms::messaging {
35
42struct subscribe_request final {
48 std::string event_type;
49
57 std::vector<std::byte> serialize() const;
58
62 static std::expected<subscribe_request, ores::utility::serialization::error_code>
63 deserialize(std::span<const std::byte> data);
64};
65
66std::ostream& operator<<(std::ostream& s, const subscribe_request& v);
67
71struct subscribe_response final {
72 bool success;
73 std::string message;
74
83 std::vector<std::byte> serialize() const;
84
88 static std::expected<subscribe_response, ores::utility::serialization::error_code>
89 deserialize(std::span<const std::byte> data);
90};
91
92std::ostream& operator<<(std::ostream& s, const subscribe_response& v);
93
97struct unsubscribe_request final {
101 std::string event_type;
102
110 std::vector<std::byte> serialize() const;
111
115 static std::expected<unsubscribe_request, ores::utility::serialization::error_code>
116 deserialize(std::span<const std::byte> data);
117};
118
119std::ostream& operator<<(std::ostream& s, const unsubscribe_request& v);
120
125 bool success;
126 std::string message;
127
136 std::vector<std::byte> serialize() const;
137
141 static std::expected<unsubscribe_response, ores::utility::serialization::error_code>
142 deserialize(std::span<const std::byte> data);
143};
144
145std::ostream& operator<<(std::ostream& s, const unsubscribe_response& v);
146
157 std::string event_type;
158
164 std::chrono::system_clock::time_point timestamp;
165
173 std::vector<std::string> entity_ids;
174
187 std::vector<std::byte> serialize() const;
188
192 static std::expected<notification_message, ores::utility::serialization::error_code>
193 deserialize(std::span<const std::byte> data);
194};
195
196std::ostream& operator<<(std::ostream& s, const notification_message& v);
197
209
213 std::string error_message;
214
218 std::chrono::system_clock::time_point timestamp;
219
229 std::vector<std::byte> serialize() const;
230
234 static std::expected<database_status_message, ores::utility::serialization::error_code>
235 deserialize(std::span<const std::byte> data);
236};
237
238std::ostream& operator<<(std::ostream& s, const database_status_message& v);
239
252 std::vector<std::byte> serialize() const;
253
257 static std::expected<list_event_channels_request, ores::utility::serialization::error_code>
258 deserialize(std::span<const std::byte> data);
259};
260
261std::ostream& operator<<(std::ostream& s, const list_event_channels_request& v);
262
270 std::vector<eventing::domain::event_channel_info> channels;
271
283 std::vector<std::byte> serialize() const;
284
288 static std::expected<list_event_channels_response, ores::utility::serialization::error_code>
289 deserialize(std::span<const std::byte> data);
290};
291
292std::ostream& operator<<(std::ostream& s, const list_event_channels_response& v);
293
297template<>
301 static constexpr message_type request_message_type =
302 message_type::subscribe_request;
303};
304
308template<>
312 static constexpr message_type request_message_type =
313 message_type::unsubscribe_request;
314};
315
319template<>
323 static constexpr message_type request_message_type =
324 message_type::list_event_channels_request;
325};
326
327}
328
329#endif
Contains messaging related infrastructure in the comms library.
Definition assets_protocol.hpp:122
Traits template for mapping request types to their response types and message type enum values.
Definition message_traits.hpp:66
Request to subscribe to entity change notifications.
Definition subscription_protocol.hpp:42
static std::expected< subscribe_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition subscription_protocol.cpp:40
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition subscription_protocol.cpp:33
std::string event_type
The event type to subscribe to.
Definition subscription_protocol.hpp:48
Response confirming subscription request.
Definition subscription_protocol.hpp:71
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition subscription_protocol.cpp:56
static std::expected< subscribe_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition subscription_protocol.cpp:64
Request to unsubscribe from entity change notifications.
Definition subscription_protocol.hpp:97
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition subscription_protocol.cpp:85
std::string event_type
The event type to unsubscribe from.
Definition subscription_protocol.hpp:101
static std::expected< unsubscribe_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition subscription_protocol.cpp:92
Response confirming unsubscription request.
Definition subscription_protocol.hpp:124
static std::expected< unsubscribe_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition subscription_protocol.cpp:116
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition subscription_protocol.cpp:108
Server-initiated notification of an entity change.
Definition subscription_protocol.hpp:153
std::vector< std::byte > serialize() const
Serialize notification to bytes.
Definition subscription_protocol.cpp:137
std::string event_type
The event type that occurred.
Definition subscription_protocol.hpp:157
std::chrono::system_clock::time_point timestamp
Timestamp of when the change occurred (UTC).
Definition subscription_protocol.hpp:164
std::vector< std::string > entity_ids
Identifiers of entities that changed.
Definition subscription_protocol.hpp:173
static std::expected< notification_message, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize notification from bytes.
Definition subscription_protocol.cpp:156
Server-initiated notification of database status.
Definition subscription_protocol.hpp:204
static std::expected< database_status_message, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize notification from bytes.
Definition subscription_protocol.cpp:210
std::vector< std::byte > serialize() const
Serialize notification to bytes.
Definition subscription_protocol.cpp:196
std::chrono::system_clock::time_point timestamp
Timestamp of when the status was checked (UTC).
Definition subscription_protocol.hpp:218
bool available
Whether the database is available.
Definition subscription_protocol.hpp:208
std::string error_message
Error message if unavailable, empty otherwise.
Definition subscription_protocol.hpp:213
Request to list available event channels.
Definition subscription_protocol.hpp:246
static std::expected< list_event_channels_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition subscription_protocol.cpp:245
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition subscription_protocol.cpp:239
Response containing available event channels.
Definition subscription_protocol.hpp:266
std::vector< eventing::domain::event_channel_info > channels
List of available event channels.
Definition subscription_protocol.hpp:270
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition subscription_protocol.cpp:256
static std::expected< list_event_channels_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition subscription_protocol.cpp:272