Crc32.h
// Crc32.h
//
// Author David Barrett-Lennard
// (C)opyright Cedanet Pty Ltd 2004
#pragma once
#ifndef Ceda_cxUtils_Crc32_H
#define Ceda_cxUtils_Crc32_H
#include "cxUtils.h"
namespace ceda
{
typedef uint32 CRC32;
cxUtils_API CRC32 CalculateCRC32(const void* buffer, ssize_t numBytes, CRC32 previousCrc32 = 0);
class Crc32
{
public:
Crc32() : crc_(0) {}
// Only required if a new CRC is to be calculated
void Clear()
{
crc_ = 0;
}
// Call as many times as required to write the stream on which the CRC is to be calculated
void Append(const void* buffer, ssize_t numBytes)
{
crc_ = CalculateCRC32(buffer, numBytes, crc_);
}
// operator() used to read the calculated 32 bit CRC
CRC32 operator()() const
{
return crc_;
}
private:
CRC32 crc_;
};
cxUtils_API uint32 CalcChecksum32(const void* buffer, ssize_t numBytes);
cxUtils_API uint32 CalculateChecksum32(const uint32* buffer, ssize_t count);
} // namespace ceda
#endif // include guard