scclib
Stable Cloud Computing C++ Library
adler32.h
Go to the documentation of this file.
1 #ifndef _SCC_ENCODE_ADLER32_H
2 #define _SCC_ENCODE_ADLER32_H
3 
4 #include <cstdint>
5 
6 namespace scc::encode {
7 
32 class Adler32
33 {
34  uint32_t m_val;
35  int m_sz;
36 public:
38  Adler32() : m_val(1), m_sz(0) {}
43  Adler32(const void* loc, int len) : m_val(1), m_sz(0)
44  {
45  update(loc, len);
46  }
47  virtual ~Adler32() {}
48 
49  operator uint32_t() const { return m_val; }
50  uint32_t val() const { return m_val; }
51 
54  int size()
55  {
56  return m_sz;
57  }
58 
61  uint32_t reset()
62  {
63  m_val = 1;
64  m_sz = 0;
65  return m_val;
66  }
67 
72  uint32_t reset(const void* loc, int len)
73  {
74  m_val = 1;
75  m_sz = 0;
76  return update(loc, len);
77  }
78 
84  uint32_t update(const void*, int);
85 
86 
87  /* Combine two adler checksums, using the length of the second.
88 
89  The checksum has size incremented by len.
90 
91  \param add Checksum to combine.
92  */
93  uint32_t combine(const Adler32&);
94 
105  uint32_t rotate(unsigned char, unsigned char);
106  uint32_t rotate(char xrem, char xadd) {
107  return rotate(static_cast<unsigned char>(xrem), static_cast<unsigned char>(xadd));
108  }
109 };
112 }
113 
114 #endif
Adler-32 checksum allowing rolling calculation.
Definition: adler32.h:33
Adler32(const void *loc, int len)
Construct with initial value.
Definition: adler32.h:43
Adler32()
Construct with initialized value.
Definition: adler32.h:38
uint32_t reset(const void *loc, int len)
Reset the checksum, and update with initial value.
Definition: adler32.h:72
uint32_t rotate(unsigned char, unsigned char)
Update the checksum with next byte.
Definition: adler32.cc:36
uint32_t reset()
Reset the checksum.
Definition: adler32.h:61
uint32_t update(const void *, int)
Update the checksum with buffer contents.
Definition: adler32.cc:7
int size()
Size of the current window.
Definition: adler32.h:54