30 lines
1.0 KiB
C++
30 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <cstdlib>
|
|
#include <cstdint>
|
|
|
|
namespace Feather
|
|
{
|
|
enum class Endian
|
|
{
|
|
Little,
|
|
Big
|
|
};
|
|
|
|
// TODO: Make this constexpr
|
|
inline uint8_t ReverseBytes(uint8_t n) { return n; }
|
|
#ifdef __GNUC__
|
|
inline uint16_t ReverseBytes(uint16_t n) { return __builtin_bswap16(n); }
|
|
inline uint32_t ReverseBytes(uint32_t n) { return __builtin_bswap32(n); }
|
|
inline uint64_t ReverseBytes(uint64_t n) { return __builtin_bswap64(n); }
|
|
#else
|
|
inline uint16_t ReverseBytes(uint16_t n) { return _byteswap_ushort(n); }
|
|
inline uint32_t ReverseBytes(uint32_t n) { return _byteswap_ulong (n); }
|
|
inline uint64_t ReverseBytes(uint64_t n) { return _byteswap_uint64(n); }
|
|
#endif
|
|
|
|
inline int8_t ReverseBytes(int8_t n) { return n; }
|
|
inline int16_t ReverseBytes(int16_t n) { return int16_t(ReverseBytes(uint16_t(n))); }
|
|
inline int32_t ReverseBytes(int32_t n) { return int32_t(ReverseBytes(uint32_t(n))); }
|
|
inline int64_t ReverseBytes(int64_t n) { return int64_t(ReverseBytes(uint64_t(n))); }
|
|
} |