#pragma once #ifdef _WIN32 #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include template static T byteSwap(T value) { if constexpr (sizeof(T) == 1) return value; else if constexpr (sizeof(T) == 2) return static_cast(__builtin_bswap16(static_cast(value))); else if constexpr (sizeof(T) == 4) return static_cast(__builtin_bswap32(static_cast(value))); else if constexpr (sizeof(T) == 8) return static_cast(__builtin_bswap64(static_cast(value))); assert(false && "Unexpected byte size."); return value; } template struct be { T value; T get() const { if constexpr (std::is_enum_v) return T(byteSwap(std::underlying_type_t(value))); else return byteSwap(value); } operator T() const { return get(); } };