pub struct ReplicaCoder { /* fields omitted */ }
An ErasureCode
implementation that simply replicates the input data.
Note that this is provided for example and testing purposes only and not intended to use in production.
use ecpool::{ErasureCode, ErrorKind};
use ecpool::replica::ReplicaCoder;
use std::num::NonZeroUsize;
let data_fragments = NonZeroUsize::new(4).ok_or("invalid input")?;
let parity_fragments = NonZeroUsize::new(2).ok_or("invalid input")?;
let mut coder = ReplicaCoder::new(data_fragments, parity_fragments);
let data = vec![0, 1, 2, 3];
let encoded = coder.encode(&data)?;
let encoded = encoded.iter().map(|f| f.as_ref()).collect::<Vec<_>>();
assert_eq!(Some(&data), coder.decode(&encoded[0..]).as_ref().ok());
assert_eq!(Some(&data), coder.decode(&encoded[1..]).as_ref().ok());
assert_eq!(Some(&data), coder.decode(&encoded[2..]).as_ref().ok());
assert_eq!(Err(ErrorKind::InvalidInput), coder.decode(&encoded[3..]).map_err(|e| *e.kind()));
Makes a new ReplicaCoder
instance.
Formats the value using the given formatter. Read more
Performs copy-assignment from source
. Read more
Returns the number of data fragments that the instance uses when encoding/decoding data.
Returns the number of parity fragments that the instance uses when encoding/decoding data.
Encodes the given data to fragments. Read more
Decodes the original data from the given fragments. Read more
The total number of data fragments and parity fragments of the instance.
Reconstructs the fragment specified by the given index from other fragments.
type Coder = Self
The type of ErasureCode
implementaion to be built.
Builds an instance of the ErasureCode
implementaion.
Returns the identifier that distinguishes the kind of instances to be built. Read more