pub trait SecDedCodec {
// Required methods
fn encodable_size(&self) -> usize;
fn code_size(&self) -> usize;
fn encode(&self, data: &mut [u8]);
fn decode(&self, data: &mut [u8]) -> Result<(), ()>;
// Provided method
fn expected_slice_size(&self) -> Option<usize> { ... }
}Expand description
Your main interaction point with this crate, it allows you to encode and decode your data slices.
Required Methods§
Sourcefn encodable_size(&self) -> usize
fn encodable_size(&self) -> usize
Returns the number of bits that this SecDedCodec can encode.
Sourcefn code_size(&self) -> usize
fn code_size(&self) -> usize
Returns the size of the correction code that will be appended to the data.
Sourcefn encode(&self, data: &mut [u8])
fn encode(&self, data: &mut [u8])
Encodes the data IN-PLACE
§Arguments:
data: The slice of data to encode. The lastsecded.code_size()bits MUST be set to 0.
§Panics:
Depending on the implementation, panics may occur if the size of the slice isn’t adapted to the Codec:
- SecDed64 panics if
data.len() != 8 - SecDed128 panics if
data.len() != 16 - You can use
secded.expected_slice_size()to find out if a specific size is required for the slice.
Unless you use the no-panics feature, encoding will also panic if the data you try to encode has some
bits set to 1 in the reserved space, or past the encodable_size() + code_size() rightmost bits
Sourcefn decode(&self, data: &mut [u8]) -> Result<(), ()>
fn decode(&self, data: &mut [u8]) -> Result<(), ()>
Decodes the data IN-PLACE
§Arguments:
data: The slice of data to decode.
The lastsecded.code_size()bits will be reset to 0, a single error will be corrected implicitly.
§Returns:
Ok(()) if the data slice’s correctness has been checked: 0 error found or 1 found and corrected.
Err(()) if 2 errors were detected.
§Panics:
Depending on the implementation, panics may occur if the size of the slice isn’t adapted to the Codec:
- SecDed64 panics if
data.len() != 8 - SecDed128 panics if
data.len() != 16 - You can use
secded.expected_slice_size()to find out if a specific size is required for the slice.
Provided Methods§
Sourcefn expected_slice_size(&self) -> Option<usize>
fn expected_slice_size(&self) -> Option<usize>
Returns Some(size) if the implementation would panic if data.len() != size