17#ifndef TOOLBOX_NET_ENDIAN_HPP
18#define TOOLBOX_NET_ENDIAN_HPP
27constexpr std::uint16_t
bswap(std::uint16_t
n)
noexcept
29 return (
n << 8) | (
n >> 8);
32constexpr std::int16_t
bswap(std::int16_t
n)
noexcept
34 return bswap(
static_cast<std::uint16_t
>(
n));
37constexpr std::uint32_t
bswap(std::uint32_t
n)
noexcept
39 return (
n >> 24) | ((
n >> 8) & 0xff00) | ((
n << 8) & 0xff0000) | (
n << 24);
42constexpr std::int32_t
bswap(std::int32_t
n)
noexcept
44 return bswap(
static_cast<std::uint32_t
>(
n));
47constexpr std::uint64_t
bswap(std::uint64_t
n)
noexcept
49 const auto hi = std::uint64_t{
bswap(
static_cast<std::uint32_t
>(
n))} << 32;
50 return hi |
bswap(
static_cast<std::uint32_t
>(
n >> 32));
53constexpr std::int64_t
bswap(std::int64_t
n)
noexcept
55 return bswap(
static_cast<std::uint64_t
>(
n));
58template <
typename ValueT>
59 requires std::integral<ValueT>
62 if constexpr (std::endian::native == std::endian::little) {
69template <
typename ValueT>
70 requires std::integral<ValueT>
73 if constexpr (std::endian::native == std::endian::little) {
80template <
typename ValueT>
81 requires std::integral<ValueT>
84 if constexpr (std::endian::native == std::endian::little) {
91template <
typename ValueT>
92 requires std::integral<ValueT>
95 if constexpr (std::endian::native == std::endian::little) {
102static_assert(std::endian::native == std::endian::little || std::endian::native == std::endian::big,
103 "Mixed endianness platforms are not supported");