crcxx

Crates.iocrcxx
lib.rscrcxx
version0.3.1
sourcesrc
created_at2020-04-20 09:26:10.81238
updated_at2023-02-26 20:35:50.651569
descriptionThe crate computes CRC-8/16/32/64/128 using various methods. Included catalog of CRC parameters simplify usage.
homepagehttps://github.com/ing-systems/crcxx
repositoryhttps://github.com/ing-systems/crcxx
max_upload_size
id232138
size168,482
Karol Harasim (khrs)

documentation

https://docs.rs/crcxx

README

crcxx

Crate API License Windows Build Status

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.

Processing using no lookup table, single byte per step

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

Processing using a lookup table with 32 entries, single byte per step

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

Processing using a lookup table with 256 entries, single byte per step

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

Processing using a lookup table with 256 x SLICES entries, multiple bytes per step

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

MSRV

Current MSRV is 1.59. Keep in mind the official crate policy is latest stable.

License

This project is licensed under the Apache 2.0 license

Commit count: 89

cargo fmt