pub fn write_message(stream : &mut TcpStream, data : &[u8]) -> Result<(), Error> {
    let payload_len = match u16::try_from(data.len()) {
        Ok(l)  => l,
        Err(_) => return Err(Error::InvalidPayload)
    };

    let mut payload : Vec<u8> = Vec::with_capacity(payload_len as usize + 2);

    payload.extend_from_slice(&payload_len.to_be_bytes());
    payload.extend_from_slice(data);

    write(stream, &payload)
}
/// Write a message to stream
///
/// message format is: [len u16 - payload]
Write a message to stream
message format is: [len u16 - payload]
Write a message to stream message format is : [ len u16 - payload ]
pub fn write_message(stream : &mut TcpStream, data : &[u8]) -> Result<(), Error> {
    let payload_len = match u16::try_from(data.len()) {
        Ok(l)  => l,
        Err(_) => return Err(Error::InvalidPayload)
    };
    let mut payload : Vec<u8> = Vec::with_capacity(payload_len as usize + 2);
    payload.extend_from_slice(&payload_len.to_be_bytes());
    payload.extend_from_slice(data);
    write(stream, &payload)
}
pub fn write_message ( stream : & mut TcpStream , data : & [ u8 ] ) -> Result < ( ) , Error > { let payload_len = match u16 :: try_from ( data . len ( ) ) { Ok ( l ) => l , Err ( _ ) => return Err ( Error :: InvalidPayload ) } ; let mut payload : Vec < u8 > = Vec :: with_capacity ( payload_len as usize + 2 ) ; payload . extend_from_slice ( & payload_len . to_be_bytes ( ) ) ; payload . extend_from_slice ( data ) ; write ( stream , & payload ) }
Write a message to stream
message format is: [len u16 - payload]
Write a message to stream message format is : [ len u16 - payload ]
stream
&mut TcpStream
data
&[u8]
stream
&mut TcpStream
data
&[u8]