#pragma once

#include <cstdint>

extern const uint32_t crc_32_table[256];

class crc_32_type
{
public:
  void process_bytes(const uint8_t *ptr, std::size_t size)
  {
    uint32_t crc = m_crc;
    while (size--)
      crc = (crc >> 8) ^ crc_32_table[(crc ^ *ptr++) & 0xFF];
    m_crc = crc;
  }

  uint32_t checksum()
  {
    return m_crc;
  }

private:
  uint32_t m_crc = 0;
};
