}
}
+uint32_t
+crc32_type(const uint8_t* data, size_t nbytes, uint32_t startingChecksum) {
+ return ~crc32(data, nbytes, startingChecksum);
+}
+
} // folly
uint32_t
crc32(const uint8_t* data, size_t nbytes, uint32_t startingChecksum = ~0U);
+/**
+ * Compute the CRC-32 checksum of a buffer, using a hardware-accelerated
+ * implementation if available or a portable software implementation as
+ * a default.
+ *
+ * @note compared to crc32(), crc32_type() uses a different set of default
+ * parameters to match the results returned by boost::crc_32_type and
+ * php's built-in crc32 implementation
+ */
+uint32_t
+crc32_type(const uint8_t* data, size_t nbytes, uint32_t startingChecksum = ~0U);
+
} // folly
#include <folly/Checksum.h>
-
+#include <boost/crc.hpp>
#include <folly/Benchmark.h>
#include <folly/Hash.h>
#include <folly/detail/ChecksumDetail.h>
}
}
+void testMatchesBoost32Type() {
+ for (auto expected : expectedResults) {
+ boost::crc_32_type result;
+ result.process_bytes(buffer + expected.offset, expected.length);
+ const uint32_t boostResult = result.checksum();
+ const uint32_t follyResult =
+ folly::crc32_type(buffer + expected.offset, expected.length);
+ EXPECT_EQ(follyResult, boostResult);
+ }
+}
+
} // namespace
TEST(Checksum, crc32c_software) {
}
}
+TEST(Checksum, crc32_type) {
+ // Test that crc32_type matches boost::crc_32_type
+ testMatchesBoost32Type();
+}
+
void benchmarkHardwareCRC32C(unsigned long iters, size_t blockSize) {
if (folly::detail::crc32c_hw_supported()) {
uint32_t checksum;