From aff51370d9841f4a868f2281a1102f00bee83db1 Mon Sep 17 00:00:00 2001 From: Martchus Date: Tue, 20 Oct 2015 08:49:38 +0200 Subject: [PATCH] implemented computeCrc32() --- io/binaryreader.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/io/binaryreader.cpp b/io/binaryreader.cpp index 9c0b38c..877ec65 100644 --- a/io/binaryreader.cpp +++ b/io/binaryreader.cpp @@ -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 * digital networks and storage devices to detect accidental changes to raw data. @@ -282,6 +282,24 @@ uint32 BinaryReader::readCrc32(size_t length) 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 Cyclic redundancy check - Wikipedia + */ +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(*i)]; + } + return crc; +} + /*! * \brief CRC-32 table. * \remarks Internally used by readCrc32() method.