pub fn generate_coding_shreds(
        data: &[Shred],
        is_last_in_slot: bool,
        next_code_index: u32,
    ) -> Vec<Shred> {
        const PAYLOAD_ENCODE_SIZE: usize = SHRED_PAYLOAD_SIZE - SIZE_OF_CODING_SHRED_HEADERS;
        let ShredCommonHeader {
            slot,
            index,
            version,
            fec_set_index,
            ..
        } = data.first().unwrap().common_header;
        assert_eq!(fec_set_index, index);
        assert!(data.iter().all(|shred| shred.common_header.slot == slot
            && shred.common_header.version == version
            && shred.fec_set_index() == fec_set_index));
        let num_data = data.len();
        let num_coding = if is_last_in_slot {
            (2 * MAX_DATA_SHREDS_PER_FEC_BLOCK as usize)
                .saturating_sub(num_data)
                .max(num_data)
        } else {
            num_data
        };
        let data: Vec<_> = data
            .iter()
            .map(|shred| &shred.payload[..PAYLOAD_ENCODE_SIZE])
            .collect();
        let mut parity = vec![vec![0u8; PAYLOAD_ENCODE_SIZE]; num_coding];
        Session::new(num_data, num_coding)
            .unwrap()
            .encode(&data, &mut parity[..])
            .unwrap();
        let num_data = u16::try_from(num_data).unwrap();
        let num_coding = u16::try_from(num_coding).unwrap();
        parity
            .iter()
            .enumerate()
            .map(|(i, parity)| {
                let index = next_code_index + u32::try_from(i).unwrap();
                let mut shred = Shred::new_empty_coding(
                    slot,
                    index,
                    fec_set_index,
                    num_data,
                    num_coding,
                    u16::try_from(i).unwrap(), // position
                    version,
                );
                shred.payload[SIZE_OF_CODING_SHRED_HEADERS..].copy_from_slice(parity);
                shred
            })
            .collect()
    }
/// Generates coding shreds for the data shreds in the current FEC set
Generates coding shreds for the data shreds in the current FEC set
Generates coding shreds for the data shreds in the current FEC set
pub fn generate_coding_shreds(
        data: &[Shred],
        is_last_in_slot: bool,
        next_code_index: u32,
    ) -> Vec<Shred> {
        const PAYLOAD_ENCODE_SIZE: usize = SHRED_PAYLOAD_SIZE - SIZE_OF_CODING_SHRED_HEADERS;
        let ShredCommonHeader {
            slot,
            index,
            version,
            fec_set_index,
            ..
        } = data.first().unwrap().common_header;
        assert_eq!(fec_set_index, index);
        assert!(data.iter().all(|shred| shred.common_header.slot == slot
            && shred.common_header.version == version
            && shred.fec_set_index() == fec_set_index));
        let num_data = data.len();
        let num_coding = if is_last_in_slot {
            (2 * MAX_DATA_SHREDS_PER_FEC_BLOCK as usize)
                .saturating_sub(num_data)
                .max(num_data)
        } else {
            num_data
        };
        let data: Vec<_> = data
            .iter()
            .map(|shred| &shred.payload[..PAYLOAD_ENCODE_SIZE])
            .collect();
        let mut parity = vec![vec![0u8; PAYLOAD_ENCODE_SIZE]; num_coding];
        Session::new(num_data, num_coding)
            .unwrap()
            .encode(&data, &mut parity[..])
            .unwrap();
        let num_data = u16::try_from(num_data).unwrap();
        let num_coding = u16::try_from(num_coding).unwrap();
        parity
            .iter()
            .enumerate()
            .map(|(i, parity)| {
                let index = next_code_index + u32::try_from(i).unwrap();
                let mut shred = Shred::new_empty_coding(
                    slot,
                    index,
                    fec_set_index,
                    num_data,
                    num_coding,
                    u16::try_from(i).unwrap(), // position
                    version,
                );
                shred.payload[SIZE_OF_CODING_SHRED_HEADERS..].copy_from_slice(parity);
                shred
            })
            .collect()
    }
pub fn generate_coding_shreds ( data : & [ Shred ] , is_last_in_slot : bool , next_code_index : u32 , ) -> Vec < Shred > { const PAYLOAD_ENCODE_SIZE : usize = SHRED_PAYLOAD_SIZE - SIZE_OF_CODING_SHRED_HEADERS ; let ShredCommonHeader { slot , index , version , fec_set_index , .. } = data . first ( ) . unwrap ( ) . common_header ; assert_eq ! ( fec_set_index index ) ; assert ! ( data iter ( ) all ( shred shred common_header slot slot shred common_header version version shred fec_set_index ( ) fec_set_index ) ) ; let num_data = data . len ( ) ; let num_coding = if is_last_in_slot { ( 2 * MAX_DATA_SHREDS_PER_FEC_BLOCK as usize ) . saturating_sub ( num_data ) . max ( num_data ) } else { num_data } ; let data : Vec < _ > = data . iter ( ) . map ( | shred | & shred . payload [ .. PAYLOAD_ENCODE_SIZE ] ) . collect ( ) ; let mut parity = vec ! [ vec [ 0u8 PAYLOAD_ENCODE_SIZE ] num_coding ] ; Session :: new ( num_data , num_coding ) . unwrap ( ) . encode ( & data , & mut parity [ .. ] ) . unwrap ( ) ; let num_data = u16 :: try_from ( num_data ) . unwrap ( ) ; let num_coding = u16 :: try_from ( num_coding ) . unwrap ( ) ; parity . iter ( ) . enumerate ( ) . map ( | ( i , parity ) | { let index = next_code_index + u32 :: try_from ( i ) . unwrap ( ) ; let mut shred = Shred :: new_empty_coding ( slot , index , fec_set_index , num_data , num_coding , u16 :: try_from ( i ) . unwrap ( ) , // position version , ) ; shred . payload [ SIZE_OF_CODING_SHRED_HEADERS .. ] . copy_from_slice ( parity ) ; shred } ) . collect ( ) }
Generates coding shreds for the data shreds in the current FEC set
Generates coding shreds for the data shreds in the current FEC set
data
&[Shred]
is_last_in_slot
bool
next_code_index
u32