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 <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
tniessen authored and targos committed Sep 16, 2022
1 parent e3103b4 commit a35b204
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 @@ -748,26 +748,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 a35b204

Please sign in to comment.