Struct reed_solomon_erasure::ShardByShard
[−]
[src]
pub struct ShardByShard<'a> { /* fields omitted */ }
Bookkeeper for shard by shard encoding.
This is useful for avoiding incorrect use of
encode_single
, encode_single_sep
, encode_single_shard
and encode_single_shard_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
let r = ReedSolomon::new(3, 2); let mut sbs = ShardByShard::new(&r); let mut shards = shards!([0, 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_shard(&mut shards).unwrap(); sbs.encode_shard(&mut shards).unwrap(); // fill in 3rd data shard shards[2][0] = 10; shards[2][1] = 11; shards[2][2] = 12; shards[2][3] = 13; shards[2][4] = 14; // now do the encoding sbs.encode_shard(&mut shards).unwrap(); // above is equivalent to doing r.encode_shards(&mut shards) assert!(r.verify_shards(&shards).unwrap());
Methods
impl<'a> ShardByShard<'a>
[src]
fn new(codec: &'a ReedSolomon) -> ShardByShard<'a>
[src]
Creates a new instance of the bookkeeping struct.
fn parity_ready(&self) -> bool
[src]
Checks if the parity shards are ready to use.
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 LeftoverShards
when there are shards encoded
but parity shards are not ready to use.
fn reset_force(&mut self)
[src]
Resets the bookkeeping data without checking.
fn cur_input_index(&self) -> usize
[src]
Returns the current input shard index.
fn encode(&mut self, slices: &mut [&mut [u8]]) -> Result<(), SBSError>
[src]
Constructs the parity shards partially using the current input data shard.
Returns TooManyCalls
when all input data shards
have already been filled in via encode
or encode_shard
.
fn encode_sep(
&mut self,
data: &[&[u8]],
parity: &mut [&mut [u8]]
) -> Result<(), SBSError>
[src]
&mut self,
data: &[&[u8]],
parity: &mut [&mut [u8]]
) -> Result<(), SBSError>
Constructs the parity shards partially using the current input data shard.
Returns TooManyCalls
when all input data shards
have already been filled in via encode
or encode_shard
.
fn encode_shard(&mut self, shards: &mut [Shard]) -> Result<(), SBSError>
[src]
Constructs the parity shards partially using the current input data shard.
Returns TooManyCalls
when all input data shards
have already been filled in via encode
or encode_shard
.
fn encode_shard_sep(
&mut self,
data: &[Shard],
parity: &mut [Shard]
) -> Result<(), SBSError>
[src]
&mut self,
data: &[Shard],
parity: &mut [Shard]
) -> Result<(), SBSError>
Constructs the parity shards partially using the current input data shard.
Returns TooManyCalls
when all input data shards
have already been filled in via encode
or encode_shard
.
Trait Implementations
impl<'a> PartialEq for ShardByShard<'a>
[src]
fn eq(&self, __arg_0: &ShardByShard<'a>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &ShardByShard<'a>) -> bool
[src]
This method tests for !=
.