crcany

Crates.iocrcany
lib.rscrcany
version0.0.2
sourcesrc
created_at2021-10-16 02:39:37.92014
updated_at2021-10-29 02:44:37.628542
descriptionCompute any CRC.
homepage
repositoryhttps://git.sr.ht/~couch/crcany
max_upload_size
id465717
size28,399
Andrew Dona-Couch -- GitHub drop ICE (couchand)

documentation

https://docs.rs/crcany

README

crcany-rs

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.

Examples

Procedural macro

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

Evaluating a model

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);
Commit count: 0

cargo fmt