fn parse_internal(cursor: &mut impl Read) -> Result<Option<(Self, u64)>> {
        let (first, second) = {
            let mut head = [0u8; 2];
            if cursor.read(&mut head)? != 2 {
                return Ok(None);
            }
            trace!("Parsed headers {:?}", head);
            (head[0], head[1])
        };

        trace!("First: {:b}", first);
        trace!("Second: {:b}", second);

        let is_final = first & 0x80 != 0;

        let rsv1 = first & 0x40 != 0;
        let rsv2 = first & 0x20 != 0;
        let rsv3 = first & 0x10 != 0;

        let opcode = OpCode::from(first & 0x0F);
        trace!("Opcode: {:?}", opcode);

        let masked = second & 0x80 != 0;
        trace!("Masked: {:?}", masked);

        let length = {
            let length_byte = second & 0x7F;
            let length_length = LengthFormat::for_byte(length_byte).extra_bytes();
            if length_length > 0 {
                match cursor.read_uint::<NetworkEndian>(length_length) {
                    Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => {
                        return Ok(None);
                    }
                    Err(err) => {
                        return Err(err.into());
                    }
                    Ok(read) => read,
                }
            } else {
                u64::from(length_byte)
            }
        };

        let mask = if masked {
            let mut mask_bytes = [0u8; 4];
            if cursor.read(&mut mask_bytes)? != 4 {
                return Ok(None);
            } else {
                Some(mask_bytes)
            }
        } else {
            None
        };

        // Disallow bad opcode
        match opcode {
            OpCode::Control(Control::Reserved(_)) | OpCode::Data(Data::Reserved(_)) => {
                return Err(Error::Protocol(ProtocolError::InvalidOpcode(first & 0x0F)))
            }
            _ => (),
        }

        let hdr = FrameHeader { is_final, rsv1, rsv2, rsv3, opcode, mask };

        Ok(Some((hdr, length)))
    }
/// Internal parse engine.
/// Returns `None` if insufficient data.
/// Payload size is returned along with the header.
Internal parse engine.
Returns `None` if insufficient data.
Payload size is returned along with the header.
Internal parse engine . Returns ` None ` if insufficient data . Payload size is returned along with the header .
fn parse_internal(cursor: &mut impl Read) -> Result<Option<(Self, u64)>> {
        let (first, second) = {
            let mut head = [0u8; 2];
            if cursor.read(&mut head)? != 2 {
                return Ok(None);
            }
            trace!("Parsed headers {:?}", head);
            (head[0], head[1])
        };
        trace!("First: {:b}", first);
        trace!("Second: {:b}", second);
        let is_final = first & 0x80 != 0;
        let rsv1 = first & 0x40 != 0;
        let rsv2 = first & 0x20 != 0;
        let rsv3 = first & 0x10 != 0;
        let opcode = OpCode::from(first & 0x0F);
        trace!("Opcode: {:?}", opcode);
        let masked = second & 0x80 != 0;
        trace!("Masked: {:?}", masked);
        let length = {
            let length_byte = second & 0x7F;
            let length_length = LengthFormat::for_byte(length_byte).extra_bytes();
            if length_length > 0 {
                match cursor.read_uint::<NetworkEndian>(length_length) {
                    Err(ref err) if err.kind() == ErrorKind::UnexpectedEof => {
                        return Ok(None);
                    }
                    Err(err) => {
                        return Err(err.into());
                    }
                    Ok(read) => read,
                }
            } else {
                u64::from(length_byte)
            }
        };
        let mask = if masked {
            let mut mask_bytes = [0u8; 4];
            if cursor.read(&mut mask_bytes)? != 4 {
                return Ok(None);
            } else {
                Some(mask_bytes)
            }
        } else {
            None
        };
        // Disallow bad opcode
        match opcode {
            OpCode::Control(Control::Reserved(_)) | OpCode::Data(Data::Reserved(_)) => {
                return Err(Error::Protocol(ProtocolError::InvalidOpcode(first & 0x0F)))
            }
            _ => (),
        }
        let hdr = FrameHeader { is_final, rsv1, rsv2, rsv3, opcode, mask };
        Ok(Some((hdr, length)))
    }
fn parse_internal ( cursor : & mut impl Read ) -> Result < Option < ( Self , u64 ) > > { let ( first , second ) = { let mut head = [ 0u8 ; 2 ] ; if cursor . read ( & mut head ) ? != 2 { return Ok ( None ) ; } trace ! ( " " head ) ; ( head [ 0 ] , head [ 1 ] ) } ; trace ! ( " " first ) ; trace ! ( " " second ) ; let is_final = first & 0x80 != 0 ; let rsv1 = first & 0x40 != 0 ; let rsv2 = first & 0x20 != 0 ; let rsv3 = first & 0x10 != 0 ; let opcode = OpCode :: from ( first & 0x0F ) ; trace ! ( " " opcode ) ; let masked = second & 0x80 != 0 ; trace ! ( " " masked ) ; let length = { let length_byte = second & 0x7F ; let length_length = LengthFormat :: for_byte ( length_byte ) . extra_bytes ( ) ; if length_length > 0 { match cursor . read_uint :: < NetworkEndian > ( length_length ) { Err ( ref err ) if err . kind ( ) == ErrorKind :: UnexpectedEof => { return Ok ( None ) ; } Err ( err ) => { return Err ( err . into ( ) ) ; } Ok ( read ) => read , } } else { u64 :: from ( length_byte ) } } ; let mask = if masked { let mut mask_bytes = [ 0u8 ; 4 ] ; if cursor . read ( & mut mask_bytes ) ? != 4 { return Ok ( None ) ; } else { Some ( mask_bytes ) } } else { None } ; // Disallow bad opcode match opcode { OpCode :: Control ( Control :: Reserved ( _ ) ) | OpCode :: Data ( Data :: Reserved ( _ ) ) => { return Err ( Error :: Protocol ( ProtocolError :: InvalidOpcode ( first & 0x0F ) ) ) } _ => ( ) , } let hdr = FrameHeader { is_final , rsv1 , rsv2 , rsv3 , opcode , mask } ; Ok ( Some ( ( hdr , length ) ) ) }
Internal parse engine.
Internal parse engine .
cursor
&mut impl Read
cursor
&mut impl Read