1. Rename `CelGetFrameStart` to `CelGetFrame`, in line with the other 2 functions with the same name and load the `uint32_t` safely. 2. Remove redundant `FrameHeader`, simply use `LoadLE16`. 3. Document all the functions.
31 lines
1 KiB
C++
31 lines
1 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
namespace devilution {
|
|
|
|
template <typename T>
|
|
constexpr std::uint16_t LoadLE16(const T *b)
|
|
{
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
|
return (static_cast<std::uint16_t>(b[1]) << 8) | static_cast<std::uint16_t>(b[0]);
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr std::uint32_t LoadLE32(const T *b)
|
|
{
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
|
return (static_cast<std::uint32_t>(b[3]) << 24) | (static_cast<std::uint32_t>(b[2]) << 16) | (static_cast<std::uint32_t>(b[1]) << 8) | static_cast<std::uint32_t>(b[0]);
|
|
}
|
|
|
|
template <typename T>
|
|
constexpr std::uint32_t LoadBE32(const T *b)
|
|
{
|
|
static_assert(sizeof(T) == 1, "invalid argument");
|
|
// NOLINTNEXTLINE(readability-magic-numbers)
|
|
return (static_cast<std::uint32_t>(b[0]) << 24) | (static_cast<std::uint32_t>(b[1]) << 16) | (static_cast<std::uint32_t>(b[2]) << 8) | static_cast<std::uint32_t>(b[3]);
|
|
}
|
|
|
|
} // namespace devilution
|