Trait SecDedCodec

Source
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§

Source

fn encodable_size(&self) -> usize

Returns the number of bits that this SecDedCodec can encode.

Source

fn code_size(&self) -> usize

Returns the size of the correction code that will be appended to the data.

Source

fn encode(&self, data: &mut [u8])

Encodes the data IN-PLACE

§Arguments:
  • data: The slice of data to encode. The last secded.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

Source

fn decode(&self, data: &mut [u8]) -> Result<(), ()>

Decodes the data IN-PLACE

§Arguments:
  • data: The slice of data to decode.
    The last secded.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§

Source

fn expected_slice_size(&self) -> Option<usize>

Returns Some(size) if the implementation would panic if data.len() != size

Implementors§