#pragma once
#include
#include
#include
#include
#include
namespace DB
{
template
requires std::is_integral_v
inline void transformEndianness(T & value)
{
if constexpr (ToEndian != FromEndian)
value = std::byteswap(value);
}
template
requires is_big_int_v
inline void transformEndianness(T & x)
{
if constexpr (ToEndian != FromEndian)
{
auto & items = x.items;
std::transform(std::begin(items), std::end(items), std::begin(items), [](auto & item) { return std::byteswap(item); });
std::reverse(std::begin(items), std::end(items));
}
}
template
requires is_decimal
inline void transformEndianness(T & x)
{
transformEndianness(x.value);
}
template
requires std::is_floating_point_v
inline void transformEndianness(T & value)
{
if constexpr (ToEndian != FromEndian)
{
auto * start = reinterpret_cast(&value);
std::reverse(start, start + sizeof(T));
}
}
template
requires std::is_enum_v || std::is_scoped_enum_v
inline void transformEndianness(T & x)
{
using UnderlyingType = std::underlying_type_t;
transformEndianness(reinterpret_cast(x));
}
template
inline void transformEndianness(std::pair & pair)
{
transformEndianness(pair.first);
transformEndianness(pair.second);
}
template
inline void transformEndianness(StrongTypedef & x)
{
transformEndianness(x.toUnderType());
}
template
inline void transformEndianness(CityHash_v1_0_2::uint128 & x)
{
transformEndianness(x.low64);
transformEndianness(x.high64);
}
}