Crates.io | crcxx |
lib.rs | crcxx |
version | 0.3.1 |
source | src |
created_at | 2020-04-20 09:26:10.81238 |
updated_at | 2023-02-26 20:35:50.651569 |
description | The crate computes CRC-8/16/32/64/128 using various methods. Included catalog of CRC parameters simplify usage. |
homepage | https://github.com/ing-systems/crcxx |
repository | https://github.com/ing-systems/crcxx |
max_upload_size | |
id | 232138 |
size | 168,482 |
The crate computes CRC-8/16/32/64/128 using various methods. Included catalog of CRC parameters simplify usage. It is applicable from small embedded systems to modern desktops and servers. No unsafe or architecture specific code.
The slowest method. No additional memory required.
use crcxx::crc32::{*, catalog::CRC_32_BZIP2};
const CRC: Crc<NoLookupTable> =
Crc::<NoLookupTable>::new(&CRC_32_BZIP2);
fn main() {
// singlepart data.
let crc = CRC.compute(b"123456789");
assert_eq!(crc, 0xFC89_1918);
// Multipart data.
let mut multipart = CRC.compute_multipart();
multipart.update(b"1234");
multipart.update(b"5678");
multipart.update(b"9");
let crc = multipart.value();
assert_eq!(crc, 0xFC89_1918);
}
Good compromise between speed and memory consumption for small embedded devices. Depending on usage scenario usually 2-5 times faster than the previous method.
use crcxx::crc32::{*, catalog::CRC_32_BZIP2};
const CRC: Crc<LookupTable32> =
Crc::<LookupTable32>::new(&CRC_32_BZIP2);
fn main() {
// singlepart data.
let crc = CRC.compute(b"123456789");
assert_eq!(crc, 0xFC89_1918);
// Multipart data.
let mut multipart = CRC.compute_multipart();
multipart.update(b"1234");
multipart.update(b"5678");
multipart.update(b"9");
let crc = multipart.value();
assert_eq!(crc, 0xFC89_1918);
}
Depending on usage scenario usually no more than 2 times faster than the previous method.
use crcxx::crc32::{*, catalog::CRC_32_BZIP2};
const CRC: Crc<LookupTable256> =
Crc::<LookupTable256>::new(&CRC_32_BZIP2);
fn main() {
// singlepart data.
let crc = CRC.compute(b"123456789");
assert_eq!(crc, 0xFC89_1918);
// Multipart data.
let mut multipart = CRC.compute_multipart();
multipart.update(b"1234");
multipart.update(b"5678");
multipart.update(b"9");
let crc = multipart.value();
assert_eq!(crc, 0xFC89_1918);
}
Ultimate method for processing big amounts of data on modern desktops and servers without using architecture specific instructions. Depending on usage scenario (prefer bigger chunks) usually 6 times faster than the previous method. The recommended number of slices is 16. There is usually less than 10% improvement when going from 16 to 32.
use crcxx::crc32::{*, catalog::CRC_32_BZIP2};
const SLICES: usize = 16;
const CRC: Crc<LookupTable256xN<SLICES>> =
Crc::<LookupTable256xN<SLICES>>::new(&CRC_32_BZIP2);
fn main() {
// singlepart data.
let crc = CRC.compute(b"123456789");
assert_eq!(crc, 0xFC89_1918);
// Multipart data.
let mut multipart = CRC.compute_multipart();
multipart.update(b"1234");
multipart.update(b"5678");
multipart.update(b"9");
let crc = multipart.value();
assert_eq!(crc, 0xFC89_1918);
}
Current MSRV is 1.59. Keep in mind the official crate policy is latest stable.
This project is licensed under the Apache 2.0 license