| Index: src/utils.h
|
| diff --git a/src/utils.h b/src/utils.h
|
| index 93cded18bcd2f9c07dc9c29ec567bbc565bb3520..46dabfdeb323643b54d2c68cf9503f0559e8e317 100644
|
| --- a/src/utils.h
|
| +++ b/src/utils.h
|
| @@ -239,6 +239,46 @@ inline int StrLength(const char* string) {
|
| }
|
|
|
|
|
| +template <typename T>
|
| +inline void Swizzle(T* value) {
|
| + char* start = reinterpret_cast<char*>(value);
|
| + char* end = start + sizeof(*value) - 1;
|
| + while (start < end) {
|
| + char t = *start;
|
| + *start++ = *end;
|
| + *end-- = t;
|
| + }
|
| +}
|
| +
|
| +
|
| +enum Endianness {
|
| + kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
|
| + kBigEndian
|
| +};
|
| +
|
| +
|
| +inline enum Endianness GetEndianness() {
|
| + // Constant-folded by the compiler.
|
| + const union {
|
| + uint8_t u8[2];
|
| + uint16_t u16;
|
| + } u = {
|
| + { 1, 0 }
|
| + };
|
| + return u.u16 == 1 ? kLittleEndian : kBigEndian;
|
| +}
|
| +
|
| +
|
| +inline bool IsLittleEndian() {
|
| + return GetEndianness() == kLittleEndian;
|
| +}
|
| +
|
| +
|
| +inline bool IsBigEndian() {
|
| + return GetEndianness() == kBigEndian;
|
| +}
|
| +
|
| +
|
| // ----------------------------------------------------------------------------
|
| // BitField is a help template for encoding and decode bitfield with
|
| // unsigned content.
|
|
|