#pragma once #include #include #include #include #include namespace floormat::Serialize { static_assert(std::endian::native == std::endian::big || std::endian::native == std::endian::little); template struct make_integer; template using make_integer_t = typename make_integer::type; #define FM_SERIALIZE_MAKE_INTEGER(T) template<> struct make_integer { using type = T; } FM_SERIALIZE_MAKE_INTEGER(std::uint8_t); FM_SERIALIZE_MAKE_INTEGER(std::uint16_t); FM_SERIALIZE_MAKE_INTEGER(std::uint32_t); FM_SERIALIZE_MAKE_INTEGER(std::uint64_t); #undef FN_SERIALIZE_MAKE_INTEGER template concept integer = requires(T x) { requires std::integral; requires sizeof(T) == sizeof(make_integer_t); }; template concept serializable = requires(T x) { requires std::same_as>; requires std::floating_point || integer; }; template constexpr inline T maybe_byteswap(T x) noexcept { return x; } template constexpr inline T maybe_byteswap(T x) noexcept { if constexpr(std::endian::native == std::endian::big) return std::byteswap(x); else return x; } } // namespace floormat::Serialize