pub fn calculate_checksum(buffer: &mut [u8], csum_offset: usize) -> Result<u32> {
    // Read the checksum into a mutable slice
    let csum_buf = &mut buffer[csum_offset..csum_offset + 4];
    // Convert the checksum chunk in to a u32 integer
    let orig_csum = LittleEndian::read_u32(csum_buf);
    // Zero the checksum in the buffer
    LittleEndian::write_u32(csum_buf, 0);
    // Calculate the checksum on the resulting buffer
    let new_csum = crc32c::crc32c(buffer);
    // Put back the original checksum in the buffer
    LittleEndian::write_u32(&mut buffer[csum_offset..csum_offset + 4], orig_csum);

    Ok(new_csum)
}
/// Calculates the checksum of a buffer that itself containts its checksum
/// Therefore, before calculating, the existing checksum is retrieved and the
/// corresponding field is made zero. After the calculation, the existing checksum
/// is put back to the buffer.
Calculates the checksum of a buffer that itself containts its checksum
Therefore, before calculating, the existing checksum is retrieved and the
corresponding field is made zero. After the calculation, the existing checksum
is put back to the buffer.
Calculates the checksum of a buffer that itself containts its checksum Therefore before calculating the existing checksum is retrieved and the corresponding field is made zero . After the calculation the existing checksum is put back to the buffer .
pub fn calculate_checksum(buffer: &mut [u8], csum_offset: usize) -> Result<u32> {
    // Read the checksum into a mutable slice
    let csum_buf = &mut buffer[csum_offset..csum_offset + 4];
    // Convert the checksum chunk in to a u32 integer
    let orig_csum = LittleEndian::read_u32(csum_buf);
    // Zero the checksum in the buffer
    LittleEndian::write_u32(csum_buf, 0);
    // Calculate the checksum on the resulting buffer
    let new_csum = crc32c::crc32c(buffer);
    // Put back the original checksum in the buffer
    LittleEndian::write_u32(&mut buffer[csum_offset..csum_offset + 4], orig_csum);
    Ok(new_csum)
}
pub fn calculate_checksum ( buffer : & mut [ u8 ] , csum_offset : usize ) -> Result < u32 > { // Read the checksum into a mutable slice let csum_buf = & mut buffer [ csum_offset .. csum_offset + 4 ] ; // Convert the checksum chunk in to a u32 integer let orig_csum = LittleEndian :: read_u32 ( csum_buf ) ; // Zero the checksum in the buffer LittleEndian :: write_u32 ( csum_buf , 0 ) ; // Calculate the checksum on the resulting buffer let new_csum = crc32c :: crc32c ( buffer ) ; // Put back the original checksum in the buffer LittleEndian :: write_u32 ( & mut buffer [ csum_offset .. csum_offset + 4 ] , orig_csum ) ; Ok ( new_csum ) }
Calculates the checksum of a buffer that itself containts its checksum
Therefore, before calculating, the existing checksum is retrieved and the
corresponding field is made zero.
Calculates the checksum of a buffer that itself containts its checksum Therefore before calculating the existing checksum is retrieved and the corresponding field is made zero .
buffer
&mut [u8]
csum_offset
usize
buffer
&mut [u8]
csum_offset
usize