Crates.io | crc-any |
lib.rs | crc-any |
version | 2.5.0 |
source | src |
created_at | 2018-08-24 06:51:10.760593 |
updated_at | 2024-05-01 13:45:49.926109 |
description | To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions. |
homepage | https://magiclen.org/crc-any |
repository | https://github.com/magiclen/crc-any |
max_upload_size | |
id | 81000 |
size | 242,515 |
To compute CRC values by providing the length of bits, expression, reflection, an initial value and a final xor value. It has many built-in CRC functions.
You can use create_crc
associated function to create a CRC instance by providing the length of bits, expression, reflection, an initial value and a final xor value. For example, if you want to compute a CRC-24 value.
use crc_any::CRC;
let mut crc24 = CRC::create_crc(0x0000000000864CFB, 24, 0x0000000000B704CE, 0x0000000000000000, false);
crc24.digest(b"hello");
assert_eq!([71, 245, 138].to_vec(), crc24.get_crc_vec_be());
assert_eq!("0x47F58A", &crc24.to_string());
To simplify the usage, there are several common versions of CRC whose computing functions are already built-in.
crc32b
in mhash
.mhash
is a common library which has two weird versions of CRC32 called crc32
and crc32b
. crc32
and crc32mhash
in this module are crc32b
and crc32
in mhash respectively.For instance,
use crc_any::CRC;
let mut crc64 = CRC::crc64();
crc64.digest(b"hello");
assert_eq!([64, 84, 74, 48, 97, 55, 182, 236].to_vec(), crc64.get_crc_vec_be());
assert_eq!("0x40544A306137B6EC", &crc64.to_string());
After getting a CRC value, you can still use the digest
method to continue computing the next CRC values.
To make sure this crate will not use heap memory allocation, you can disable the default features.
[dependencies.crc-any]
version = "*"
default-features = false
After doing that, the get_crc_vec_be
and get_crc_vec_le
methods can not be used. But if you still need this crate to return a Vec
without dynamic allocation, you can enable the heapless
feature to make the get_crc_heapless_vec_be
and get_crc_heapless_vec_le
methods available.
[dependencies.crc-any]
version = "*"
default-features = false
features = ["heapless"]
https://crates.io/crates/crc-any