wrap zlibs checksum functionality
This commit is contained in:
parent
aafcfaaa19
commit
1f6f79782a
3
Makefile
3
Makefile
@ -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
25
checksum.cc
Normal 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
22
checksum.h
Normal 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
|
Loading…
Reference in New Issue
Block a user