20#ifndef ORES_UTILITY_RFL_REFLECTORS_HPP
21#define ORES_UTILITY_RFL_REFLECTORS_HPP
29#include <boost/uuid/uuid.hpp>
30#include <boost/uuid/uuid_io.hpp>
31#include <boost/lexical_cast.hpp>
32#include <boost/asio/ip/address.hpp>
34#include "ores.utility/uuid/tenant_id.hpp"
39namespace ores::utility::serialization {
42namespace ores::comms::messaging {
43 enum class compression_type : std::uint8_t;
44 enum class message_type : std::uint16_t;
55struct Reflector<boost::uuids::uuid> {
56 using ReflType = std::string;
58 static boost::uuids::uuid to(
const ReflType& str) {
59 return boost::lexical_cast<boost::uuids::uuid>(str);
62 static ReflType from(
const boost::uuids::uuid& v) {
63 return boost::lexical_cast<std::string>(v);
73struct Reflector<
ores::utility::uuid::tenant_id> {
74 using ReflType = std::string;
79 throw std::runtime_error(
"Invalid tenant_id: " + result.error());
96struct Reflector<
std::optional<boost::uuids::uuid>> {
97 using ReflType = std::optional<std::string>;
99 static std::optional<boost::uuids::uuid> to(
const ReflType& str) {
100 if (!str.has_value()) {
103 return boost::lexical_cast<boost::uuids::uuid>(str.value());
106 static ReflType from(
const std::optional<boost::uuids::uuid>& v) {
107 if (!v.has_value()) {
110 return boost::lexical_cast<std::string>(v.value());
125struct Reflector<
std::chrono::system_clock::time_point> {
126 using ReflType = std::string;
136 static std::chrono::system_clock::time_point
to(
const ReflType& str) {
139 std::istringstream ss(str);
140 ss >> std::get_time(&tm,
"%Y-%m-%d %H:%M:%S");
142 auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
153 static ReflType
from(
const std::chrono::system_clock::time_point& v) {
159 return std::format(
"{:%F %T}Z", v);
169struct Reflector<boost::asio::ip::address> {
170 using ReflType = std::string;
172 static boost::asio::ip::address to(
const ReflType& str) {
173 return boost::asio::ip::make_address(str);
176 static ReflType from(
const boost::asio::ip::address& v) {
177 return v.to_string();
188struct Reflector<
ores::comms::messaging::compression_type> {
189 using ReflType = std::uint8_t;
191 static ores::comms::messaging::compression_type to(
const ReflType& v) {
194 throw std::runtime_error(
"Invalid value for compression_type enum: " +
197 return static_cast<ores::comms::messaging::compression_type
>(v);
200 static ReflType from(
const ores::comms::messaging::compression_type& v) {
201 return static_cast<ReflType
>(v);
212struct Reflector<
ores::utility::serialization::error_code> {
213 using ReflType = std::uint16_t;
215 static ores::utility::serialization::error_code to(
const ReflType& v) {
218 throw std::runtime_error(
"Invalid value for error_code enum: " +
221 return static_cast<ores::utility::serialization::error_code
>(v);
224 static ReflType from(
const ores::utility::serialization::error_code& v) {
225 return static_cast<ReflType
>(v);
236struct Reflector<
ores::comms::messaging::message_type> {
237 using ReflType = std::uint16_t;
239 static ores::comms::messaging::message_type to(
const ReflType& v) {
242 if (v == 0 || v > 0x5FFF) {
243 throw std::runtime_error(
"Invalid value for message_type enum: " +
246 return static_cast<ores::comms::messaging::message_type
>(v);
249 static ReflType from(
const ores::comms::messaging::message_type& v) {
250 return static_cast<ReflType
>(v);
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition image.hpp:29
error_code
Error codes returned by service-layer request helpers.
Definition error_code.hpp:28
static std::chrono::system_clock::time_point to(const ReflType &str)
Parses a string into a time_point.
Definition reflectors.hpp:136
static ReflType from(const std::chrono::system_clock::time_point &v)
Formats a time_point into a string.
Definition reflectors.hpp:153
A strongly-typed wrapper around a UUID representing a tenant identifier.
Definition tenant_id.hpp:66
std::string to_string() const
Converts the tenant_id to its string representation.
Definition tenant_id.cpp:81
static std::expected< tenant_id, std::string > from_string(std::string_view str)
Creates a tenant_id from a string representation.
Definition tenant_id.cpp:57