pub(super) fn read_frame<Stream>(
        &mut self,
        stream: &mut Stream,
        max_size: Option<usize>,
    ) -> Result<Option<Frame>>
    where
        Stream: Read,
    {
        let max_size = max_size.unwrap_or_else(usize::max_value);

        let payload = loop {
            {
                let cursor = self.in_buffer.as_cursor_mut();

                if self.header.is_none() {
                    self.header = FrameHeader::parse(cursor)?;
                }

                if let Some((_, ref length)) = self.header {
                    let length = *length;

                    // Enforce frame size limit early and make sure `length`
                    // is not too big (fits into `usize`).
                    if length > max_size as u64 {
                        return Err(Error::Capacity(CapacityError::MessageTooLong {
                            size: length as usize,
                            max_size,
                        }));
                    }

                    let input_size = cursor.get_ref().len() as u64 - cursor.position();
                    if length <= input_size {
                        // No truncation here since `length` is checked above
                        let mut payload = Vec::with_capacity(length as usize);
                        if length > 0 {
                            cursor.take(length).read_to_end(&mut payload)?;
                        }
                        break payload;
                    }
                }
            }

            // Not enough data in buffer.
            let size = self.in_buffer.read_from(stream)?;
            if size == 0 {
                trace!("no frame received");
                return Ok(None);
            }
        };

        let (header, length) = self.header.take().expect("Bug: no frame header");
        debug_assert_eq!(payload.len() as u64, length);
        let frame = Frame::from_payload(header, payload);
        trace!("received frame {}", frame);
        Ok(Some(frame))
    }
/// Read a frame from the provided stream.
Read a frame from the provided stream.
Read a frame from the provided stream .
pub(super) fn read_frame<Stream>(
        &mut self,
        stream: &mut Stream,
        max_size: Option<usize>,
    ) -> Result<Option<Frame>>
    where
        Stream: Read,
    {
        let max_size = max_size.unwrap_or_else(usize::max_value);
        let payload = loop {
            {
                let cursor = self.in_buffer.as_cursor_mut();
                if self.header.is_none() {
                    self.header = FrameHeader::parse(cursor)?;
                }
                if let Some((_, ref length)) = self.header {
                    let length = *length;
                    // Enforce frame size limit early and make sure `length`
                    // is not too big (fits into `usize`).
                    if length > max_size as u64 {
                        return Err(Error::Capacity(CapacityError::MessageTooLong {
                            size: length as usize,
                            max_size,
                        }));
                    }
                    let input_size = cursor.get_ref().len() as u64 - cursor.position();
                    if length <= input_size {
                        // No truncation here since `length` is checked above
                        let mut payload = Vec::with_capacity(length as usize);
                        if length > 0 {
                            cursor.take(length).read_to_end(&mut payload)?;
                        }
                        break payload;
                    }
                }
            }
            // Not enough data in buffer.
            let size = self.in_buffer.read_from(stream)?;
            if size == 0 {
                trace!("no frame received");
                return Ok(None);
            }
        };
        let (header, length) = self.header.take().expect("Bug: no frame header");
        debug_assert_eq!(payload.len() as u64, length);
        let frame = Frame::from_payload(header, payload);
        trace!("received frame {}", frame);
        Ok(Some(frame))
    }
pub ( super ) fn read_frame < Stream > ( & mut self , stream : & mut Stream , max_size : Option < usize > , ) -> Result < Option < Frame > > where Stream : Read , { let max_size = max_size . unwrap_or_else ( usize :: max_value ) ; let payload = loop { { let cursor = self . in_buffer . as_cursor_mut ( ) ; if self . header . is_none ( ) { self . header = FrameHeader :: parse ( cursor ) ? ; } if let Some ( ( _ , ref length ) ) = self . header { let length = * length ; // Enforce frame size limit early and make sure `length` // is not too big (fits into `usize`). if length > max_size as u64 { return Err ( Error :: Capacity ( CapacityError :: MessageTooLong { size : length as usize , max_size , } ) ) ; } let input_size = cursor . get_ref ( ) . len ( ) as u64 - cursor . position ( ) ; if length <= input_size { // No truncation here since `length` is checked above let mut payload = Vec :: with_capacity ( length as usize ) ; if length > 0 { cursor . take ( length ) . read_to_end ( & mut payload ) ? ; } break payload ; } } } // Not enough data in buffer. let size = self . in_buffer . read_from ( stream ) ? ; if size == 0 { trace ! ( " " ) ; return Ok ( None ) ; } } ; let ( header , length ) = self . header . take ( ) . expect ( " " ) ; debug_assert_eq ! ( payload len ( ) as u64 length ) ; let frame = Frame :: from_payload ( header , payload ) ; trace ! ( " " frame ) ; Ok ( Some ( frame ) ) }
Read a frame from the provided stream.
Read a frame from the provided stream .
&mut self
stream
&mut Stream
max_size
Option<usize>
&mut self
stream
&mut Stream
max_size
Option<usize>