pub fn read_command(stream : &mut TcpStream) -> Result<CommandMessage, Error> {
    let mut buf : [u8; 1] = [0; 1];
    if let Err(_) = stream.read_exact(&mut buf) {
        return Err(Error::NetworkError);
    }

    let code = match CommandCode::from_u8(buf[0]) {
        Some(c) => c,
        None    => return Err(Error::InvalidPayload)
    };

    match read_message(stream) {
        Ok(payload) if payload.len() > 0 => Ok(CommandMessage::new(code, Some(payload))),
        Ok(_)                            => Ok(CommandMessage::new(code, None)),
        Err(msg)                         => Err(msg)
    }
}
/// Read a CommandMessage from stream
///
/// message format is: [command u8 - len u16 - payload]
Read a CommandMessage from stream
message format is: [command u8 - len u16 - payload]
Read a CommandMessage from stream message format is : [ command u8 - len u16 - payload ]
pub fn read_command(stream : &mut TcpStream) -> Result<CommandMessage, Error> {
    let mut buf : [u8; 1] = [0; 1];
    if let Err(_) = stream.read_exact(&mut buf) {
        return Err(Error::NetworkError);
    }
    let code = match CommandCode::from_u8(buf[0]) {
        Some(c) => c,
        None    => return Err(Error::InvalidPayload)
    };
    match read_message(stream) {
        Ok(payload) if payload.len() > 0 => Ok(CommandMessage::new(code, Some(payload))),
        Ok(_)                            => Ok(CommandMessage::new(code, None)),
        Err(msg)                         => Err(msg)
    }
}
pub fn read_command ( stream : & mut TcpStream ) -> Result < CommandMessage , Error > { let mut buf : [ u8 ; 1 ] = [ 0 ; 1 ] ; if let Err ( _ ) = stream . read_exact ( & mut buf ) { return Err ( Error :: NetworkError ) ; } let code = match CommandCode :: from_u8 ( buf [ 0 ] ) { Some ( c ) => c , None => return Err ( Error :: InvalidPayload ) } ; match read_message ( stream ) { Ok ( payload ) if payload . len ( ) > 0 => Ok ( CommandMessage :: new ( code , Some ( payload ) ) ) , Ok ( _ ) => Ok ( CommandMessage :: new ( code , None ) ) , Err ( msg ) => Err ( msg ) } }
Read a CommandMessage from stream
message format is: [command u8 - len u16 - payload]
Read a CommandMessage from stream message format is : [ command u8 - len u16 - payload ]
stream
&mut TcpStream
stream
&mut TcpStream