pub async fn recv<T: DeserializeOwned>(&mut self) -> Result<T, Error> {
        let bincode_config = self.bincode_config();

        loop {
            if self.recv_pos < self.recv_chunk.len() {
                let mut reader = &self.recv_chunk[self.recv_pos..];
                let msg = bincode_config.deserialize_from(&mut reader)?;
                self.recv_pos = self.recv_chunk.len() - reader.len();
                return Ok(msg);
            }

            if self.read_pos < 3 {
                self.read_buffer.resize(3, 0);
                self.finish_read().await?;
            }

            let compressed = self.read_buffer[0] != 0;
            let chunk_len = LittleEndian::read_u16(&self.read_buffer[1..3]);
            if chunk_len > self.max_chunk_len {
                return Err(Error::ChunkTooLarge);
            }
            self.read_buffer.resize(chunk_len as usize + 3, 0);
            self.finish_read().await?;

            if compressed {
                let decompressed_len = decompress_len(&self.read_buffer[3..])?;
                if decompressed_len > self.max_chunk_len as usize {
                    return Err(Error::ChunkTooLarge);
                }
                self.recv_chunk.resize(decompressed_len, 0);
                self.decoder
                    .decompress(&self.read_buffer[3..], &mut self.recv_chunk)?;
            } else {
                self.recv_chunk.resize(chunk_len as usize, 0);
                self.recv_chunk.copy_from_slice(&self.read_buffer[3..]);
            }

            self.recv_pos = 0;
            self.read_pos = 0;
        }
    }
/// Receive a message.
///
/// This method is cancel safe, it will never partially receive a message and will never drop a
/// received message.
Receive a message.
This method is cancel safe, it will never partially receive a message and will never drop a
received message.
Receive a message . This method is cancel safe it will never partially receive a message and will never drop a received message .
pub async fn recv<T: DeserializeOwned>(&mut self) -> Result<T, Error> {
        let bincode_config = self.bincode_config();
        loop {
            if self.recv_pos < self.recv_chunk.len() {
                let mut reader = &self.recv_chunk[self.recv_pos..];
                let msg = bincode_config.deserialize_from(&mut reader)?;
                self.recv_pos = self.recv_chunk.len() - reader.len();
                return Ok(msg);
            }
            if self.read_pos < 3 {
                self.read_buffer.resize(3, 0);
                self.finish_read().await?;
            }
            let compressed = self.read_buffer[0] != 0;
            let chunk_len = LittleEndian::read_u16(&self.read_buffer[1..3]);
            if chunk_len > self.max_chunk_len {
                return Err(Error::ChunkTooLarge);
            }
            self.read_buffer.resize(chunk_len as usize + 3, 0);
            self.finish_read().await?;
            if compressed {
                let decompressed_len = decompress_len(&self.read_buffer[3..])?;
                if decompressed_len > self.max_chunk_len as usize {
                    return Err(Error::ChunkTooLarge);
                }
                self.recv_chunk.resize(decompressed_len, 0);
                self.decoder
                    .decompress(&self.read_buffer[3..], &mut self.recv_chunk)?;
            } else {
                self.recv_chunk.resize(chunk_len as usize, 0);
                self.recv_chunk.copy_from_slice(&self.read_buffer[3..]);
            }
            self.recv_pos = 0;
            self.read_pos = 0;
        }
    }
pub async fn recv < T : DeserializeOwned > ( & mut self ) -> Result < T , Error > { let bincode_config = self . bincode_config ( ) ; loop { if self . recv_pos < self . recv_chunk . len ( ) { let mut reader = & self . recv_chunk [ self . recv_pos .. ] ; let msg = bincode_config . deserialize_from ( & mut reader ) ? ; self . recv_pos = self . recv_chunk . len ( ) - reader . len ( ) ; return Ok ( msg ) ; } if self . read_pos < 3 { self . read_buffer . resize ( 3 , 0 ) ; self . finish_read ( ) . await ? ; } let compressed = self . read_buffer [ 0 ] != 0 ; let chunk_len = LittleEndian :: read_u16 ( & self . read_buffer [ 1 .. 3 ] ) ; if chunk_len > self . max_chunk_len { return Err ( Error :: ChunkTooLarge ) ; } self . read_buffer . resize ( chunk_len as usize + 3 , 0 ) ; self . finish_read ( ) . await ? ; if compressed { let decompressed_len = decompress_len ( & self . read_buffer [ 3 .. ] ) ? ; if decompressed_len > self . max_chunk_len as usize { return Err ( Error :: ChunkTooLarge ) ; } self . recv_chunk . resize ( decompressed_len , 0 ) ; self . decoder . decompress ( & self . read_buffer [ 3 .. ] , & mut self . recv_chunk ) ? ; } else { self . recv_chunk . resize ( chunk_len as usize , 0 ) ; self . recv_chunk . copy_from_slice ( & self . read_buffer [ 3 .. ] ) ; } self . recv_pos = 0 ; self . read_pos = 0 ; } }
Receive a message.
Receive a message .
&mut self
&mut self