Engauge Digitizer 2
Loading...
Searching...
No Matches
Crc32 Class Reference

Compute crc checksum that linux cksum would produce for specified bytes. Based on IEEE Std 1003.1 - 2017. More...

#include <Crc32.h>

Collaboration diagram for Crc32:
Collaboration graph

Public Member Functions

 Crc32 ()
 Single default constructor.
unsigned filecrc (const QString &filename) const
 Compute the checksum using data in file.
unsigned memcrc (const unsigned char *b, unsigned int n) const
 Compute the checksum using data in memory.

Detailed Description

Compute crc checksum that linux cksum would produce for specified bytes. Based on IEEE Std 1003.1 - 2017.

Definition at line 13 of file Crc32.h.

Constructor & Destructor Documentation

◆ Crc32()

Crc32::Crc32 ( )

Single default constructor.

Definition at line 65 of file Crc32.cpp.

66{
67}

Member Function Documentation

◆ filecrc()

unsigned Crc32::filecrc ( const QString & filename) const

Compute the checksum using data in file.

Definition at line 69 of file Crc32.cpp.

70{
71 LOG4CPP_INFO_S ((*mainCat)) << "Crc32::filecrc";
72
73 unsigned i, c, b = 0;
74
75 QFile f (filename);
76 unsigned rtn = 0;
77 if (f.open (QFile::ReadOnly)) {
78 QByteArray array = f.readAll ();
79 int length = array.length ();
80
81 for (i = length; i > 0; --i) {
82 unsigned char chr = array [b++];
83 c = (unsigned) chr;
84 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
85 }
86
87 // Extend with the length of the string
88 while (length != 0) {
89 c = length & 0377;
90 length >>= 8;
91 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
92 }
93
94 rtn = ~rtn;
95 }
96
97 return rtn;
98}
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ memcrc()

unsigned Crc32::memcrc ( const unsigned char * b,
unsigned int n ) const

Compute the checksum using data in memory.

Definition at line 100 of file Crc32.cpp.

101{
102 LOG4CPP_INFO_S ((*mainCat)) << "Crc32::memcrc";
103
104 unsigned i, c, rtn = 0;
105
106 for (i = length; i > 0; --i) {
107 c = (unsigned)(*b++);
108 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
109 }
110
111 // Extend with the length of the string
112 while (length != 0) {
113 c = length & 0377;
114 length >>= 8;
115 rtn = (rtn << 8) ^ m_crctab [(rtn >> 24) ^ c];
116 }
117
118 return ~rtn;
119}

The documentation for this class was generated from the following files: