pub async fn receive(&mut self) -> io::Result<Result<Command>> {
        self.send_ready_for_query().await?.expect("to send ready for query");
        let mut buffer = [0u8; 1];
        let tag = self.socket.read_exact(&mut buffer).await.map(|_| buffer[0])?;
        if b'X' == tag {
            Ok(Ok(Command::Terminate))
        } else {
            let mut buffer = [0u8; 4];
            let len = self
                .socket
                .read_exact(&mut buffer)
                .await
                .map(|_| NetworkEndian::read_u32(&buffer))?;
            let mut buffer = BytesMut::with_capacity(len as usize - 4);
            buffer.resize(len as usize - 4, b'0');
            let sql_buff = self.socket.read_exact(&mut buffer).await.map(|_| buffer)?;
            log::debug!("FOR TEST sql = {:?}", sql_buff);
            let sql = match String::from_utf8(sql_buff[..sql_buff.len() - 1].to_vec()) {
                Ok(sql) => sql,
                Err(_e) => return Ok(Err(Error::QueryIsNotValidUtfString)),
            };
            log::debug!("SQL = {}", sql);
            Ok(Ok(Command::Query(sql)))
        }
    }
/// receives and decodes a command from remote client
receives and decodes a command from remote client
receives and decodes a command from remote client
pub async fn receive(&mut self) -> io::Result<Result<Command>> {
        self.send_ready_for_query().await?.expect("to send ready for query");
        let mut buffer = [0u8; 1];
        let tag = self.socket.read_exact(&mut buffer).await.map(|_| buffer[0])?;
        if b'X' == tag {
            Ok(Ok(Command::Terminate))
        } else {
            let mut buffer = [0u8; 4];
            let len = self
                .socket
                .read_exact(&mut buffer)
                .await
                .map(|_| NetworkEndian::read_u32(&buffer))?;
            let mut buffer = BytesMut::with_capacity(len as usize - 4);
            buffer.resize(len as usize - 4, b'0');
            let sql_buff = self.socket.read_exact(&mut buffer).await.map(|_| buffer)?;
            log::debug!("FOR TEST sql = {:?}", sql_buff);
            let sql = match String::from_utf8(sql_buff[..sql_buff.len() - 1].to_vec()) {
                Ok(sql) => sql,
                Err(_e) => return Ok(Err(Error::QueryIsNotValidUtfString)),
            };
            log::debug!("SQL = {}", sql);
            Ok(Ok(Command::Query(sql)))
        }
    }
pub async fn receive ( & mut self ) -> io :: Result < Result < Command > > { self . send_ready_for_query ( ) . await ? . expect ( " " ) ; let mut buffer = [ 0u8 ; 1 ] ; let tag = self . socket . read_exact ( & mut buffer ) . await . map ( | _ | buffer [ 0 ] ) ? ; if b'X' == tag { Ok ( Ok ( Command :: Terminate ) ) } else { let mut buffer = [ 0u8 ; 4 ] ; let len = self . socket . read_exact ( & mut buffer ) . await . map ( | _ | NetworkEndian :: read_u32 ( & buffer ) ) ? ; let mut buffer = BytesMut :: with_capacity ( len as usize - 4 ) ; buffer . resize ( len as usize - 4 , b'0' ) ; let sql_buff = self . socket . read_exact ( & mut buffer ) . await . map ( | _ | buffer ) ? ; log :: debug ! ( " " sql_buff ) ; let sql = match String :: from_utf8 ( sql_buff [ .. sql_buff . len ( ) - 1 ] . to_vec ( ) ) { Ok ( sql ) => sql , Err ( _e ) => return Ok ( Err ( Error :: QueryIsNotValidUtfString ) ) , } ; log :: debug ! ( " " sql ) ; Ok ( Ok ( Command :: Query ( sql ) ) ) } }
receives and decodes a command from remote client
receives and decodes a command from remote client
&mut self
&mut self