implemented computeCrc32()
This commit is contained in:
parent
db0fae5ec2
commit
aff51370d9
|
@ -265,7 +265,7 @@ string BinaryReader::readMultibyteTerminatedStringLE(size_t maxBytesToRead, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Reads \a length bytes from the stream an computes the CRC-32 for that block of data.
|
* \brief Reads \a length bytes from the stream and computes the CRC-32 for that block of data.
|
||||||
*
|
*
|
||||||
* \remarks A cyclic redundancy check (CRC) is an error-detecting code commonly used in
|
* \remarks A cyclic redundancy check (CRC) is an error-detecting code commonly used in
|
||||||
* digital networks and storage devices to detect accidental changes to raw data.
|
* digital networks and storage devices to detect accidental changes to raw data.
|
||||||
|
@ -282,6 +282,24 @@ uint32 BinaryReader::readCrc32(size_t length)
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Reads \a length bytes from the buffer and computes the CRC-32 for that block of data.
|
||||||
|
*
|
||||||
|
* \remarks A cyclic redundancy check (CRC) is an error-detecting code commonly used in
|
||||||
|
* digital networks and storage devices to detect accidental changes to raw data.
|
||||||
|
* \remarks NOT TESTED YET
|
||||||
|
*
|
||||||
|
* \sa <a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check">Cyclic redundancy check - Wikipedia</a>
|
||||||
|
*/
|
||||||
|
uint32 BinaryReader::computeCrc32(const char *buffer, size_t length)
|
||||||
|
{
|
||||||
|
uint32 crc = 0x00;
|
||||||
|
for(const char *i = buffer, *end = buffer + length; i < end; ++i) {
|
||||||
|
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast<byte>(*i)];
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief CRC-32 table.
|
* \brief CRC-32 table.
|
||||||
* \remarks Internally used by readCrc32() method.
|
* \remarks Internally used by readCrc32() method.
|
||||||
|
|
Loading…
Reference in New Issue