pub fn load<T, O>(
        reader: &mut T,
        snapshot_len: usize,
        version_map: VersionMap,
    ) -> Result<O, Error>
    where
        T: Read,
        O: Versionize,
    {
        let mut crc_reader = CRC64Reader::new(reader);

        // Extract snapshot data without stored checksum, which is 8 bytes in size
        let raw_snapshot_len = snapshot_len
            .checked_sub(std::mem::size_of::<u64>())
            .ok_or(Error::InvalidSnapshotSize)?;
        let mut snapshot = vec![0u8; raw_snapshot_len];
        crc_reader
            .read_exact(&mut snapshot)
            .map_err(|ref err| Error::Io(err.raw_os_error().unwrap_or(libc::EINVAL)))?;

        // Since the reader updates the checksum as bytes ar being read from it, the order of these 2 statements is
        // important, we first get the checksum computed on the read bytes then read the stored checksum.
        let computed_checksum = crc_reader.checksum();
        let format_vm = Self::format_version_map();
        let stored_checksum: u64 =
            Versionize::deserialize(&mut crc_reader, &format_vm, 0).map_err(Error::Versionize)?;
        if computed_checksum != stored_checksum {
            return Err(Error::Crc64(computed_checksum));
        }

        let mut snapshot_slice: &[u8] = &mut snapshot.as_mut_slice();
        let object: O = Snapshot::unchecked_load(&mut snapshot_slice, version_map)?;

        Ok(object)
    }
/// Attempts to load an existing snapshot and validate CRC.
Attempts to load an existing snapshot and validate CRC.
Attempts to load an existing snapshot and validate CRC .
pub fn load<T, O>(
        reader: &mut T,
        snapshot_len: usize,
        version_map: VersionMap,
    ) -> Result<O, Error>
    where
        T: Read,
        O: Versionize,
    {
        let mut crc_reader = CRC64Reader::new(reader);
        // Extract snapshot data without stored checksum, which is 8 bytes in size
        let raw_snapshot_len = snapshot_len
            .checked_sub(std::mem::size_of::<u64>())
            .ok_or(Error::InvalidSnapshotSize)?;
        let mut snapshot = vec![0u8; raw_snapshot_len];
        crc_reader
            .read_exact(&mut snapshot)
            .map_err(|ref err| Error::Io(err.raw_os_error().unwrap_or(libc::EINVAL)))?;
        // Since the reader updates the checksum as bytes ar being read from it, the order of these 2 statements is
        // important, we first get the checksum computed on the read bytes then read the stored checksum.
        let computed_checksum = crc_reader.checksum();
        let format_vm = Self::format_version_map();
        let stored_checksum: u64 =
            Versionize::deserialize(&mut crc_reader, &format_vm, 0).map_err(Error::Versionize)?;
        if computed_checksum != stored_checksum {
            return Err(Error::Crc64(computed_checksum));
        }
        let mut snapshot_slice: &[u8] = &mut snapshot.as_mut_slice();
        let object: O = Snapshot::unchecked_load(&mut snapshot_slice, version_map)?;
        Ok(object)
    }
pub fn load < T , O > ( reader : & mut T , snapshot_len : usize , version_map : VersionMap , ) -> Result < O , Error > where T : Read , O : Versionize , { let mut crc_reader = CRC64Reader :: new ( reader ) ; // Extract snapshot data without stored checksum, which is 8 bytes in size let raw_snapshot_len = snapshot_len . checked_sub ( std :: mem :: size_of :: < u64 > ( ) ) . ok_or ( Error :: InvalidSnapshotSize ) ? ; let mut snapshot = vec ! [ 0u8 raw_snapshot_len ] ; crc_reader . read_exact ( & mut snapshot ) . map_err ( | ref err | Error :: Io ( err . raw_os_error ( ) . unwrap_or ( libc :: EINVAL ) ) ) ? ; // Since the reader updates the checksum as bytes ar being read from it, the order of these 2 statements is // important, we first get the checksum computed on the read bytes then read the stored checksum. let computed_checksum = crc_reader . checksum ( ) ; let format_vm = Self :: format_version_map ( ) ; let stored_checksum : u64 = Versionize :: deserialize ( & mut crc_reader , & format_vm , 0 ) . map_err ( Error :: Versionize ) ? ; if computed_checksum != stored_checksum { return Err ( Error :: Crc64 ( computed_checksum ) ) ; } let mut snapshot_slice : & [ u8 ] = & mut snapshot . as_mut_slice ( ) ; let object : O = Snapshot :: unchecked_load ( & mut snapshot_slice , version_map ) ? ; Ok ( object ) }
Attempts to load an existing snapshot and validate CRC.
Attempts to load an existing snapshot and validate CRC .
reader
&mut T
snapshot_len
usize
version_map
VersionMap
reader
&mut T
snapshot_len
usize
version_map
VersionMap