async fn fill_buf(&mut self) -> Result<(), Error> {
        let bs = self.block_size as usize;

        if self.found_reset || self.bad_checksum || self.buf_range.end - self.buf_range.start > bs {
            return Ok(());
        }

        // Before we read, shuffle existing data to the beginning of the buffer.
        self.buf.copy_within(self.buf_range.clone(), 0);
        self.buf_range = 0..self.buf_range.end - self.buf_range.start;

        while self.buf_range.end - self.buf_range.start < bs {
            self.buf.resize(self.buf_range.end + bs, 0);
            assert!(self.buf_range.end <= bs);
            let last_read_checksum = self.last_read_checksum();

            // Read the next block's worth, verify its checksum, and append it to |buf|.
            let mut buffer = self.handle.allocate_buffer(bs);
            assert!(self.read_offset % bs as u64 == 0);
            if self.handle.read(self.read_offset, buffer.as_mut()).await? != bs {
                // This shouldn't happen -- it shouldn't be possible to read to the end
                // of the journal file.
                bail!("unexpected end of journal file");
            }
            self.buf.as_mut_slice()[self.buf_range.end..].copy_from_slice(buffer.as_slice());

            let (contents_slice, checksum_slice) =
                buffer.as_slice().split_at(bs - std::mem::size_of::<Checksum>());
            let stored_checksum = LittleEndian::read_u64(checksum_slice);
            let computed_checksum = fletcher64(contents_slice, last_read_checksum);
            if stored_checksum != computed_checksum {
                if stored_checksum ^ RESET_XOR == computed_checksum
                    && self.buf_file_offset <= self.read_offset
                {
                    // Record that we've encountered a reset in the stream (a point where the
                    // journal wasn't cleanly closed in the past) and it starts afresh in this
                    // block.  We don't adjust buf_range until the reset has been processed, but we
                    // do push the checksum.
                    self.found_reset = true;
                    self.checksums.push(stored_checksum);
                    self.read_offset += bs as u64;
                } else {
                    self.bad_checksum = true;
                }
                return Ok(());
            }

            self.checksums.push(stored_checksum);

            // If this was our first read, our buffer offset might be somewhere within the middle of
            // the block, so we need to adjust buf_range accordingly.
            if self.buf_file_offset > self.read_offset {
                assert!(self.buf_range.start == 0);
                self.buf_range = (self.buf_file_offset - self.read_offset) as usize
                    ..self.buf.len() - std::mem::size_of::<Checksum>();
            } else {
                self.buf_range =
                    self.buf_range.start..self.buf.len() - std::mem::size_of::<Checksum>();
            }
            self.read_offset += self.block_size;
        }
        Ok(())
    }
// Fills the buffer so that at least one blocks worth of data is contained within the buffer.
// After reading a block, it verifies the checksum.  Once done, it should be possible to
// deserialize records.
Fills the buffer so that at least one blocks worth of data is contained within the buffer.
After reading a block, it verifies the checksum.  Once done, it should be possible to
deserialize records.
Fills the buffer so that at least one blocks worth of data is contained within the buffer . After reading a block it verifies the checksum . Once done it should be possible to deserialize records .
async fn fill_buf(&mut self) -> Result<(), Error> {
        let bs = self.block_size as usize;
        if self.found_reset || self.bad_checksum || self.buf_range.end - self.buf_range.start > bs {
            return Ok(());
        }
        // Before we read, shuffle existing data to the beginning of the buffer.
        self.buf.copy_within(self.buf_range.clone(), 0);
        self.buf_range = 0..self.buf_range.end - self.buf_range.start;
        while self.buf_range.end - self.buf_range.start < bs {
            self.buf.resize(self.buf_range.end + bs, 0);
            assert!(self.buf_range.end <= bs);
            let last_read_checksum = self.last_read_checksum();
            // Read the next block's worth, verify its checksum, and append it to |buf|.
            let mut buffer = self.handle.allocate_buffer(bs);
            assert!(self.read_offset % bs as u64 == 0);
            if self.handle.read(self.read_offset, buffer.as_mut()).await? != bs {
                // This shouldn't happen -- it shouldn't be possible to read to the end
                // of the journal file.
                bail!("unexpected end of journal file");
            }
            self.buf.as_mut_slice()[self.buf_range.end..].copy_from_slice(buffer.as_slice());
            let (contents_slice, checksum_slice) =
                buffer.as_slice().split_at(bs - std::mem::size_of::<Checksum>());
            let stored_checksum = LittleEndian::read_u64(checksum_slice);
            let computed_checksum = fletcher64(contents_slice, last_read_checksum);
            if stored_checksum != computed_checksum {
                if stored_checksum ^ RESET_XOR == computed_checksum
                    && self.buf_file_offset <= self.read_offset
                {
                    // Record that we've encountered a reset in the stream (a point where the
                    // journal wasn't cleanly closed in the past) and it starts afresh in this
                    // block.  We don't adjust buf_range until the reset has been processed, but we
                    // do push the checksum.
                    self.found_reset = true;
                    self.checksums.push(stored_checksum);
                    self.read_offset += bs as u64;
                } else {
                    self.bad_checksum = true;
                }
                return Ok(());
            }
            self.checksums.push(stored_checksum);
            // If this was our first read, our buffer offset might be somewhere within the middle of
            // the block, so we need to adjust buf_range accordingly.
            if self.buf_file_offset > self.read_offset {
                assert!(self.buf_range.start == 0);
                self.buf_range = (self.buf_file_offset - self.read_offset) as usize
                    ..self.buf.len() - std::mem::size_of::<Checksum>();
            } else {
                self.buf_range =
                    self.buf_range.start..self.buf.len() - std::mem::size_of::<Checksum>();
            }
            self.read_offset += self.block_size;
        }
        Ok(())
    }
async fn fill_buf ( & mut self ) -> Result < ( ) , Error > { let bs = self . block_size as usize ; if self . found_reset || self . bad_checksum || self . buf_range . end - self . buf_range . start > bs { return Ok ( ( ) ) ; } // Before we read, shuffle existing data to the beginning of the buffer. self . buf . copy_within ( self . buf_range . clone ( ) , 0 ) ; self . buf_range = 0 .. self . buf_range . end - self . buf_range . start ; while self . buf_range . end - self . buf_range . start < bs { self . buf . resize ( self . buf_range . end + bs , 0 ) ; assert ! ( self buf_range end bs ) ; let last_read_checksum = self . last_read_checksum ( ) ; // Read the next block's worth, verify its checksum, and append it to |buf|. let mut buffer = self . handle . allocate_buffer ( bs ) ; assert ! ( self read_offset bs as u64 0 ) ; if self . handle . read ( self . read_offset , buffer . as_mut ( ) ) . await ? != bs { // This shouldn't happen -- it shouldn't be possible to read to the end // of the journal file. bail ! ( " " ) ; } self . buf . as_mut_slice ( ) [ self . buf_range . end .. ] . copy_from_slice ( buffer . as_slice ( ) ) ; let ( contents_slice , checksum_slice ) = buffer . as_slice ( ) . split_at ( bs - std :: mem :: size_of :: < Checksum > ( ) ) ; let stored_checksum = LittleEndian :: read_u64 ( checksum_slice ) ; let computed_checksum = fletcher64 ( contents_slice , last_read_checksum ) ; if stored_checksum != computed_checksum { if stored_checksum ^ RESET_XOR == computed_checksum && self . buf_file_offset <= self . read_offset { // Record that we've encountered a reset in the stream (a point where the // journal wasn't cleanly closed in the past) and it starts afresh in this // block.  We don't adjust buf_range until the reset has been processed, but we // do push the checksum. self . found_reset = true ; self . checksums . push ( stored_checksum ) ; self . read_offset += bs as u64 ; } else { self . bad_checksum = true ; } return Ok ( ( ) ) ; } self . checksums . push ( stored_checksum ) ; // If this was our first read, our buffer offset might be somewhere within the middle of // the block, so we need to adjust buf_range accordingly. if self . buf_file_offset > self . read_offset { assert ! ( self buf_range start 0 ) ; self . buf_range = ( self . buf_file_offset - self . read_offset ) as usize .. self . buf . len ( ) - std :: mem :: size_of :: < Checksum > ( ) ; } else { self . buf_range = self . buf_range . start .. self . buf . len ( ) - std :: mem :: size_of :: < Checksum > ( ) ; } self . read_offset += self . block_size ; } Ok ( ( ) ) }
Fills the buffer so that at least one blocks worth of data is contained within the buffer.
Fills the buffer so that at least one blocks worth of data is contained within the buffer .
&mut self
&mut self