diff --git a/include/duckhandy/endianness.hpp b/include/duckhandy/endianness.hpp index 0da8d0c..4e704a9 100644 --- a/include/duckhandy/endianness.hpp +++ b/include/duckhandy/endianness.hpp @@ -93,6 +93,28 @@ namespace dhandy { return static_cast(__builtin_bswap64(static_cast(parV))); #else # error "Unsupported endianness" +#endif + } + template <> + [[gnu::pure]] inline constexpr long long int htobe (long long int parV) { + static_assert(sizeof(long long int) == sizeof(uint64_t), "Size mismatch"); +#if __BYTE_ORDER == __BIG_ENDIAN + return parV; +#elif __BYTE_ORDER == __LITTLE_ENDIAN + return static_cast(__builtin_bswap64(static_cast(parV))); +#else +# error "Unsupported endianness" +#endif + } + template <> + [[gnu::pure]] inline constexpr unsigned long long int htobe (unsigned long long int parV) { + static_assert(sizeof(unsigned long long int) == sizeof(uint64_t), "Size mismatch"); +#if __BYTE_ORDER == __BIG_ENDIAN + return parV; +#elif __BYTE_ORDER == __LITTLE_ENDIAN + return static_cast(__builtin_bswap64(static_cast(parV))); +#else +# error "Unsupported endianness" #endif } @@ -162,6 +184,28 @@ namespace dhandy { return parV; #else # error "Unsupported endianness" +#endif + } + template <> + [[gnu::pure]] inline constexpr long long int htole (long long int parV) { + static_assert(sizeof(long long int) == sizeof(uint64_t), "Size mismatch"); +#if __BYTE_ORDER == __BIG_ENDIAN + return static_cast(__builtin_bswap64(static_cast(parV))); +#elif __BYTE_ORDER == __LITTLE_ENDIAN + return parV; +#else +# error "Unsupported endianness" +#endif + } + template <> + [[gnu::pure]] inline constexpr unsigned long long int htole (unsigned long long int parV) { + static_assert(sizeof(unsigned long long int) == sizeof(uint64_t), "Size mismatch"); +#if __BYTE_ORDER == __BIG_ENDIAN + return static_cast(__builtin_bswap64(static_cast(parV))); +#elif __BYTE_ORDER == __LITTLE_ENDIAN + return parV; +#else +# error "Unsupported endianness" #endif }