pub fn reconstruct_blobs<B>(
        &self,
        blobs: &mut [B],
        present: &[bool],
        size: usize,
        block_start_idx: u64,
        slot: u64,
    ) -> Result<(Vec<Blob>, Vec<Blob>)>
    where
        B: AsMut<[u8]>,
    {
        let mut blocks: Vec<&mut [u8]> = blobs.iter_mut().map(AsMut::as_mut).collect();

        trace!("[reconstruct_blobs] present: {:?}, size: {}", present, size,);

        // Decode the blocks
        self.decode_blocks(blocks.as_mut_slice(), &present)?;

        let mut recovered_data = vec![];
        let mut recovered_coding = vec![];

        let erasures = present
            .iter()
            .enumerate()
            .filter_map(|(i, present)| if *present { None } else { Some(i) });

        // Create the missing blobs from the reconstructed data
        for n in erasures {
            let data_size;
            let idx;
            let first_byte;

            if n < NUM_DATA {
                let mut blob = Blob::new(&blocks[n]);

                data_size = blob.data_size() as usize - BLOB_HEADER_SIZE;
                idx = n as u64 + block_start_idx;
                first_byte = blob.data[0];

                blob.set_size(data_size);
                recovered_data.push(blob);
            } else {
                let mut blob = Blob::default();
                blob.data_mut()[..size].copy_from_slice(&blocks[n]);
                data_size = size;
                idx = (n as u64 + block_start_idx) - NUM_DATA as u64;
                first_byte = blob.data[0];

                blob.set_slot(slot);
                blob.set_index(idx);
                blob.set_size(data_size);
                recovered_coding.push(blob);
            }

            trace!(
                "[reconstruct_blobs] erasures[{}] ({}) data_size: {} data[0]: {}",
                n,
                idx,
                data_size,
                first_byte
            );
        }

        Ok((recovered_data, recovered_coding))
    }
/// Reconstruct any missing blobs in this erasure set if possible
/// Re-indexes any coding blobs that have been reconstructed and fixes up size in metadata
/// Assumes that the user has sliced into the blobs appropriately already. else recovery will
/// return an error or garbage data
Reconstruct any missing blobs in this erasure set if possible
Re-indexes any coding blobs that have been reconstructed and fixes up size in metadata
Assumes that the user has sliced into the blobs appropriately already. else recovery will
return an error or garbage data
Reconstruct any missing blobs in this erasure set if possible Re - indexes any coding blobs that have been reconstructed and fixes up size in metadata Assumes that the user has sliced into the blobs appropriately already . else recovery will return an error or garbage data
pub fn reconstruct_blobs<B>(
        &self,
        blobs: &mut [B],
        present: &[bool],
        size: usize,
        block_start_idx: u64,
        slot: u64,
    ) -> Result<(Vec<Blob>, Vec<Blob>)>
    where
        B: AsMut<[u8]>,
    {
        let mut blocks: Vec<&mut [u8]> = blobs.iter_mut().map(AsMut::as_mut).collect();
        trace!("[reconstruct_blobs] present: {:?}, size: {}", present, size,);
        // Decode the blocks
        self.decode_blocks(blocks.as_mut_slice(), &present)?;
        let mut recovered_data = vec![];
        let mut recovered_coding = vec![];
        let erasures = present
            .iter()
            .enumerate()
            .filter_map(|(i, present)| if *present { None } else { Some(i) });
        // Create the missing blobs from the reconstructed data
        for n in erasures {
            let data_size;
            let idx;
            let first_byte;
            if n < NUM_DATA {
                let mut blob = Blob::new(&blocks[n]);
                data_size = blob.data_size() as usize - BLOB_HEADER_SIZE;
                idx = n as u64 + block_start_idx;
                first_byte = blob.data[0];
                blob.set_size(data_size);
                recovered_data.push(blob);
            } else {
                let mut blob = Blob::default();
                blob.data_mut()[..size].copy_from_slice(&blocks[n]);
                data_size = size;
                idx = (n as u64 + block_start_idx) - NUM_DATA as u64;
                first_byte = blob.data[0];
                blob.set_slot(slot);
                blob.set_index(idx);
                blob.set_size(data_size);
                recovered_coding.push(blob);
            }
            trace!(
                "[reconstruct_blobs] erasures[{}] ({}) data_size: {} data[0]: {}",
                n,
                idx,
                data_size,
                first_byte
            );
        }
        Ok((recovered_data, recovered_coding))
    }
pub fn reconstruct_blobs < B > ( & self , blobs : & mut [ B ] , present : & [ bool ] , size : usize , block_start_idx : u64 , slot : u64 , ) -> Result < ( Vec < Blob > , Vec < Blob > ) > where B : AsMut < [ u8 ] > , { let mut blocks : Vec < & mut [ u8 ] > = blobs . iter_mut ( ) . map ( AsMut :: as_mut ) . collect ( ) ; trace ! ( " " present size ) ; // Decode the blocks self . decode_blocks ( blocks . as_mut_slice ( ) , & present ) ? ; let mut recovered_data = vec ! [ ] ; let mut recovered_coding = vec ! [ ] ; let erasures = present . iter ( ) . enumerate ( ) . filter_map ( | ( i , present ) | if * present { None } else { Some ( i ) } ) ; // Create the missing blobs from the reconstructed data for n in erasures { let data_size ; let idx ; let first_byte ; if n < NUM_DATA { let mut blob = Blob :: new ( & blocks [ n ] ) ; data_size = blob . data_size ( ) as usize - BLOB_HEADER_SIZE ; idx = n as u64 + block_start_idx ; first_byte = blob . data [ 0 ] ; blob . set_size ( data_size ) ; recovered_data . push ( blob ) ; } else { let mut blob = Blob :: default ( ) ; blob . data_mut ( ) [ .. size ] . copy_from_slice ( & blocks [ n ] ) ; data_size = size ; idx = ( n as u64 + block_start_idx ) - NUM_DATA as u64 ; first_byte = blob . data [ 0 ] ; blob . set_slot ( slot ) ; blob . set_index ( idx ) ; blob . set_size ( data_size ) ; recovered_coding . push ( blob ) ; } trace ! ( " " n idx data_size first_byte ) ; } Ok ( ( recovered_data , recovered_coding ) ) }
Reconstruct any missing blobs in this erasure set if possible
Re-indexes any coding blobs that have been reconstructed and fixes up size in metadata
Assumes that the user has sliced into the blobs appropriately already.
Reconstruct any missing blobs in this erasure set if possible Re - indexes any coding blobs that have been reconstructed and fixes up size in metadata Assumes that the user has sliced into the blobs appropriately already .
&self
blobs
&mut [B]
present
&[bool]
size
usize
block_start_idx
u64
slot
u64
&self
blobs
&mut [B]
present
&[bool]
size
usize
block_start_idx
u64
slot
u64