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
32namespace ores::comms::messaging {
33
40struct subscribe_request final {
46 std::string event_type;
47
55 std::vector<std::byte> serialize() const;
56
60 static std::expected<subscribe_request, error_code>
61 deserialize(std::span<const std::byte> data);
62};
63
64std::ostream& operator<<(std::ostream& s, const subscribe_request& v);
65
69struct subscribe_response final {
70 bool success;
71 std::string message;
72
81 std::vector<std::byte> serialize() const;
82
86 static std::expected<subscribe_response, error_code>
87 deserialize(std::span<const std::byte> data);
88};
89
90std::ostream& operator<<(std::ostream& s, const subscribe_response& v);
91
95struct unsubscribe_request final {
99 std::string event_type;
100
108 std::vector<std::byte> serialize() const;
109
113 static std::expected<unsubscribe_request, error_code>
114 deserialize(std::span<const std::byte> data);
115};
116
117std::ostream& operator<<(std::ostream& s, const unsubscribe_request& v);
118
123 bool success;
124 std::string message;
125
134 std::vector<std::byte> serialize() const;
135
139 static std::expected<unsubscribe_response, error_code>
140 deserialize(std::span<const std::byte> data);
141};
142
143std::ostream& operator<<(std::ostream& s, const unsubscribe_response& v);
144
155 std::string event_type;
156
162 std::chrono::system_clock::time_point timestamp;
163
172 std::vector<std::byte> serialize() const;
173
177 static std::expected<notification_message, error_code>
178 deserialize(std::span<const std::byte> data);
179};
180
181std::ostream& operator<<(std::ostream& s, const notification_message& v);
182
194
198 std::string error_message;
199
203 std::chrono::system_clock::time_point timestamp;
204
214 std::vector<std::byte> serialize() const;
215
219 static std::expected<database_status_message, error_code>
220 deserialize(std::span<const std::byte> data);
221};
222
223std::ostream& operator<<(std::ostream& s, const database_status_message& v);
224
225}
226
227#endif
Contains messaging related infrastructure in the comms library.
Definition compression.hpp:29
Request to subscribe to entity change notifications.
Definition subscription_protocol.hpp:40
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition subscription_protocol.cpp:30
std::string event_type
The event type to subscribe to.
Definition subscription_protocol.hpp:46
static std::expected< subscribe_request, error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition subscription_protocol.cpp:37
Response confirming subscription request.
Definition subscription_protocol.hpp:69
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition subscription_protocol.cpp:53
static std::expected< subscribe_response, error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition subscription_protocol.cpp:61
Request to unsubscribe from entity change notifications.
Definition subscription_protocol.hpp:95
static std::expected< unsubscribe_request, error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition subscription_protocol.cpp:89
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition subscription_protocol.cpp:82
std::string event_type
The event type to unsubscribe from.
Definition subscription_protocol.hpp:99
Response confirming unsubscription request.
Definition subscription_protocol.hpp:122
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition subscription_protocol.cpp:105
static std::expected< unsubscribe_response, error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition subscription_protocol.cpp:113
Server-initiated notification of an entity change.
Definition subscription_protocol.hpp:151
std::vector< std::byte > serialize() const
Serialize notification to bytes.
Definition subscription_protocol.cpp:134
std::string event_type
The event type that occurred.
Definition subscription_protocol.hpp:155
std::chrono::system_clock::time_point timestamp
Timestamp of when the change occurred (UTC).
Definition subscription_protocol.hpp:162
static std::expected< notification_message, error_code > deserialize(std::span< const std::byte > data)
Deserialize notification from bytes.
Definition subscription_protocol.cpp:147
Server-initiated notification of database status.
Definition subscription_protocol.hpp:189
std::vector< std::byte > serialize() const
Serialize notification to bytes.
Definition subscription_protocol.cpp:171
std::chrono::system_clock::time_point timestamp
Timestamp of when the status was checked (UTC).
Definition subscription_protocol.hpp:203
bool available
Whether the database is available.
Definition subscription_protocol.hpp:193
std::string error_message
Error message if unavailable, empty otherwise.
Definition subscription_protocol.hpp:198
static std::expected< database_status_message, error_code > deserialize(std::span< const std::byte > data)
Deserialize notification from bytes.
Definition subscription_protocol.cpp:185