pub struct CrcCorrector<const L: usize, W: Width> { /* private fields */ }Expand description
CRC Corrector
Associated const CrcCorrector::L refers to message length in bits including an appended CRC
Implementations§
Source§impl<const L: usize> CrcCorrector<L, u16>
impl<const L: usize> CrcCorrector<L, u16>
Sourcepub const fn new(crc: Crc<u16, Table<1>>) -> Self
pub const fn new(crc: Crc<u16, Table<1>>) -> Self
Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.
§Panics
This function will panic if
- The message length is not a multiple of 8. (We expect byte data)
- The requested table length is too large
- The CRC algorithm cannot reliably perform single bit correction with the required message length
In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.
Sourcepub fn correct(
&self,
data: &mut [u8],
crc: u16,
) -> Result<Correction<u16>, Error>
pub fn correct( &self, data: &mut [u8], crc: u16, ) -> Result<Correction<u16>, Error>
Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.
If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.
§Errors
This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.
Source§impl<const L: usize> CrcCorrector<L, u32>
impl<const L: usize> CrcCorrector<L, u32>
Sourcepub const fn new(crc: Crc<u32, Table<1>>) -> Self
pub const fn new(crc: Crc<u32, Table<1>>) -> Self
Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.
§Panics
This function will panic if
- The message length is not a multiple of 8. (We expect byte data)
- The requested table length is too large
- The CRC algorithm cannot reliably perform single bit correction with the required message length
In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.
Sourcepub fn correct(
&self,
data: &mut [u8],
crc: u32,
) -> Result<Correction<u32>, Error>
pub fn correct( &self, data: &mut [u8], crc: u32, ) -> Result<Correction<u32>, Error>
Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.
If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.
§Errors
This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.
Source§impl<const L: usize> CrcCorrector<L, u64>
impl<const L: usize> CrcCorrector<L, u64>
Sourcepub const fn new(crc: Crc<u64, Table<1>>) -> Self
pub const fn new(crc: Crc<u64, Table<1>>) -> Self
Construct CRC Corrector, including lookup table, for a given CRC algorithm and message length.
§Panics
This function will panic if
- The message length is not a multiple of 8. (We expect byte data)
- The requested table length is too large
- The CRC algorithm cannot reliably perform single bit correction with the required message length
In the last case the problem is similar to a hash collision. Either choose a longer CRC (64 bit vs 32 bit vs 16 bit) or a different algorithm. Ultimately there is a limit to the message length a CRC can correct errors for.
Sourcepub fn correct(
&self,
data: &mut [u8],
crc: u64,
) -> Result<Correction<u64>, Error>
pub fn correct( &self, data: &mut [u8], crc: u64, ) -> Result<Correction<u64>, Error>
Correct message with a single bit of corruption in either the provided message or the provided CRC. This method mutates the message to correct corruption but will not mutate it if correction fails.
If a correction is applied the CRC is validated again to ensure that the integrity of the data is okay. This isn’t strictly necessary, but guards against any bugs which would incorrectly ‘correct’ data.
§Errors
This method will either return an error if correction could not be applied, or will mutate the data with a single bit correction and return an indication of which bit was the issue.