/// Append given data and return the number of bytes used.
Append given data and return the number of bytes used.
Append given data and return the number of bytes used .
pub fn add(&mut self, data: &[u8]) -> ParsingResult<usize> {
        if self.complete {
            return Ok(0);
        }
        let buf_len   = self.buffer.len();
        let sep_len   = self.separator.len();
        let available = self.max_len - buf_len;
        let consume = if available > data.len() {
            data.len()
        } else {
            available
        };
        let start = if sep_len < buf_len {
            buf_len - sep_len
        } else {
            0
        };
        self.buffer.extend_from_slice(&data[..consume]);
        if let Some(pos) = self.find_separator(start) {
            self.buffer.resize(pos, 0);
            self.complete = true;
            Ok(pos + sep_len - buf_len)
        } else if consume < data.len() {
            Err(ParseError::from("line length exceeded"))
        } else {
            Ok(consume)
        }
    }
pub fn add ( & mut self , data : & [ u8 ] ) -> ParsingResult < usize > { if self . complete { return Ok ( 0 ) ; } let buf_len = self . buffer . len ( ) ; let sep_len = self . separator . len ( ) ; let available = self . max_len - buf_len ; let consume = if available > data . len ( ) { data . len ( ) } else { available } ; let start = if sep_len < buf_len { buf_len - sep_len } else { 0 } ; self . buffer . extend_from_slice ( & data [ .. consume ] ) ; if let Some ( pos ) = self . find_separator ( start ) { self . buffer . resize ( pos , 0 ) ; self . complete = true ; Ok ( pos + sep_len - buf_len ) } else if consume < data . len ( ) { Err ( ParseError :: from ( " " ) ) } else { Ok ( consume ) } }
Append given data and return the number of bytes used.
Append given data and return the number of bytes used .
&mut self
data
&[u8]