Crate crcxx

Source
Expand description

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.

§Usage

§Processing using no lookup table, single byte per step

The slowest method. No additional memory required.

use crcxx::crc64::{*, catalog::CRC_64_XZ};

const CRC: Crc<NoLookupTable> = Crc::<NoLookupTable>::new(&CRC_64_XZ);

fn main() {
    // singlepart data.
    let crc = CRC.compute(b"123456789");
    assert_eq!(crc, 0x995D_C9BB_DF19_39FA);

    // 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, 0x995D_C9BB_DF19_39FA);
}

§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::crc64::{*, catalog::CRC_64_XZ};

const CRC: Crc<LookupTable32> = Crc::<LookupTable32>::new(&CRC_64_XZ);

fn main() {
    // singlepart data.
    let crc = CRC.compute(b"123456789");
    assert_eq!(crc, 0x995D_C9BB_DF19_39FA);

    // 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, 0x995D_C9BB_DF19_39FA);
}

§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::crc64::{*, catalog::CRC_64_XZ};

const CRC: Crc<LookupTable256> = Crc::<LookupTable256>::new(&CRC_64_XZ);

fn main() {
    // singlepart data.
    let crc = CRC.compute(b"123456789");
    assert_eq!(crc, 0x995D_C9BB_DF19_39FA);

    // 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, 0x995D_C9BB_DF19_39FA);
}

§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::crc64::{*, catalog::CRC_64_XZ};

const SLICES: usize = 16;
const CRC: Crc<LookupTable256xN<SLICES>> =
    Crc::<LookupTable256xN<SLICES>>::new(&CRC_64_XZ);

fn main() {
    // singlepart data.
    let crc = CRC.compute(b"123456789");
    assert_eq!(crc, 0x995D_C9BB_DF19_39FA);

    // 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, 0x995D_C9BB_DF19_39FA);
}

Modules§

crc8
CRC-8
crc16
CRC-16
crc32
CRC-32
crc64
CRC-64
crc128
CRC-128

Structs§

GenericLookupTable32
Calculate using a lookup table with 32 entries
GenericLookupTable256
Calculate using a lookup table with 256 entries
GenericLookupTable256xN
Calculate using a lookup table with 256xN entries
GenericNoLookupTable
Calculate using no lookup table
Params
CRC calculation paremeters

Traits§

ComputeMethod
Abstraction over CRC calculation method.
Register