RIT VEXU Core API
Loading...
Searching...
No Matches
crc32.hpp
1#pragma once
2#include <cstdint>
3#include <cstddef>
4
7class CRC32 {
8 public:
12 CRC32();
16 void reset();
21 void update(const uint8_t &data);
27 template <typename Type> void update(const Type &data) { update(&data, 1); }
34 template <typename Type> void update(const Type *data, std::size_t size) {
35 std::size_t nBytes = size * sizeof(Type);
36 const uint8_t *pData = (const uint8_t *)data;
37
38 for (std::size_t i = 0; i < nBytes; i++) {
39 update(pData[i]);
40 }
41 }
42
45 uint32_t finalize() const;
53 template <typename Type> static uint32_t calculate(const Type *data, std::size_t size) {
54 CRC32 crc;
55 crc.update(data, size);
56 return crc.finalize();
57 }
58
59 private:
63 uint32_t _state = ~0L;
64};
static uint32_t calculate(const Type *data, std::size_t size)
Calculate the checksum of an arbitrary data array.
Definition crc32.hpp:53
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:27
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:34
uint32_t finalize() const
Definition crc32.cpp:23