36 BBEndianness globalEndian = BB_LE;
37 BBEndianness hostEndian = BB_LE;
42 void detectHostEndian();
43 BBEndianness getHostEndian() {
return hostEndian; }
45 static uint32_t readPackedInt(uint32_t packed, uint32_t &output);
46 static uint32_t writePackedInt(uint32_t integer, uint32_t &output);
48 void setGlobalEndianness(BBEndianness end) { globalEndian = end; }
53 T toGlobal(T in, BBEndianness end) {
55 if (end == globalEndian) {
63 std::size_t bytesize =
sizeof(in);
64 #if defined(__GNUC__) || defined(__MINGW32__) || defined(__MINGW64__)
66 return __builtin_bswap16(in);
68 else if (bytesize == 4) {
69 return __builtin_bswap32(in);
71 else if (bytesize == 8) {
72 return __builtin_bswap64(in);
74 #elif defined(_MSC_VER)
76 return _byteswap_ushort(in);
78 else if (bytesize == 4) {
79 return _byteswap_ulong(in);
81 else if (bytesize == 8) {
82 return _byteswap_uint64(in);
94 T toHost(T in, BBEndianness end) {
98 if (end == hostEndian) {
106 std::size_t bytesize =
sizeof(in);
107 #if defined(__GNUC__) || defined(__MINGW32__) || defined(__MINGW64__)
109 return __builtin_bswap16(in);
111 else if (bytesize == 4) {
112 return __builtin_bswap32(in);
114 else if (bytesize == 8) {
115 return __builtin_bswap64(in);
117 #elif defined(_MSC_VER)
119 return _byteswap_ushort(in);
121 else if (bytesize == 4) {
122 return _byteswap_ulong(in);
124 else if (bytesize == 8) {
125 return _byteswap_uint64(in);
Definition: bytebauble.h:35