cpp: Add load32/64 little-endian helpers
@@ -121,6 +121,14 @@ inline constexpr uint64_t load64be(const uint8_t* bytes) noexcept
(uint64_t{bytes[6]} << 8) | uint64_t{bytes[7]};
}
+/// Loads 64 bits / 8 bytes of data from the given @p bytes array in little-endian order.
+inline constexpr uint64_t load64le(const uint8_t* bytes) noexcept
+{
+ return uint64_t{bytes[0]} | (uint64_t{bytes[1]} << 8) | (uint64_t{bytes[2]} << 16) |
+ (uint64_t{bytes[3]} << 24) | (uint64_t{bytes[4]} << 32) | (uint64_t{bytes[5]} << 40) |
+ (uint64_t{bytes[6]} << 48) | (uint64_t{bytes[7]} << 56);
+}
+
/// Loads 32 bits / 4 bytes of data from the given @p bytes array in big-endian order.
inline constexpr uint32_t load32be(const uint8_t* bytes) noexcept
{
@@ -128,6 +136,13 @@ inline constexpr uint32_t load32be(const uint8_t* bytes) noexcept
uint32_t{bytes[3]};
}
+/// Loads 32 bits / 4 bytes of data from the given @p bytes array in little-endian order.
+inline constexpr uint32_t load32le(const uint8_t* bytes) noexcept
+{
+ return uint32_t{bytes[0]} | (uint32_t{bytes[1]} << 8) | (uint32_t{bytes[2]} << 16) |
+ (uint32_t{bytes[3]} << 24);
+}
+
namespace fnv
{
constexpr auto prime = 0x100000001b3; ///< The 64-bit FNV prime number.
