如何使用boost::crc?

发布于 2024-08-27 14:10:40 字数 564 浏览 14 评论 0原文

我想使用 boost::crc ,以便它的工作方式与 PHP 的 crc32()< /a> 函数。我尝试阅读 可怕的文档,后来我遇到了很多头痛没有取得任何进展。

显然我必须做一些类似的事情:

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应该是32..其他的东西是什么是个谜。有一点帮助吗? ;)

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? ;)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

神也荒唐 2024-09-03 14:10:40

Dan Story 和 ergosys 提供了很好的答案(显然我找错了地方,这就是头痛的原因),但当我这样做时,我想为未来的谷歌用户提供一个复制和粘贴解决方案:

#include <boost/crc.hpp>

uint32_t GetCrc32(const string& my_string) {
    boost::crc_32_type result;
    result.process_bytes(my_string.data(), my_string.length());
    return result.checksum();
}

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:

#include <boost/crc.hpp>

uint32_t GetCrc32(const string& my_string) {
    boost::crc_32_type result;
    result.process_bytes(my_string.data(), my_string.length());
    return result.checksum();
}
別甾虛僞 2024-09-03 14:10:40

您可能想使用 crc_32_type 而不是使用 crc 模板。该模板是通用的,旨在适应使用广泛变化的参数的各种 CRC 设计,但它们提供四种内置的预配置 CRC 类型供常用,涵盖 CRC16、CCITT、XMODEM 和 CRC32。

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.

小巷里的女流氓 2024-09-03 14:10:40

该库包含预定义的 CRC 引擎。我认为你想要的是crc_32_type。请参阅此示例: http://www.boost.org/doc /libs/1_37_0/libs/crc/crc_example.cpp

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

ぃ双果 2024-09-03 14:10:40

您是否尝试过使用预定义的crc_32_type

Have you tried using the predefined crc_32_type?

∞梦里开花 2024-09-03 14:10:40

在此页面上,找到您想要的特定 32 位 CRC,读出所有其他参数:
http://regregex.bbcmicro.net/crc-catalogue.htm

On this page, find the particular 32-bit CRC you want, read off all the other parameters:
http://regregex.bbcmicro.net/crc-catalogue.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文