macro_rules! crc8_hasher_lookup_table {
(struct $struct_name:ident, $initial_value:expr, $lookup_table:ident, $doc:expr) => { ... };
}
Expand description
Define public structure implementing the CRC-8 algorithm as a core::hash::Hasher
trait implementation using a pre-calculated lookup table.
This implementation is much faster at the cost of some space. A struct name and some documentation for it must be provided.
The lookup table must be stored in a constant defined in the same environment
and can be generated in the build.rs
file with the
build_rs_lookup_table_file_generation
macro and then included like in the following example.
You can also find an example on how to do this in the smbus-pec
crate.
use core::hash::Hasher;
use embedded_crc_macros::crc8_hasher_lookup_table;
// include!(concat!(env!("OUT_DIR"), "/lookup_table.rs"));
crc8_hasher_lookup_table!(struct SmbusPec, 0, LOOKUP_TABLE, "SMBus Packet Error Code");
let mut hasher = SmbusPec::new();
hasher.write(&[0xAB, 0xCD]);
let pec = hasher.finish();
println!("PEC: {}", pec);