ORE Studio 0.0.4
Loading...
Searching...
No Matches
writer.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_UTILITY_SERIALIZATION_WRITER_HPP
21#define ORES_UTILITY_SERIALIZATION_WRITER_HPP
22
23#include <vector>
24#include <string>
25#include <cstdint>
26#include <boost/uuid/uuid.hpp>
27#include "ores.utility/uuid/tenant_id.hpp"
28
29namespace ores::utility::serialization {
30
37class writer {
38public:
42 static void write_uint8(std::vector<std::byte>& buffer, std::uint8_t value);
43
47 static void write_uint16(std::vector<std::byte>& buffer, std::uint16_t value);
48
52 static void write_uint32(std::vector<std::byte>& buffer, std::uint32_t value);
53
57 static void write_int64(std::vector<std::byte>& buffer, std::int64_t value);
58
62 static void write_uint64(std::vector<std::byte>& buffer, std::uint64_t value);
63
69 static void write_string(std::vector<std::byte>& buffer, const std::string& str);
70
76 static void write_string32(std::vector<std::byte>& buffer, const std::string& str);
77
81 static void write_bool(std::vector<std::byte>& buffer, bool value);
82
86 static void write_uuid(std::vector<std::byte>& buffer,
87 const boost::uuids::uuid& uuid);
88
94 static void write_tenant_id(std::vector<std::byte>& buffer,
95 const uuid::tenant_id& tenant_id);
96};
97
98}
99
100#endif
Helper class to write binary data in network byte order.
Definition writer.hpp:37
static void write_string(std::vector< std::byte > &buffer, const std::string &str)
Write a string with 16-bit length prefix.
Definition writer.cpp:64
static void write_string32(std::vector< std::byte > &buffer, const std::string &str)
Write a string with 32-bit length prefix.
Definition writer.cpp:73
static void write_tenant_id(std::vector< std::byte > &buffer, const uuid::tenant_id &tenant_id)
Write a tenant_id (16 bytes UUID).
Definition writer.cpp:93
static void write_uint32(std::vector< std::byte > &buffer, std::uint32_t value)
Write a 32-bit integer in network byte order.
Definition writer.cpp:35
static void write_uuid(std::vector< std::byte > &buffer, const boost::uuids::uuid &uuid)
Write a UUID (16 bytes).
Definition writer.cpp:82
static void write_bool(std::vector< std::byte > &buffer, bool value)
Write a boolean (1 byte).
Definition writer.cpp:89
static void write_uint8(std::vector< std::byte > &buffer, std::uint8_t value)
Write a single byte.
Definition writer.cpp:26
static void write_int64(std::vector< std::byte > &buffer, std::int64_t value)
Write a signed 64-bit integer in network byte order.
Definition writer.cpp:42
static void write_uint16(std::vector< std::byte > &buffer, std::uint16_t value)
Write a 16-bit integer in network byte order.
Definition writer.cpp:30
static void write_uint64(std::vector< std::byte > &buffer, std::uint64_t value)
Write an unsigned 64-bit integer in network byte order.
Definition writer.cpp:53
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66