Struct liberasurecode::ErasureCoder [−][src]
pub struct ErasureCoder { /* fields omitted */ }
Erasure coder.
Examples
use liberasurecode::{ErasureCoder, Error}; use std::num::NonZeroUsize; let data_fragments = NonZeroUsize::new(4).ok_or("too few fragments")?; let parity_fragments = NonZeroUsize::new(2).ok_or("too few fragments")?; let mut coder = ErasureCoder::new(data_fragments, parity_fragments)?; let data = vec![0, 1, 2, 3]; let encoded = coder.encode(&data)?; assert_eq!(Ok(&data), coder.decode(&encoded[0..]).as_ref()); assert_eq!(Ok(&data), coder.decode(&encoded[1..]).as_ref()); assert_eq!(Ok(&data), coder.decode(&encoded[2..]).as_ref()); assert_eq!(Err(Error::InsufficientFragments), coder.decode(&encoded[3..]));
Methods
impl ErasureCoder
[src]
impl ErasureCoder
pub fn new(
data_fragments: NonZeroUsize,
parity_fragments: NonZeroUsize
) -> Result<Self>
[src]
pub fn new(
data_fragments: NonZeroUsize,
parity_fragments: NonZeroUsize
) -> Result<Self>
Makes a new ErasureCoder
instance with the default settings.
This is equivalent to Builder::new(data_fragments, parity_fragments).finish()
.
pub fn data_fragments(&self) -> NonZeroUsize
[src]
pub fn data_fragments(&self) -> NonZeroUsize
Returns the number of data fragments specified to the coder.
pub fn parity_fragments(&self) -> NonZeroUsize
[src]
pub fn parity_fragments(&self) -> NonZeroUsize
Returns the number of parity fragments specified to the coder.
pub fn fragments(&self) -> NonZeroUsize
[src]
pub fn fragments(&self) -> NonZeroUsize
The total number of data fragments and parity fragments specified to the coder.
pub fn encode(&mut self, data: &[u8]) -> Result<Vec<Vec<u8>>>
[src]
pub fn encode(&mut self, data: &[u8]) -> Result<Vec<Vec<u8>>>
Encodes the given data to data and parity fragments.
pub fn decode<T: AsRef<[u8]>>(&mut self, fragments: &[T]) -> Result<Vec<u8>>
[src]
pub fn decode<T: AsRef<[u8]>>(&mut self, fragments: &[T]) -> Result<Vec<u8>>
Decodes the original data from the given fragments.
pub fn reconstruct<T, F>(
&mut self,
index: usize,
available_fragments: T
) -> Result<Vec<u8>> where
T: Iterator<Item = F>,
F: AsRef<[u8]>,
[src]
pub fn reconstruct<T, F>(
&mut self,
index: usize,
available_fragments: T
) -> Result<Vec<u8>> where
T: Iterator<Item = F>,
F: AsRef<[u8]>,
Reconstructs the fragment specified by the given index from other available fragments.
Trait Implementations
impl Debug for ErasureCoder
[src]
impl Debug for ErasureCoder
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Drop for ErasureCoder
[src]
impl Drop for ErasureCoder
Auto Trait Implementations
impl Send for ErasureCoder
impl Send for ErasureCoder
impl Sync for ErasureCoder
impl Sync for ErasureCoder