Support afd endpoint serialization

This commit is contained in:
momo5502
2024-11-17 09:23:45 +01:00
parent d05ccdd04c
commit a87bb85858
5 changed files with 124 additions and 17 deletions

View File

@@ -9,6 +9,9 @@
#include <functional>
#include <typeindex>
void serialize();
void deserialize();
namespace utils
{
class buffer_serializer;
@@ -57,6 +60,18 @@ namespace utils
: std::true_type
{
};
template <typename, typename = void>
struct has_construct_function : std::false_type
{
};
template <typename T>
struct has_construct_function<T, std::void_t<decltype(T::construct(
std::declval<buffer_deserializer&>()))>>
: std::bool_constant<std::is_same_v<decltype(T::construct(std::declval<buffer_deserializer&>())), T>>
{
};
}
class buffer_deserializer
@@ -291,7 +306,11 @@ namespace utils
template <typename T>
T construct_object()
{
if constexpr (std::is_default_constructible_v<T>)
if constexpr (detail::has_construct_function<T>::value)
{
return T::construct(*this);
}
else if constexpr (std::is_default_constructible_v<T>)
{
return {};
}