wrap zlibs checksum functionality

This commit is contained in:
Joe Thornber 2011-09-12 11:49:42 +01:00
parent aafcfaaa19
commit 1f6f79782a
3 changed files with 49 additions and 1 deletions

View File

@ -3,6 +3,7 @@
all: thin_repair thin_dump thin_restore
SOURCE=\
checksum.cc \
endian_utils.cc \
error_set.cc \
metadata.cc \
@ -14,7 +15,7 @@ OBJECTS=$(subst .cc,.o,$(SOURCE))
TOP_DIR:=$(PWD)
CPPFLAGS=-Wall -g -I$(TOP_DIR)
#CPPFLAGS=-Wall -std=c++0x -g -I$(TOP_DIR)
LIBS=-lstdc++
LIBS=-lz -lstdc++
.PHONEY: test-programs

25
checksum.cc Normal file
View File

@ -0,0 +1,25 @@
#include "checksum.h"
#include <zlib.h>
using namespace base;
//----------------------------------------------------------------
crc32::crc32(uint32_t seed)
: sum_(seed) {
}
void
crc32::append(void const *buffer, unsigned len)
{
sum_ = ::crc32(sum_, reinterpret_cast<Bytef const *>(buffer), len);
}
uint32_t
crc32::get_sum() const
{
return sum_;
}
//----------------------------------------------------------------

22
checksum.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef CHECKSUM_H
#define CHECKSUM_H
#include <stdint.h>
//----------------------------------------------------------------
namespace base {
class crc32 {
crc32(uint32_t seed);
void append(void const *buffer, unsigned len);
uint32_t get_sum() const;
private:
uint32_t sum_;
};
}
//----------------------------------------------------------------
#endif