/// Scans up-to `scan_len` bytes from the stream until a byte pattern is matched on the
/// specified byte alignment boundary. Operation is otherwise identical to `scan_bytes_ref`.
Scans up-to `scan_len` bytes from the stream until a byte pattern is matched on the
specified byte alignment boundary. Operation is otherwise identical to `scan_bytes_ref`.
Scans up - to ` scan_len ` bytes from the stream until a byte pattern is matched on the specified byte alignment boundary . Operation is otherwise identical to ` scan_bytes_ref ` .
pub fn scan_bytes_aligned_ref(
        &mut self,
        pattern: &[u8],
        align: usize,
        scan_len: usize
    ) -> io::Result<&'a [u8]> {
        // The pattern must be atleast one byte.
        debug_assert!(!pattern.is_empty());
        let start = self.pos;
        let remaining = self.buf.len() - start;
        let end = start + cmp::min(remaining, scan_len);
        // If the pattern is longer than amount of bytes remaining, or the scan length is shorter
        // than the pattern, then the pattern will never match. However, since unmatched patterns
        // return the remainder of the buffer or scan_length bytes, which ever is shorter, we return
        // that here.
        if remaining < pattern.len() || scan_len < pattern.len() {
            return Ok(&self.buf[start..end]);
        }
        let mut j = start;
        let mut i = start + pattern.len();
        while i < end {
            if &self.buf[j..i] == pattern {
                break;
            }
            i += align;
            j += align;
        }
        self.pos = cmp::min(i, self.buf.len());
        Ok(&self.buf[start..self.pos])
    }
pub fn scan_bytes_aligned_ref ( & mut self , pattern : & [ u8 ] , align : usize , scan_len : usize ) -> io :: Result < & ' a [ u8 ] > { // The pattern must be atleast one byte. debug_assert ! ( pattern is_empty ( ) ) ; let start = self . pos ; let remaining = self . buf . len ( ) - start ; let end = start + cmp :: min ( remaining , scan_len ) ; // If the pattern is longer than amount of bytes remaining, or the scan length is shorter // than the pattern, then the pattern will never match. However, since unmatched patterns // return the remainder of the buffer or scan_length bytes, which ever is shorter, we return // that here. if remaining < pattern . len ( ) || scan_len < pattern . len ( ) { return Ok ( & self . buf [ start .. end ] ) ; } let mut j = start ; let mut i = start + pattern . len ( ) ; while i < end { if & self . buf [ j .. i ] == pattern { break ; } i += align ; j += align ; } self . pos = cmp :: min ( i , self . buf . len ( ) ) ; Ok ( & self . buf [ start .. self . pos ] ) }
Scans up-to `scan_len` bytes from the stream until a byte pattern is matched on the
specified byte alignment boundary.
Scans up - to ` scan_len ` bytes from the stream until a byte pattern is matched on the specified byte alignment boundary .
&mut self
pattern
&[u8]
align
usize
scan_len
usize