9#include <initializer_list>
23 explicit constexpr CRC16(uint16_t initialCRC = 0xffff)
30 constexpr void init(uint16_t initialCRC)
35 constexpr void init(std::initializer_list<uint8_t> list)
38 for (
const auto& val : list) {
48 crc = uint16_t((crc << 8) ^ tab[0][(crc >> 8) ^ value]);
54 constexpr void update(std::span<const uint8_t> data)
69 while (data.size() >= 8) {
70 c = tab[7][data[0] ^ (c >> 8)] ^
71 tab[6][data[1] ^ (c & 255)] ^
78 data = data.subspan(8);
82 c = uint16_t(c << 8) ^ tab[0][(c >> 8) ^ d];
89 [[nodiscard]]
constexpr uint16_t
getValue()
const
95 static constexpr auto tab = [] {
96 std::array<std::array<uint16_t, 0x100>, 8> result = {};
97 for (
auto i :
xrange(0x100)) {
98 auto x = uint16_t(i << 8);
100 x = narrow_cast<uint16_t>((x << 1) ^ ((x & 0x8000) ? 0x1021 : 0));
104 for (
auto i :
xrange(0x100)) {
105 uint16_t c = result[0][i];
106 for (
auto j :
xrange(1, 8)) {
107 c = narrow_cast<uint16_t>(result[0][c >> 8] ^ (c << 8));
This class calculates CRC numbers for the polygon x^16 + x^12 + x^5 + 1.
constexpr void update(uint8_t value)
Update CRC with one byte.
constexpr uint16_t getValue() const
Get current CRC value.
constexpr void init(std::initializer_list< uint8_t > list)
constexpr CRC16(uint16_t initialCRC=0xffff)
Create CRC16 with an optional initial value.
constexpr void init(uint16_t initialCRC)
(Re)initialize the current value
constexpr void update(std::span< const uint8_t > data)
For large blocks (e.g.
This file implemented 3 utility functions:
constexpr void repeat(T n, Op op)
Repeat the given operation 'op' 'n' times.
constexpr auto xrange(T e)