Fec

Struct Fec 

Source
pub struct Fec { /* private fields */ }
Expand description

Forward Error Correcting encoder/decoder.

The encoder can be defined with 2 values: k and m

  • k is the number of chunks needed to reconstruct the original message
  • m is the total number of chunks that will be produced

The first k chunks contain the original unaltered data, meaning that if all the original chunks are available on the decoding end, no decoding needs to take place.

The final (m-k) chunks contain the parity coding necessary to reproduce any one of the original chunks.

Coding is done with respect to the chunk’s location within the encoded data. This means that each chunk’s sequence number is needed for correct reconstruction.

§Example

use zfec_rs::Fec;

let message = b"Message to be sent";

let fec = Fec::new(5, 8).unwrap();

let (mut encoded_chunks, padding) = fec.encode(&message[..]).unwrap();
encoded_chunks.remove(2);
let decoded_message = fec.decode(&encoded_chunks, padding).unwrap();

assert_eq!(message.to_vec(), decoded_message);

Implementations§

Source§

impl Fec

Source

pub fn new(k: usize, m: usize) -> Result<Fec, Error>

Generates a new encoder/decoder

Source

pub fn encode(&self, data: &[u8]) -> Result<(Vec<Chunk>, usize), Error>

Performs the encoding, returning the encoded chunks and the amount of padding

Because all chunks need to be the same size, the data is padded with 0s at the end as needed

Source

pub fn decode( &self, encoded_data: &Vec<Chunk>, padding: usize, ) -> Result<Vec<u8>, Error>

Performs the decoding

Auto Trait Implementations§

§

impl Freeze for Fec

§

impl RefUnwindSafe for Fec

§

impl Send for Fec

§

impl Sync for Fec

§

impl Unpin for Fec

§

impl UnwindSafe for Fec

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.