20#ifndef ORES_UTILITY_RFL_REFLECTORS_HPP
21#define ORES_UTILITY_RFL_REFLECTORS_HPP
28#include <boost/uuid/uuid.hpp>
29#include <boost/uuid/uuid_io.hpp>
30#include <boost/lexical_cast.hpp>
31#include <boost/asio/ip/address.hpp>
37namespace ores::utility::serialization {
38 enum class error_code : std::uint16_t;
42 enum class message_type;
53struct Reflector<boost::uuids::uuid> {
54 using ReflType = std::string;
56 static boost::uuids::uuid to(
const ReflType& str) {
57 return boost::lexical_cast<boost::uuids::uuid>(str);
60 static ReflType from(
const boost::uuids::uuid& v) {
61 return boost::lexical_cast<std::string>(v);
76struct Reflector<
std::chrono::system_clock::time_point> {
77 using ReflType = std::string;
87 static std::chrono::system_clock::time_point
to(
const ReflType& str) {
90 std::istringstream ss(str);
91 ss >> std::get_time(&tm,
"%Y-%m-%d %H:%M:%S");
93 auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
104 static ReflType
from(
const std::chrono::system_clock::time_point& v) {
110 return std::format(
"{:%F %T}Z", v);
120struct Reflector<boost::asio::ip::address> {
121 using ReflType = std::string;
123 static boost::asio::ip::address to(
const ReflType& str) {
124 return boost::asio::ip::make_address(str);
127 static ReflType from(
const boost::asio::ip::address& v) {
128 return v.to_string();
139struct Reflector<
ores::comms::messaging::compression_type> {
140 using ReflType = std::uint8_t;
145 throw std::runtime_error(
"Invalid value for compression_type enum: " +
152 return static_cast<ReflType
>(v);
163struct Reflector<
ores::utility::serialization::error_code> {
164 using ReflType = std::uint16_t;
166 static ores::utility::serialization::error_code to(
const ReflType& v) {
169 throw std::runtime_error(
"Invalid value for error_code enum: " +
172 return static_cast<ores::utility::serialization::error_code
>(v);
175 static ReflType from(
const ores::utility::serialization::error_code& v) {
176 return static_cast<ReflType
>(v);
187struct Reflector<
ores::comms::messaging::message_type> {
188 using ReflType = std::uint16_t;
190 static ores::comms::messaging::message_type to(
const ReflType& v) {
193 if (v == 0 || v > 0x5FFF) {
194 throw std::runtime_error(
"Invalid value for message_type enum: " +
197 return static_cast<ores::comms::messaging::message_type
>(v);
200 static ReflType from(
const ores::comms::messaging::message_type& v) {
201 return static_cast<ReflType
>(v);
ORE Studio - Graphical interface and data management for Open Source Risk Engine.
Definition image.hpp:27
Contains messaging related infrastructure in the comms library.
Definition assets_protocol.hpp:122
compression_type
Compression algorithm used for payload compression.
Definition message_types.hpp:259
static std::chrono::system_clock::time_point to(const ReflType &str)
Parses a string into a time_point.
Definition reflectors.hpp:87
static ReflType from(const std::chrono::system_clock::time_point &v)
Formats a time_point into a string.
Definition reflectors.hpp:104