sandbox
Loading...
Searching...
No Matches
crc32.hpp
1
// SPDX-License-Identifier: MIT
2
#ifndef LIBSBX_UTILITY_CRC32_HPP_
3
#define LIBSBX_UTILITY_CRC32_HPP_
4
5
#include <cstdint>
6
7
#include <span>
8
#include <concepts>
9
10
namespace
sbx::utility {
11
12
auto
crc32(std::span<const std::uint8_t> buffer, std::uint32_t crc = 0xFFFFFFFFu) -> std::uint32_t;
13
14
template
<std::
unsigned
_
int
egral Type, std::
size_t
N>
15
requires
(
sizeof
(Type) == N - 1u)
16
static
consteval
auto
make_magic(
const
char
(&
string
)[N]) -> Type {
17
auto
result = Type{};
18
19
for
(
auto
i = 0u; i < N - 1u; ++i) {
20
result |=
static_cast<
Type
>
(
static_cast<
unsigned
char
>
(
string
[i])) << (i * 8u);
21
}
22
23
return
result;
24
}
25
26
}
// namespace sbx::utility
27
28
#endif
// LIBSBX_UTILITY_CRC32_HPP_
libsbx-utility
libsbx
utility
crc32.hpp
Generated by
1.9.5