pub fn read_header(buf: &[u8], offset: &mut usize) -> Result<Option<(Header, usize)>, Error> {
    let mut len: usize = 0;
    for pos in 0..=3 {
        if buf.len() > *offset + pos + 1 {
            let byte = buf[*offset + pos + 1];
            len += (byte as usize & 0x7F) << (pos * 7);
            if (byte & 0x80) == 0 {
                // Continuation bit == 0, length is parsed
                if buf.len() < *offset + 2 + pos + len {
                    // Won't be able to read full packet
                    return Ok(None);
                }
                // Parse header byte, skip past the header, and return
                let header = Header::new(buf[*offset])?;
                *offset += pos + 2;
                return Ok(Some((header, len)));
            }
        } else {
            // Couldn't read full length
            return Ok(None);
        }
    }
    // Continuation byte == 1 four times, that's illegal.
    Err(Error::InvalidHeader)
}
/// Read the parsed header and remaining_len from the buffer. Only return Some() and advance the
/// buffer position if there is enough data in the buffer to read the full packet.
Read the parsed header and remaining_len from the buffer. Only return Some() and advance the
buffer position if there is enough data in the buffer to read the full packet.
Read the parsed header and remaining_len from the buffer . Only return Some () and advance the buffer position if there is enough data in the buffer to read the full packet .
pub fn read_header(buf: &[u8], offset: &mut usize) -> Result<Option<(Header, usize)>, Error> {
    let mut len: usize = 0;
    for pos in 0..=3 {
        if buf.len() > *offset + pos + 1 {
            let byte = buf[*offset + pos + 1];
            len += (byte as usize & 0x7F) << (pos * 7);
            if (byte & 0x80) == 0 {
                // Continuation bit == 0, length is parsed
                if buf.len() < *offset + 2 + pos + len {
                    // Won't be able to read full packet
                    return Ok(None);
                }
                // Parse header byte, skip past the header, and return
                let header = Header::new(buf[*offset])?;
                *offset += pos + 2;
                return Ok(Some((header, len)));
            }
        } else {
            // Couldn't read full length
            return Ok(None);
        }
    }
    // Continuation byte == 1 four times, that's illegal.
    Err(Error::InvalidHeader)
}
pub fn read_header ( buf : & [ u8 ] , offset : & mut usize ) -> Result < Option < ( Header , usize ) > , Error > { let mut len : usize = 0 ; for pos in 0 ..= 3 { if buf . len ( ) > * offset + pos + 1 { let byte = buf [ * offset + pos + 1 ] ; len += ( byte as usize & 0x7F ) << ( pos * 7 ) ; if ( byte & 0x80 ) == 0 { // Continuation bit == 0, length is parsed if buf . len ( ) < * offset + 2 + pos + len { // Won't be able to read full packet return Ok ( None ) ; } // Parse header byte, skip past the header, and return let header = Header :: new ( buf [ * offset ] ) ? ; * offset += pos + 2 ; return Ok ( Some ( ( header , len ) ) ) ; } } else { // Couldn't read full length return Ok ( None ) ; } } // Continuation byte == 1 four times, that's illegal. Err ( Error :: InvalidHeader ) }
Read the parsed header and remaining_len from the buffer.
Read the parsed header and remaining_len from the buffer .
buf
&[u8]
offset
&mut usize
buf
&[u8]
offset
&mut usize