ORE Studio 0.0.4
Loading...
Searching...
No Matches
assets_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_ASSETS_MESSAGING_ASSETS_PROTOCOL_HPP
21#define ORES_ASSETS_MESSAGING_ASSETS_PROTOCOL_HPP
22
23#include <span>
24#include <chrono>
25#include <iosfwd>
26#include <vector>
27#include <optional>
28#include <expected>
29#include "ores.comms/messaging/message_types.hpp"
30#include "ores.comms/messaging/message_traits.hpp"
31#include "ores.assets/domain/image.hpp"
32
34
38constexpr std::uint32_t MAX_IMAGES_PER_REQUEST = 100;
39
45struct get_images_request final {
46 std::vector<std::string> image_ids;
47
48 std::vector<std::byte> serialize() const;
49 static std::expected<get_images_request, ores::utility::serialization::error_code>
50 deserialize(std::span<const std::byte> data);
51};
52
53std::ostream& operator<<(std::ostream& s, const get_images_request& v);
54
58struct get_images_response final {
59 std::vector<domain::image> images;
60
61 std::vector<std::byte> serialize() const;
62 static std::expected<get_images_response, ores::utility::serialization::error_code>
63 deserialize(std::span<const std::byte> data);
64};
65
66std::ostream& operator<<(std::ostream& s, const get_images_response& v);
67
74struct list_images_request final {
81 std::optional<std::chrono::system_clock::time_point> modified_since;
82
83 std::vector<std::byte> serialize() const;
84 static std::expected<list_images_request, ores::utility::serialization::error_code>
85 deserialize(std::span<const std::byte> data);
86};
87
88std::ostream& operator<<(std::ostream& s, const list_images_request& v);
89
93struct image_info final {
94 std::string image_id;
95 std::string key;
96 std::string description;
102 std::chrono::system_clock::time_point recorded_at;
103};
104
105std::ostream& operator<<(std::ostream& s, const image_info& v);
106
111 std::vector<image_info> images;
112
113 std::vector<std::byte> serialize() const;
114 static std::expected<list_images_response, ores::utility::serialization::error_code>
115 deserialize(std::span<const std::byte> data);
116};
117
118std::ostream& operator<<(std::ostream& s, const list_images_response& v);
119
120}
121
123
127template<>
128struct message_traits<assets::messaging::get_images_request> {
131 static constexpr message_type request_message_type =
132 message_type::get_images_request;
133};
134
138template<>
139struct message_traits<assets::messaging::list_images_request> {
142 static constexpr message_type request_message_type =
143 message_type::list_images_request;
144};
145
146}
147
148#endif
Network messaging infrastructure for the assets module.
Definition assets_message_handler.hpp:28
constexpr std::uint32_t MAX_IMAGES_PER_REQUEST
Maximum number of images that can be requested in a single get_images_request.
Definition assets_protocol.hpp:38
Contains messaging related infrastructure in the comms library.
Definition assets_protocol.hpp:122
Request to retrieve images by their IDs.
Definition assets_protocol.hpp:45
Response containing requested images.
Definition assets_protocol.hpp:58
Request to list available images.
Definition assets_protocol.hpp:74
std::optional< std::chrono::system_clock::time_point > modified_since
Optional timestamp to filter images.
Definition assets_protocol.hpp:81
Metadata for an image (without SVG data).
Definition assets_protocol.hpp:93
std::chrono::system_clock::time_point recorded_at
Timestamp when this image was last modified.
Definition assets_protocol.hpp:102
Response containing metadata for all available images.
Definition assets_protocol.hpp:110
Traits template for mapping request types to their response types and message type enum values.
Definition message_traits.hpp:66