Skip to content

Commit

Permalink
src: make Endianness an enum class
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Aug 27, 2022
1 parent a5d27f4 commit f8e3dbb
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,26 +751,23 @@ inline v8::MaybeLocal<v8::Value> ToV8Value(v8::Local<v8::Context> context,
.Check(); \
} while (0)

enum Endianness {
kLittleEndian, // _Not_ LITTLE_ENDIAN, clashes with endian.h.
kBigEndian
};
enum class Endianness { LITTLE, BIG };

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;
return u.u16 == 1 ? Endianness::LITTLE : Endianness::BIG;
}

inline bool IsLittleEndian() {
return GetEndianness() == kLittleEndian;
return GetEndianness() == Endianness::LITTLE;
}

inline bool IsBigEndian() {
return GetEndianness() == kBigEndian;
return GetEndianness() == Endianness::BIG;
}

// Round up a to the next highest multiple of b.
Expand Down

0 comments on commit f8e3dbb

Please sign in to comment.