[−][src]Struct reed_solomon_erasure::ShardByShard
Bookkeeper for shard by shard encoding.
This is useful for avoiding incorrect use of
encode_single
and encode_single_sep
Use cases
Shard by shard encoding is useful for streamed data encoding where you do not have all the needed data shards immediately, but you want to spread out the encoding workload rather than doing the encoding after everything is ready.
A concrete example would be network packets encoding, where encoding packet by packet as you receive them may be more efficient than waiting for N packets then encode them all at once.
Example
use reed_solomon_erasure::galois_8::Field; let r: ReedSolomon<Field> = ReedSolomon::new(3, 2).unwrap(); let mut sbs = ShardByShard::new(&r); let mut shards = shards!([0u8, 1, 2, 3, 4], [5, 6, 7, 8, 9], // say we don't have the 3rd data shard yet // and we want to fill it in later [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]); // encode 1st and 2nd data shard sbs.encode(&mut shards).unwrap(); sbs.encode(&mut shards).unwrap(); // fill in 3rd data shard shards[2][0] = 10.into(); shards[2][1] = 11.into(); shards[2][2] = 12.into(); shards[2][3] = 13.into(); shards[2][4] = 14.into(); // now do the encoding sbs.encode(&mut shards).unwrap(); assert!(r.verify(&shards).unwrap());
Methods
impl<'a, F: 'a + Field> ShardByShard<'a, F>
[src]
pub fn new(codec: &'a ReedSolomon<F>) -> ShardByShard<'a, F>
[src]
Creates a new instance of the bookkeeping struct.
pub fn parity_ready(&self) -> bool
[src]
Checks if the parity shards are ready to use.
pub fn reset(&mut self) -> Result<(), SBSError>
[src]
Resets the bookkeeping data.
You should call this when you have added and encoded all data shards, and have finished using the parity shards.
Returns SBSError::LeftoverShards
when there are shards encoded
but parity shards are not ready to use.
pub fn reset_force(&mut self)
[src]
Resets the bookkeeping data without checking.
pub fn cur_input_index(&self) -> usize
[src]
Returns the current input shard index.
pub fn encode<T, U>(&mut self, shards: T) -> Result<(), SBSError> where
T: AsRef<[U]> + AsMut<[U]>,
U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,
[src]
T: AsRef<[U]> + AsMut<[U]>,
U: AsRef<[F::Elem]> + AsMut<[F::Elem]>,
Constructs the parity shards partially using the current input data shard.
Returns SBSError::TooManyCalls
when all input data shards
have already been filled in via encode
pub fn encode_sep<T: AsRef<[F::Elem]>, U: AsRef<[F::Elem]> + AsMut<[F::Elem]>>(
&mut self,
data: &[T],
parity: &mut [U]
) -> Result<(), SBSError>
[src]
&mut self,
data: &[T],
parity: &mut [U]
) -> Result<(), SBSError>
Constructs the parity shards partially using the current input data shard.
Returns SBSError::TooManyCalls
when all input data shards
have already been filled in via encode
Trait Implementations
impl<'a, F: Debug + 'a + Field> Debug for ShardByShard<'a, F>
[src]
impl<'a, F: PartialEq + 'a + Field> PartialEq<ShardByShard<'a, F>> for ShardByShard<'a, F>
[src]
fn eq(&self, other: &ShardByShard<'a, F>) -> bool
[src]
fn ne(&self, other: &ShardByShard<'a, F>) -> bool
[src]
impl<'a, F: 'a + Field> StructuralPartialEq for ShardByShard<'a, F>
[src]
Auto Trait Implementations
impl<'a, F> RefUnwindSafe for ShardByShard<'a, F> where
<F as Field>::Elem: RefUnwindSafe,
<F as Field>::Elem: RefUnwindSafe,
impl<'a, F> Send for ShardByShard<'a, F> where
<F as Field>::Elem: Send + Sync,
<F as Field>::Elem: Send + Sync,
impl<'a, F> Sync for ShardByShard<'a, F> where
<F as Field>::Elem: Send + Sync,
<F as Field>::Elem: Send + Sync,
impl<'a, F> Unpin for ShardByShard<'a, F>
impl<'a, F> UnwindSafe for ShardByShard<'a, F> where
<F as Field>::Elem: RefUnwindSafe,
<F as Field>::Elem: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,