为什么80%的码农都做不了架构师?>>>
template T EndianScalar(T t) {#if FLATBUFFERS_LITTLEENDIANreturn t;#else#if defined(_MSC_VER)#pragma push_macro("__builtin_bswap16")#pragma push_macro("__builtin_bswap32")#pragma push_macro("__builtin_bswap64")#define __builtin_bswap16 _byteswap_ushort#define __builtin_bswap32 _byteswap_ulong#define __builtin_bswap64 _byteswap_uint64#endif// If you're on the few remaining big endian platforms, we make the bold// assumption you're also on gcc/clang, and thus have bswap intrinsics:if (sizeof(T) == 1) { // Compile-time if-then's.return t;} else if (sizeof(T) == 2) {auto r = __builtin_bswap16(*reinterpret_cast(&t));return *reinterpret_cast(&r);} else if (sizeof(T) == 4) {auto r = __builtin_bswap32(*reinterpret_cast(&t));return *reinterpret_cast(&r);} else if (sizeof(T) == 8) {auto r = __builtin_bswap64(*reinterpret_cast(&t));return *reinterpret_cast(&r);} else {assert(0);}#if defined(_MSC_VER)#pragma pop_macro("__builtin_bswap16")#pragma pop_macro("__builtin_bswap32")#pragma pop_macro("__builtin_bswap64")#endif#endif
}