8#ifndef SEN_CORE_IO_DETAIL_SERIALIZATION_TRAITS_H
9#define SEN_CORE_IO_DETAIL_SERIALIZATION_TRAITS_H
30inline constexpr bool isPureIntegral = std::is_same_v<int8_t, T> || std::is_same_v<uint8_t, T> ||
31 std::is_same_v<int16_t, T> || std::is_same_v<uint16_t, T> ||
32 std::is_same_v<int32_t, T> || std::is_same_v<uint32_t, T> ||
33 std::is_same_v<int64_t, T> || std::is_same_v<uint64_t, T>;
39inline constexpr bool isNumeric =
40 isPureIntegral<T> || (std::is_floating_point_v<T> && std::numeric_limits<T>::is_iec559);
44inline constexpr bool isBasic = isNumeric<T> || std::is_same_v<char, T> || std::is_same_v<unsigned char, T>;
49inline constexpr bool allowsContiguousIO =
50 !std::is_same_v<T, bool> &&
51 (isBasic<T> || std::is_enum_v<T> || (std::is_trivially_copyable_v<T> && !std::is_class_v<T>)) &&
52 (hostIsLittleEndian() ||
sizeof(T) == 1U);
54static_assert(!allowsContiguousIO<std::vector<std::string>>);
55static_assert(!allowsContiguousIO<std::vector<bool>>);
58template <
typename T,
typename R>
59using IfBasic =
typename std::enable_if_t<isBasic<T>, R>;
62template <
typename T,
typename R>
63using IfEnum =
typename std::enable_if_t<std::is_enum_v<T>, R>;
66using BoolTransportType = uint8_t;
69template <
typename S,
typename T>
73 template <
typename SS,
typename TT>
74 static auto outputTest(
unsigned) ->
decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type());
76 template <
typename,
typename>
77 static auto outputTest(...) -> std::false_type;
79 template <
typename SS,
typename TT>
80 static auto inputTest(
unsigned) ->
decltype(std::declval<SS&>() >> std::declval<TT&>(), std::true_type());
82 template <
typename,
typename>
83 static auto inputTest(...) -> std::false_type;
86 static constexpr bool output =
decltype(outputTest<S, T>(0U))::value;
87 static constexpr bool input =
decltype(inputTest<S, T>(0U))::value;
90[[nodiscard]]
constexpr uint32_t getSerializedSize(
bool val)
noexcept
93 return sizeof(BoolTransportType);
97[[nodiscard]]
constexpr IfBasic<T, uint32_t> getSerializedSize(T val)
noexcept
104[[nodiscard]]
constexpr IfEnum<T, uint32_t> getSerializedSize(T val)
noexcept
106 return getSerializedSize(
static_cast<std::underlying_type_t<T>
>(val));
109[[nodiscard]]
inline uint32_t getSerializedSize(
const std::string& val)
noexcept
111 const auto size =
static_cast<uint32_t
>(val.size());
112 const auto sizeSize = getSerializedSize(size);
120 return sizeSize + size;
123[[nodiscard]]
constexpr uint32_t getSerializedSize(TimeStamp val)
noexcept
126 return getSerializedSize(int64_t {0});