ORE Studio 0.0.4
Loading...
Searching...
No Matches
reader.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_READER_HPP
21#define ORES_COMMS_MESSAGING_READER_HPP
22
23#include <span>
24#include <vector>
25#include <string>
26#include <cstdint>
27#include <expected>
28#include <boost/uuid/uuid_io.hpp>
29#include "ores.comms/messaging/message_types.hpp"
30
31namespace ores::comms::messaging {
32
36class reader {
37public:
41 static std::expected<std::uint16_t, error_code>
42 read_uint16(std::span<const std::byte>& data);
43
47 static std::expected<std::uint32_t, error_code>
48 read_uint32(std::span<const std::byte>& data);
49
53 static std::expected<std::int64_t, error_code>
54 read_int64(std::span<const std::byte>& data);
55
59 static void write_uuid(std::vector<std::byte>& buffer,
60 const boost::uuids::uuid& uuid);
61
65 static std::expected<std::string, error_code>
66 read_string(std::span<const std::byte>& data);
67
71 static std::expected<boost::uuids::uuid, error_code>
72 read_uuid(std::span<const std::byte>& data);
73
77 static std::expected<bool, error_code>
78 read_bool(std::span<const std::byte>& data);
79};
80
81}
82
83#endif
Contains messaging related infrastructure in the comms library.
Definition compression.hpp:29
Helper to read network data.
Definition reader.hpp:36
static std::expected< boost::uuids::uuid, error_code > read_uuid(std::span< const std::byte > &data)
Helper to read a UUID (16 bytes).
Definition reader.cpp:83
static std::expected< std::uint16_t, error_code > read_uint16(std::span< const std::byte > &data)
Helper to read a 16-bit integer in network byte order.
Definition reader.cpp:27
static std::expected< std::uint32_t, error_code > read_uint32(std::span< const std::byte > &data)
Helper to read a 32-bit integer in network byte order.
Definition reader.cpp:38
static std::expected< bool, error_code > read_bool(std::span< const std::byte > &data)
Helper to read a boolean (1 byte).
Definition reader.cpp:99
static std::expected< std::int64_t, error_code > read_int64(std::span< const std::byte > &data)
Helper to read a 64-bit integer in network byte order.
Definition reader.cpp:51
static void write_uuid(std::vector< std::byte > &buffer, const boost::uuids::uuid &uuid)
Helper to write a UUID (16 bytes).
static std::expected< std::string, error_code > read_string(std::span< const std::byte > &data)
Helper to read a string with 16-bit length prefix.
Definition reader.cpp:68