pub async fn read_from(socket: &mut TcpStream) -> crate::Result<Option<Self>> {
        // determine request type; also return `None` if the connection has been closed
        let request_type = match socket.read_u8().await {
            Ok(request_type) => request_type,
            Err(ref e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return Ok(None),
            Err(e) => return Err(e.into()),
        };

        // based on the type, read the rest of the request
        match request_type {
            SYNC_TYPE_ID => {
                let num_peer_requests = socket.read_u16_le().await?;
                let mut peer_requests = Vec::with_capacity(num_peer_requests as usize);
                for _ in 0..num_peer_requests {
                    let peer_request = PeerRequest::read_from(socket).await?;
                    peer_requests.push(peer_request);
                }
                Ok(Some(Self::Sync(peer_requests)))
            }
            COPY_TYPE_ID => {
                let object_ids = read_object_id_list(socket).await?;
                Ok(Some(Self::Copy(object_ids)))
            }
            TAKE_TYPE_ID => {
                let object_ids = read_object_id_list(socket).await?;
                Ok(Some(Self::Take(object_ids)))
            }
            _ => Err(RequestError::InvalidRequestType(request_type).into()),
        }
    }
/// Reads a request from the specified socket. This function will return when:
/// * A well-formed request has been read.
/// * The socket has been closed; in this case `None` will be returned.
/// * The data read from the socket does not represent a valid request; in this case
///   an error will be returned.
Reads a request from the specified socket. This function will return when:
A well-formed request has been read.
The socket has been closed; in this case `None` will be returned.
The data read from the socket does not represent a valid request; in this case
an error will be returned.
Reads a request from the specified socket . This function will return when : A well - formed request has been read . The socket has been closed ; in this case ` None ` will be returned . The data read from the socket does not represent a valid request ; in this case an error will be returned .
pub async fn read_from(socket: &mut TcpStream) -> crate::Result<Option<Self>> {
        // determine request type; also return `None` if the connection has been closed
        let request_type = match socket.read_u8().await {
            Ok(request_type) => request_type,
            Err(ref e) if e.kind() == std::io::ErrorKind::UnexpectedEof => return Ok(None),
            Err(e) => return Err(e.into()),
        };
        // based on the type, read the rest of the request
        match request_type {
            SYNC_TYPE_ID => {
                let num_peer_requests = socket.read_u16_le().await?;
                let mut peer_requests = Vec::with_capacity(num_peer_requests as usize);
                for _ in 0..num_peer_requests {
                    let peer_request = PeerRequest::read_from(socket).await?;
                    peer_requests.push(peer_request);
                }
                Ok(Some(Self::Sync(peer_requests)))
            }
            COPY_TYPE_ID => {
                let object_ids = read_object_id_list(socket).await?;
                Ok(Some(Self::Copy(object_ids)))
            }
            TAKE_TYPE_ID => {
                let object_ids = read_object_id_list(socket).await?;
                Ok(Some(Self::Take(object_ids)))
            }
            _ => Err(RequestError::InvalidRequestType(request_type).into()),
        }
    }
pub async fn read_from ( socket : & mut TcpStream ) -> crate :: Result < Option < Self > > { // determine request type; also return `None` if the connection has been closed let request_type = match socket . read_u8 ( ) . await { Ok ( request_type ) => request_type , Err ( ref e ) if e . kind ( ) == std :: io :: ErrorKind :: UnexpectedEof => return Ok ( None ) , Err ( e ) => return Err ( e . into ( ) ) , } ; // based on the type, read the rest of the request match request_type { SYNC_TYPE_ID => { let num_peer_requests = socket . read_u16_le ( ) . await ? ; let mut peer_requests = Vec :: with_capacity ( num_peer_requests as usize ) ; for _ in 0 .. num_peer_requests { let peer_request = PeerRequest :: read_from ( socket ) . await ? ; peer_requests . push ( peer_request ) ; } Ok ( Some ( Self :: Sync ( peer_requests ) ) ) } COPY_TYPE_ID => { let object_ids = read_object_id_list ( socket ) . await ? ; Ok ( Some ( Self :: Copy ( object_ids ) ) ) } TAKE_TYPE_ID => { let object_ids = read_object_id_list ( socket ) . await ? ; Ok ( Some ( Self :: Take ( object_ids ) ) ) } _ => Err ( RequestError :: InvalidRequestType ( request_type ) . into ( ) ) , } }
Reads a request from the specified socket.
Reads a request from the specified socket .
socket
&mut TcpStream
socket
&mut TcpStream