10#include "concepts.hpp"
39template<numeric_
integral T>
41 [[nodiscard]]
datum encode(T
const &rhs)
const noexcept
48 if (
auto *i = get_if<long long>(rhs)) {
50 throw parse_error(
"Encoded value is to out of range, got {}", rhs);
52 return static_cast<T
>(*i);
54 throw parse_error(
"Expecting numeric integrals to be encoded as a long long, got {}", rhs);
59template<std::
floating_po
int T>
61 [[nodiscard]]
datum encode(T
const &rhs)
const noexcept
66 [[nodiscard]] T
decode(datum rhs)
const
68 if (
auto *f = get_if<double>(rhs)) {
69 return static_cast<T
>(*f);
71 }
else if (
auto *i = get_if<long long>(rhs)) {
72 return static_cast<T
>(*i);
75 throw parse_error(
"Expecting floating point to be encoded as a double or long long, got {}", rhs);
82 [[nodiscard]]
datum encode(
bool const &rhs)
const noexcept
89 if (
auto *b = get_if<bool>(rhs)) {
93 throw parse_error(
"Expecting bool to be encoded as a bool, got {}", rhs);
A dynamic data type.
Definition datum.hpp:213
Exception thrown during parsing on an error.
Definition exception.hpp:26
Encode and decode a type to and from a UTF-8 string.
Definition pickle.hpp:22
T decode(datum rhs) const
Decode a UTF-8 string into a value of a given type.
datum encode(T const &rhs) const noexcept
Encode the value of a type into a UTF-8 string.