You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
|
5 years ago
|
#pragma once
|
||
|
|
|
||
|
|
#include <cstdint>
|
||
|
|
|
||
|
|
namespace devilution {
|
||
|
|
|
||
|
5 years ago
|
template <typename T>
|
||
|
4 years ago
|
constexpr uint16_t LoadLE16(const T *b)
|
||
|
5 years ago
|
{
|
||
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
||
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
||
|
4 years ago
|
return (static_cast<uint8_t>(b[1]) << 8) | static_cast<uint8_t>(b[0]);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
3 years ago
|
template <typename T>
|
||
|
|
constexpr uint16_t LoadBE16(const T *b)
|
||
|
|
{
|
||
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
||
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
||
|
|
return (static_cast<uint8_t>(b[0]) << 8) | static_cast<uint8_t>(b[1]);
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
template <typename T>
|
||
|
4 years ago
|
constexpr uint32_t LoadLE32(const T *b)
|
||
|
5 years ago
|
{
|
||
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
||
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
||
|
4 years ago
|
return (static_cast<uint8_t>(b[3]) << 24) | (static_cast<uint8_t>(b[2]) << 16) | (static_cast<uint8_t>(b[1]) << 8) | static_cast<uint8_t>(b[0]);
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
template <typename T>
|
||
|
4 years ago
|
constexpr uint32_t LoadBE32(const T *b)
|
||
|
5 years ago
|
{
|
||
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
||
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
||
|
4 years ago
|
return (static_cast<uint8_t>(b[0]) << 24) | (static_cast<uint8_t>(b[1]) << 16) | (static_cast<uint8_t>(b[2]) << 8) | static_cast<uint8_t>(b[3]);
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
} // namespace devilution
|