A serializer for a simple binary format. More...
#include <di/serialization/binary_serializer.h>
Public Types | |
using | SerializationFormat = BinaryFormat |
Public Member Functions | |
template<concepts::NotDecaysTo< BinarySerializer > T> requires (ConstructibleFrom<Writer, T>) | |
constexpr | BinarySerializer (T &&writer) |
template<typename T, concepts::InstanceOf< reflection::Fields > M> | |
constexpr auto | serialize (T &&value, M) |
constexpr auto | serialize (concepts::TupleLike auto &&value) |
constexpr auto | serialize (concepts::VariantLike auto &&value) -> meta::WriterResult< void, Writer > |
template<concepts::IntegralOrEnum T> | |
constexpr auto | serialize (T value) |
template<typename T, concepts::InstanceOf< reflection::Atom > M> requires (M::is_string()) | |
constexpr auto | serialize (T &&value, M) |
template<concepts::SizedContainer T> requires (concepts::Serializable<meta::ContainerReference<T>, BinarySerializer>) | |
constexpr auto | serialize (T &&value) -> meta::WriterResult< void, Writer > |
constexpr auto | writer () &-> Writer & |
constexpr auto | writer () const &-> Writer const & |
constexpr auto | writer () &&-> Writer && |
A serializer for a simple binary format.
Writer | The type of the writer to write to. |
The binary format is a simple format. Integral and enum types are written as-is, but are converted to little endian first. Structure types are serialized by calling serialize
on each field. Tuple types are serialized by calling serialize
on each element. Variant types are serialized by writing the index of the active alternative and then calling serialize
on the active alternative. Container types are serialized by writing the size of the container and then calling serialize
on each element. Strings are just specializations of containers.
The format is not self-describing, so the deserializer must know the format of the data it is deserializing. This also means that it is not possible to add new fields to a structure without breaking backwards compatibility. If this is needed, the structure should be wrapped in a variant, which allows the variant index to act as the version number. Including a verson number directly in a structure is not enough since the size of the structure may change.
using di::serialization::BinarySerializer< Writer >::SerializationFormat = BinaryFormat |
|
inlineexplicitconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |
|
inlineconstexpr |