Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: make Endianness an enum class #44411

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/util.h
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