CCrcCalculator.h
Go to the documentation of this file.
1 #ifndef istd_CCrcCalculator_included
2 #define istd_CCrcCalculator_included
3 
4 
5 // Qt includes
6 #include <QtCore/QVector>
7 #include <QtCore/QString>
8 
9 
10 namespace istd
11 {
12 
13 
18 {
19 public:
20  typedef QVector<quint8> ByteStream;
21 
25  static quint32 GetCrcFromData(const quint8* dataPtr, int dataSize);
26 
30  static quint32 GetCrcFromStream(const ByteStream& byteStream);
31 
35  static quint32 GetCrcFromFile(const QString& fileName);
36 
37 protected:
41  static void UpdateCrc(const quint8& byte, quint32& dwCrc32);
42 
43 private:
44  static quint32 s_crcTable[256];
45 };
46 
47 
48 // protected inline methods
49 
50 inline void CCrcCalculator::UpdateCrc(const quint8& byte, quint32& crcValue)
51 {
52  crcValue = (crcValue >> 8) ^ s_crcTable[byte ^ (crcValue & 0x000000FF)];
53 }
54 
55 
56 } // namespace istd
57 
58 
59 #endif // !istd_CCrcCalculator_included
60 
static quint32 GetCrcFromStream(const ByteStream &byteStream)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Helper class for CRC-32 checksum calculation.
static quint32 GetCrcFromData(const quint8 *dataPtr, int dataSize)
Get 32-bit CRC value for the given memory block.
static void UpdateCrc(const quint8 &byte, quint32 &dwCrc32)
Update CRC value for the new input.
static quint32 GetCrcFromFile(const QString &fileName)
Get 32-bit CRC value for a given file.
QVector< quint8 > ByteStream

© 2007-2017 Witold Gantzke and Kirill Lepskiy