I want to use boost::crc so that it works exactly like PHP's crc32() function. I tried reading the horrible documentation and many headaches later I haven't made any progress.
Apparently I have to do something like:
int GetCrc32(const string& my_string) {
return crc_32 = boost::crc<bits, TruncPoly, InitRem, FinalXor,
ReflectIn, ReflectRem>(my_string.c_str(), my_string.length());
}
bits
should be 32.. What the other things are is a mystery. A little help? ;)
Dan Story and ergosys provided good answers (apparently I was looking in the wrong place, that's why the headaches) but while I'm at it I wanted to provide a copy&paste solution for the function in my question for future googlers:
uint32_t GetCrc32(const string& my_string) {
boost::crc_32_type result;
result.process_bytes(my_string.data(), my_string.length());
return result.checksum();
}
You probably want to use the crc_32_type
instead of using the crc template. The template is general and meant to accommodate a wide range of CRC designs using widely varying parameters, but they ship four built-in pre-configured CRC types for common usage, covering CRC16, CCITT, XMODEM and CRC32.
The library includes predefined CRC engines. I think the one you want is crc_32_type. See this example: http://www.boost.org/doc/libs/1_37_0/libs/crc/crc_example.cpp
Have you tried using the predefined crc_32_type
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With