okser namespace

Namespaces

namespace in
namespace internal
namespace out

Classes

template<Input In>
struct input_context
template<Output Out>
struct output_context
struct parse_error
struct configuration
template<class T, configuration Config>
struct default_serializers
template<std::unsigned_integral T, configuration Config>
struct default_serializers<T, Config>
template<Serializer S, typename V>
struct serializable_value
template<class... Types>
class bundle
template<int Bytes, end Endianness = end::be>
struct sint

Enums

enum class error_type: uint8_t { not_enough_bytes, io_error, redundant_mismatch }
enum class end { le, be }

Typedefs

template<class T>
using result = std::expected<T, parse_error>
template<end Endianness = end::be>
using doublep = (Bytes==4||Bytes==8) struct floatp floatp<8, Endianness>

Functions

template<class Bundle, Output Out, typename... Values>
void serialize(Out&& output, Values... values) constexpr
template<Deserializer Type, typename Value = typename Type::DefaultType, class In>
auto deserialize(In&& input) -> result<Value> constexpr
template<Deserializer... Types, class... Values, std::derived_from<std::tuple<Values...>> Tuple = std::tuple<Values...>, class In>
requires(sizeof...Values = =sizeof...(Types) && sizeof...(Types), 1)
template<Serializer... Types, typename... Values>
auto simple_serialize(Values... values) -> std::string
template<class T, Output Out, auto config = internal::empty{}>
void serialize_struct(Out&& output, const T& object) constexpr
template<class T, auto config = internal::empty{}>
auto serialize_struct_to_string(const T& object) -> std::string constexpr
template<class T, class In, auto config = internal::empty{}>
auto deserialize_struct(In&& input) -> T constexpr
template<class T, int N>
requires(N>= 1) class redundant

Variables

template<typename T>
concept Output
template<typename T>
concept Input
template<typename T>
concept Serializer
template<typename T>
concept Deserializer
template<typename T>
concept InputContext
template<typename T>
concept OutputContext

Enum documentation

enum class okser::error_type: uint8_t

enum class okser::end

Enum to represent endianness

However, the user can specify the endianness of the serialized data at compile-time. Big endianness is used conventionally by default.

Enumerators
le

Little endian.

be

Big endian.

Typedef documentation

template<class T>
using okser::result = std::expected<T, parse_error>

template<end Endianness = end::be>
using okser::doublep = (Bytes==4||Bytes==8) struct floatp floatp<8, Endianness>

Template parameters
Endianness Shortcut to a double-precision floating point number

IEEE 754 floating point number

Function documentation

template<class Bundle, Output Out, typename... Values>
void okser::serialize(Out&& output, Values... values) constexpr

Template parameters
Bundle The bundle containing each element of the serialized structure.
Out
Values The types of the values to serialize. These do not need to match the Bundle.
Parameters
output The output to append to at runtime.
values The values to serialize. This needs to match the number and order of Values.

Take some values, serialize them using a bundle, and append them to an output

Example
using bundle = okser::bundle<okser::sint<1>, okser::uint<2>>;
okser::serialize<bundle>(output, 100, 50000);

template<Deserializer Type, typename Value = typename Type::DefaultType, class In>
result<Value> okser::deserialize(In&& input) constexpr

Shortcut to okser::serialize without the need to declare a bundle.

Example
okser::serialize<okser::sint<1>, okser::uint<2>>(output, 100, 50000);

template<Deserializer... Types, class... Values, std::derived_from<std::tuple<Values...>> Tuple = std::tuple<Values...>, class In>
okser::requires(sizeof...Values = =sizeof...(Types) && sizeof...(Types), 1)

template<Serializer... Types, typename... Values>
std::string okser::simple_serialize(Values... values)

Shortcut to okser::serialize that directly produces an std::string.

Example
std::string out = okser::simple_serialize<
    okser::sint<1>,
    okser::uint<2>
>(-5, 15);

template<class T, Output Out, auto config = internal::empty{}>
void okser::serialize_struct(Out&& output, const T& object) constexpr

template<class T, auto config = internal::empty{}>
std::string okser::serialize_struct_to_string(const T& object) constexpr

template<class T, class In, auto config = internal::empty{}>
T okser::deserialize_struct(In&& input) constexpr

template<class T, int N>
okser::requires(N>= 1) class redundant

Variable documentation

template<typename T>
concept okser::Output

A concept to check if a class can be used as an okser output.

template<typename T>
concept okser::Input

A concept to check if a class can be used as an okser input.

template<typename T>
concept okser::Serializer

A concept to check if a class can be used as an okser serializer and serialise values to binaries.

By default, every child of the okser::internal::type class satisfies this concept. For any custom user-provided serializable types, you can derive your type from okser::internal::type, or use a template specialization as follows:

template<>
constexpr inline bool is_serializer<MySerializer> = true;

template<typename T>
concept okser::Deserializer

A concept to check if a class can be used as an okser deserializer, and deserialise values from binaries.

template<typename T>
concept okser::InputContext

A concept to check if a class can be used as an okser input context.

An input context needs to contain at least an okser::Input. Useful for de-serializing.

template<typename T>
concept okser::OutputContext

A concept to check if a class can be used as an okser output context.

An output context needs to contain at least an okser::Output. Useful for serializing.