Crates.io | crcany |
lib.rs | crcany |
version | 0.0.2 |
source | src |
created_at | 2021-10-16 02:39:37.92014 |
updated_at | 2021-10-29 02:44:37.628542 |
description | Compute any CRC. |
homepage | |
repository | https://git.sr.ht/~couch/crcany |
max_upload_size | |
id | 465717 |
size | 28,399 |
A port of Mark Adler's crcany package to Rust.
Compute any CRC given the set of parameters that describe it. For more information, see crcany, Gary Cook's catalog of CRC parameters (the data source for these implementations), or Ross Williams's original tutorial, which first specified the parameters.
The library includes two ways to compute CRCs: either the parameter model is directly evaluated, or a procedural macro is used to generate code to handle a specific CRC. In either case, the CRCs can be calculated directly, in a bitwise fashion, or bytewise or wordwise with the use of precalculated tables.
use crcany::crc::v2::Crc;
use crcany::impl_crc;
impl_crc!("CRC-3/GSM");
let mut crc = crc3gsm::bitwise::Crc3Gsm::new();
crc.add_bytes(b"123456789");
assert_eq!(4, crc.to_inner());
use crcany::crc::{Crc, FromSpec};
use crcany::model::BitwiseModel;
let spec = "w=3 p=3 r=t c=2 res=3 n=POOH".parse().unwrap();
let bitwise = BitwiseModel::from_spec(spec);
let init = bitwise.crc(0, [].iter().cloned());
let crc = bitwise.crc(init, b"123456789".iter().cloned());
assert_eq!(2, crc);