3#include <StormByte/buffer/simple.hxx>
4#include <StormByte/exception.hxx>
5#include <StormByte/expected.hxx>
6#include <StormByte/type_traits.hxx>
26 using DecayedT = std::decay_t<T>;
72 if constexpr (std::is_trivially_copyable_v<T>) {
73 return SerializeTrivial();
75 return SerializeContainer();
77 return SerializePair();
79 return SerializeOptional();
81 return SerializeComplex();
91 if constexpr (std::is_trivially_copyable_v<T>) {
92 return DeserializeTrivial(
data);
94 return DeserializeContainer(
data);
96 return DeserializePair(
data);
98 return DeserializeOptional(
data);
100 return DeserializeComplex(
data);
104 static std::size_t Size(
const DecayedT&
data)
noexcept {
105 if constexpr (std::is_trivially_copyable_v<T>) {
107 }
else if constexpr (is_container<T>::value) {
108 return SizeContainer(
data);
109 }
else if constexpr (is_pair<T>::value) {
110 return SizePair(
data);
111 }
else if constexpr (is_optional<T>::value) {
112 return SizeOptional(
data);
114 return SizeComplex(
data);
119 const DecayedT& m_data;
127 return {
reinterpret_cast<const char*
>(&m_data),
sizeof(m_data) };
143 std::size_t
size = m_data.size();
146 for (
const auto&
element: m_data) {
172 if (m_data.has_value()) {
184 static std::size_t SizeComplex(
const DecayedT&
data)
noexcept;
191 static std::size_t SizeContainer(
const DecayedT&
data)
noexcept {
192 std::size_t
size =
sizeof(std::size_t);
204 static std::size_t SizePair(
const DecayedT&
data)
noexcept {
215 static std::size_t SizeOptional(
const DecayedT&
data)
noexcept {
217 if (
data.has_value()) {
255 for (std::size_t
i = 0;
i <
size; ++
i) {
271 using FirstT = std::decay_t<typename T::first_type>;
272 using SecondT = std::decay_t<typename T::second_type>;
A lightweight class for storing and manipulating simple byte buffers.
Definition simple.hxx:37
The class to serialize and deserialize data.
Definition serializable.hxx:25
Serializable(const DecayedT &data) noexcept
The constructor of the Serializable class.
Definition serializable.hxx:33
static StormByte::Expected< T, Buffer::BufferOverflow > Deserialize(const Buffer::Simple &data) noexcept
The function to deserialize the data.
Definition serializable.hxx:90
Serializable(const Serializable &other) noexcept=delete
The copy constructor of the Serializable class.
Serializable(Serializable &&other) noexcept=delete
The move constructor of the Serializable class.
Buffer::Simple Serialize() const noexcept
The function to serialize the data.
Definition serializable.hxx:71
~Serializable() noexcept=default
The destructor of the Serializable class.
Namespace for buffer-related components in the StormByte library.
Main namespace for the StormByte library.
auto Unexpected(std::shared_ptr< E > error_ptr)
Creates an std::unexpected with a shared pointer to the error.
Definition expected.hxx:43
std::conditional_t< is_reference< T >::value, std::expected< std::reference_wrapper< std::remove_reference_t< T > >, std::shared_ptr< E > >, std::expected< T, std::shared_ptr< E > > > Expected
Expected type with support for reference types.
Definition expected.hxx:32
Type trait to check if a type is a container.
Definition type_traits.hxx:21
Type trait to check if a type is an optional.
Definition type_traits.hxx:37
Type trait to check if a type is a pair.
Definition type_traits.hxx:54