ORE Studio 0.0.4
Loading...
Searching...
No Matches
country_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_REFDATA_MESSAGING_COUNTRY_PROTOCOL_HPP
21#define ORES_REFDATA_MESSAGING_COUNTRY_PROTOCOL_HPP
22
23#include <span>
24#include <iosfwd>
25#include <vector>
26#include <cstdint>
27#include <expected>
28#include <rfl.hpp>
29#include <rfl/json.hpp>
30#include "ores.comms/messaging/message_types.hpp"
31#include "ores.comms/messaging/message_traits.hpp"
32#include "ores.refdata/domain/country.hpp"
33
35
43 std::uint32_t offset = 0;
45 std::uint32_t limit = 100;
46
54 std::vector<std::byte> serialize() const;
55
59 static std::expected<get_countries_request, ores::utility::serialization::error_code>
60 deserialize(std::span<const std::byte> data);
61};
62
63std::ostream& operator<<(std::ostream& s, const get_countries_request& v);
64
69 std::vector<domain::country> countries;
71 std::uint32_t total_available_count = 0;
72
98 std::vector<std::byte> serialize() const;
99
103 static std::expected<get_countries_response, ores::utility::serialization::error_code>
104 deserialize(std::span<const std::byte> data);
105};
106
107std::ostream& operator<<(std::ostream& s, const get_countries_response& v);
108
117 domain::country country;
118
122 std::vector<std::byte> serialize() const;
123
127 static std::expected<save_country_request, ores::utility::serialization::error_code>
128 deserialize(std::span<const std::byte> data);
129};
130
131std::ostream& operator<<(std::ostream& s, const save_country_request& v);
132
137 bool success;
138 std::string message;
139
143 std::vector<std::byte> serialize() const;
144
148 static std::expected<save_country_response, ores::utility::serialization::error_code>
149 deserialize(std::span<const std::byte> data);
150};
151
152std::ostream& operator<<(std::ostream& s, const save_country_response& v);
153
161 std::vector<std::string> alpha2_codes;
162
172 std::vector<std::byte> serialize() const;
173
177 static std::expected<delete_country_request, ores::utility::serialization::error_code>
178 deserialize(std::span<const std::byte> data);
179};
180
181std::ostream& operator<<(std::ostream& s, const delete_country_request& v);
182
187 std::string alpha2_code;
188 bool success;
189 std::string message;
190};
191
192std::ostream& operator<<(std::ostream& s, const delete_country_result& v);
193
201 std::vector<delete_country_result> results;
202
215 std::vector<std::byte> serialize() const;
216
220 static std::expected<delete_country_response, ores::utility::serialization::error_code>
221 deserialize(std::span<const std::byte> data);
222};
223
224std::ostream& operator<<(std::ostream& s, const delete_country_response& v);
225
230 std::string alpha2_code;
231
235 std::vector<std::byte> serialize() const;
236
240 static std::expected<get_country_history_request, ores::utility::serialization::error_code>
241 deserialize(std::span<const std::byte> data);
242};
243
244std::ostream& operator<<(std::ostream& s, const get_country_history_request& v);
245
250 bool success;
251 std::string message;
252 std::vector<domain::country> history;
253
257 std::vector<std::byte> serialize() const;
258
262 static std::expected<get_country_history_response, ores::utility::serialization::error_code>
263 deserialize(std::span<const std::byte> data);
264};
265
266std::ostream& operator<<(std::ostream& s, const get_country_history_response& v);
267
268}
269
270namespace ores::comms::messaging {
271
275template<>
276struct message_traits<refdata::messaging::get_countries_request> {
279 static constexpr message_type request_message_type =
280 message_type::get_countries_request;
281};
282
286template<>
287struct message_traits<refdata::messaging::save_country_request> {
290 static constexpr message_type request_message_type =
291 message_type::save_country_request;
292};
293
297template<>
298struct message_traits<refdata::messaging::delete_country_request> {
301 static constexpr message_type request_message_type =
302 message_type::delete_country_request;
303};
304
308template<>
309struct message_traits<refdata::messaging::get_country_history_request> {
312 static constexpr message_type request_message_type =
313 message_type::get_country_history_request;
314};
315
316}
317
318#endif
Contains messaging related infrastructure in the comms library.
Definition assets_protocol.hpp:122
std::basic_ostream< CharT, TraitsT > & operator<<(std::basic_ostream< CharT, TraitsT > &stream, boost_severity level)
Inserter for boost_severity enum.
Definition boost_severity.hpp:80
Network messaging infrastructure for the risk module.
Definition country_protocol.hpp:34
Traits template for mapping request types to their response types and message type enum values.
Definition message_traits.hpp:66
Represents a country using ISO 3166-1 standard codes.
Definition country.hpp:33
Request to retrieve countries with pagination support.
Definition country_protocol.hpp:41
std::uint32_t limit
Maximum number of records to return.
Definition country_protocol.hpp:45
static std::expected< get_countries_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition country_protocol.cpp:131
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition country_protocol.cpp:123
std::uint32_t offset
Number of records to skip (0-based)
Definition country_protocol.hpp:43
Response containing countries with pagination metadata.
Definition country_protocol.hpp:68
static std::expected< get_countries_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition country_protocol.cpp:170
std::uint32_t total_available_count
Total number of countries available (not just in this page)
Definition country_protocol.hpp:71
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition country_protocol.cpp:152
Request to save a country (create or update).
Definition country_protocol.hpp:116
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition country_protocol.cpp:207
static std::expected< save_country_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition country_protocol.cpp:214
Response confirming country save operation.
Definition country_protocol.hpp:136
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition country_protocol.cpp:229
static std::expected< save_country_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition country_protocol.cpp:237
Request to delete one or more countries.
Definition country_protocol.hpp:160
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition country_protocol.cpp:262
static std::expected< delete_country_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition country_protocol.cpp:277
Result for a single country deletion.
Definition country_protocol.hpp:186
Response confirming country deletion(s).
Definition country_protocol.hpp:200
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition country_protocol.cpp:314
static std::expected< delete_country_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition country_protocol.cpp:331
Request to retrieve version history for a country.
Definition country_protocol.hpp:229
static std::expected< get_country_history_request, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize request from bytes.
Definition country_protocol.cpp:384
std::vector< std::byte > serialize() const
Serialize request to bytes.
Definition country_protocol.cpp:377
Response containing country version history.
Definition country_protocol.hpp:249
std::vector< std::byte > serialize() const
Serialize response to bytes.
Definition country_protocol.cpp:403
static std::expected< get_country_history_response, ores::utility::serialization::error_code > deserialize(std::span< const std::byte > data)
Deserialize response from bytes.
Definition country_protocol.cpp:421