/// Get buffer of log entries from byte source
Get buffer of log entries from byte source
Get buffer of log entries from byte source
async fn parse_log<T, S>(source: &mut S) -> Result<Vec<T>, PersistenceError>
    where
        T: DeserializeOwned,
        S: AsyncSeek + AsyncRead + Unpin,
    {
        let mut entries = Vec::new();
        let source_size = source
            .seek(SeekFrom::End(0))
            .await
            .map_err(PersistenceError::from)?;
        debug!("Log source size: {}", source_size);
        source
            .seek(SeekFrom::Start(0))
            .await
            .map_err(PersistenceError::from)?;
        let mut buf = Vec::new();
        while source
            .seek(SeekFrom::Current(0))
            .await
            .map_err(PersistenceError::from)?
            < source_size
        {
            let size = source.read_u64_le().await.map_err(PersistenceError::from)?;
            debug!("Log entry size: {}", size);
            buf.reserve(size.try_into().map_err(PersistenceError::LogEntryTooBig)?);
            source
                .take(size)
                .read_buf(&mut buf)
                .await
                .map_err(PersistenceError::from)?;
            entries.push(deserialize(&buf).map_err(PersistenceError::SerializationError)?);
            buf.clear();
        }
        Ok(entries)
    }
async fn parse_log < T , S > ( source : & mut S ) -> Result < Vec < T > , PersistenceError > where T : DeserializeOwned , S : AsyncSeek + AsyncRead + Unpin , { let mut entries = Vec :: new ( ) ; let source_size = source . seek ( SeekFrom :: End ( 0 ) ) . await . map_err ( PersistenceError :: from ) ? ; debug ! ( " " source_size ) ; source . seek ( SeekFrom :: Start ( 0 ) ) . await . map_err ( PersistenceError :: from ) ? ; let mut buf = Vec :: new ( ) ; while source . seek ( SeekFrom :: Current ( 0 ) ) . await . map_err ( PersistenceError :: from ) ? < source_size { let size = source . read_u64_le ( ) . await . map_err ( PersistenceError :: from ) ? ; debug ! ( " " size ) ; buf . reserve ( size . try_into ( ) . map_err ( PersistenceError :: LogEntryTooBig ) ? ) ; source . take ( size ) . read_buf ( & mut buf ) . await . map_err ( PersistenceError :: from ) ? ; entries . push ( deserialize ( & buf ) . map_err ( PersistenceError :: SerializationError ) ? ) ; buf . clear ( ) ; } Ok ( entries ) }
Get buffer of log entries from byte source
Get buffer of log entries from byte source
source
&mut S