23#include "pw_checksum/internal/config.h"
31#define PW_CHECKSUM_EMPTY_CRC32 ~_PW_CHECKSUM_CRC32_INITIAL_STATE
35#define _PW_CHECKSUM_CRC32_INITIAL_STATE 0xFFFFFFFFu
38uint32_t _pw_checksum_InternalCrc32EightBit(
const void* data,
42uint32_t _pw_checksum_InternalCrc32FourBit(
const void* data,
45uint32_t _pw_checksum_InternalCrc32OneBit(
const void* data,
49#if PW_CHECKSUM_CRC32_DEFAULT_IMPL == PW_CHECKSUM_CRC32_8BITS
50#define _pw_checksum_InternalCrc32 _pw_checksum_InternalCrc32EightBit
51#elif PW_CHECKSUM_CRC32_DEFAULT_IMPL == PW_CHECKSUM_CRC32_4BITS
52#define _pw_checksum_InternalCrc32 _pw_checksum_InternalCrc32FourBit
53#elif PW_CHECKSUM_CRC32_DEFAULT_IMPL == PW_CHECKSUM_CRC32_1BITS
54#define _pw_checksum_InternalCrc32 _pw_checksum_InternalCrc32OneBit
58static inline uint32_t pw_checksum_Crc32(
const void* data,
size_t size_bytes) {
59 return ~_pw_checksum_InternalCrc32(
60 data, size_bytes, _PW_CHECKSUM_CRC32_INITIAL_STATE);
65static inline uint32_t pw_checksum_Crc32Append(
const void* data,
67 uint32_t previous_result) {
71 return ~_pw_checksum_InternalCrc32(data, size_bytes, ~previous_result);
77#include "pw_span/span.h"
86template <u
int32_t (*kChecksumFunction)(const
void*,
size_t, u
int32_t)>
94 return ~kChecksumFunction(
95 data.data(), data.size_bytes(), _PW_CHECKSUM_CRC32_INITIAL_STATE);
98 constexpr Crc32Impl() : state_(kInitialValue) {}
102 state_ = kChecksumFunction(data.data(), data.size(), state_);
109 uint32_t
value()
const {
return ~state_; }
112 void clear() { state_ = kInitialValue; }
115 static constexpr uint32_t kInitialValue = _PW_CHECKSUM_CRC32_INITIAL_STATE;
static uint32_t Calculate(span< const std::byte > data)
Calculates the CRC32 for the provided data and returns it as a uint32_t.
Definition: crc32.h:93
void clear()
Resets the CRC to the initial value.
Definition: crc32.h:112
void Update(span< const std::byte > data)
Updates the CRC with the provided data.
Definition: crc32.h:101
uint32_t value() const
Returns the value of the CRC32 for all data passed to Update.
Definition: crc32.h:109
void Update(std::byte data)
Updates the CRC with the provided byte.
Definition: crc32.h:106
Definition: span_impl.h:235
Checksum calculation library.
Definition: crc16_ccitt.h:41