Skip to content

Commit

Permalink
src: make Endianness an enum class
Browse files Browse the repository at this point in the history
PR-URL: #44411
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
tniessen authored and RafaelGSS committed Sep 6, 2022
1 parent 1e62bb1 commit 8db2e66
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 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() {
inline 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 8db2e66

Please sign in to comment.