RIT VEXU Core API
Loading...
Searching...
No Matches
crc32.hpp
1#pragma once
2#include <cstdint>
3
6class CRC32 {
7 public:
11 CRC32();
15 void reset();
20 void update(const uint8_t &data);
26 template <typename Type> void update(const Type &data) { update(&data, 1); }
33 template <typename Type> void update(const Type *data, std::size_t size) {
34 std::size_t nBytes = size * sizeof(Type);
35 const uint8_t *pData = (const uint8_t *)data;
36
37 for (std::size_t i = 0; i < nBytes; i++) {
38 update(pData[i]);
39 }
40 }
41
44 uint32_t finalize() const;
52 template <typename Type> static uint32_t calculate(const Type *data, std::size_t size) {
53 CRC32 crc;
54 crc.update(data, size);
55 return crc.finalize();
56 }
57
58 private:
62 uint32_t _state = ~0L;
63};
static uint32_t calculate(const Type *data, std::size_t size)
Calculate the checksum of an arbitrary data array.
Definition crc32.hpp:52
CRC32()
Initialize an empty CRC32 checksum.
Definition crc32.cpp:9
void update(const Type &data)
Update the current checksum caclulation with the given data.
Definition crc32.hpp:26
void reset()
Reset the checksum claculation.
Definition crc32.cpp:11
void update(const uint8_t &data)
Update the current checksum caclulation with the given data.
Definition crc32.cpp:13
void update(const Type *data, std::size_t size)
Update the current checksum caclulation with the given data.
Definition crc32.hpp:33
uint32_t finalize() const
Definition crc32.cpp:23