Struct ecpool::liberasurecode::LibErasureCoder [−][src]
pub struct LibErasureCoder { /* fields omitted */ }
An ErasureCode
implementation based on openstack/liberasurecode.
Examples
use ecpool::{ErasureCode, ErrorKind}; use ecpool::liberasurecode::LibErasureCoder; 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 = LibErasureCoder::new(data_fragments, parity_fragments)?; // Encodes let data = vec![0, 1, 2, 3]; let encoded = coder.encode(&data)?; let encoded = encoded.iter().map(|f| f.as_ref()).collect::<Vec<_>>(); // Decodes 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()));
Methods
impl LibErasureCoder
[src]
impl LibErasureCoder
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 LibErasureCoder
instance with the default settings.
This is equivalent to LibErasureCoderBuilder::new(data_fragments, parity_fragments).build_coder()
.
pub fn inner_ref(&self) -> &ErasureCoder
[src]
pub fn inner_ref(&self) -> &ErasureCoder
Returns a reference to the inner coder of the instance.
pub fn inner_mut(&mut self) -> &mut ErasureCoder
[src]
pub fn inner_mut(&mut self) -> &mut ErasureCoder
Returns a mutable reference to the inner coder of the instance.
pub fn into_inner(self) -> ErasureCoder
[src]
pub fn into_inner(self) -> ErasureCoder
Takes the owership of the instance and returns the inner coder.
Trait Implementations
impl ErasureCode for LibErasureCoder
[src]
impl ErasureCode for LibErasureCoder
fn data_fragments(&self) -> NonZeroUsize
[src]
fn data_fragments(&self) -> NonZeroUsize
Returns the number of data fragments that the instance uses when encoding/decoding data.
fn parity_fragments(&self) -> NonZeroUsize
[src]
fn parity_fragments(&self) -> NonZeroUsize
Returns the number of parity fragments that the instance uses when encoding/decoding data.
fn encode(&mut self, data: &[u8]) -> Result<Vec<FragmentBuf>>
[src]
fn encode(&mut self, data: &[u8]) -> Result<Vec<FragmentBuf>>
Encodes the given data to fragments. Read more
fn decode(&mut self, fragments: &[&Fragment]) -> Result<Vec<u8>>
[src]
fn decode(&mut self, fragments: &[&Fragment]) -> Result<Vec<u8>>
Decodes the original data from the given fragments. Read more
fn reconstruct(
&mut self,
index: usize,
fragments: &[&Fragment]
) -> Result<Vec<u8>>
[src]
fn reconstruct(
&mut self,
index: usize,
fragments: &[&Fragment]
) -> Result<Vec<u8>>
Reconstructs the fragment specified by the given index from other fragments.
fn fragments(&self) -> NonZeroUsize
[src]
fn fragments(&self) -> NonZeroUsize
The total number of data fragments and parity fragments of the instance.
impl From<ErasureCoder> for LibErasureCoder
[src]
impl From<ErasureCoder> for LibErasureCoder
fn from(f: ErasureCoder) -> Self
[src]
fn from(f: ErasureCoder) -> Self
Performs the conversion.
Auto Trait Implementations
impl Send for LibErasureCoder
impl Send for LibErasureCoder
impl Sync for LibErasureCoder
impl Sync for LibErasureCoder