pub(crate) fn write_packet<T>(conn: &mut OssuaryConnection,
                                stream: &mut T, data: &[u8],
                                kind: PacketType) -> Result<usize, OssuaryError>
where T: std::io::Write {
    let msg_id = conn.local_msg_id as u16;
    conn.write_buf[0..2].copy_from_slice(&(data.len() as u16).to_be_bytes());
    conn.write_buf[2..4].copy_from_slice(&msg_id.to_be_bytes());
    conn.write_buf[4..6].copy_from_slice(&(kind as u16).to_be_bytes());
    conn.write_buf[6..8].copy_from_slice(&(0u16).to_be_bytes());
    conn.write_buf[8..8+data.len()].copy_from_slice(&data);
    conn.write_buf_used = 8 + data.len();
    conn.local_msg_id += 1;
    let written = write_stored_packet(conn, stream)?;
    Ok(written)
}
/// Write a packet to the OssuaryConnection's internal packet buffer
///
/// All packets are buffered internally because there is no guarantee that a
/// complete packet can be written without blocking, and Ossuary is a non-
/// blocking library.
///
/// On success, returns the number of bytes written to the output buffer.
Write a packet to the OssuaryConnection's internal packet buffer
All packets are buffered internally because there is no guarantee that a
complete packet can be written without blocking, and Ossuary is a non
blocking library.

On success, returns the number of bytes written to the output buffer.
Write a packet to the OssuaryConnection ' s internal packet buffer All packets are buffered internally because there is no guarantee that a complete packet can be written without blocking and Ossuary is a non blocking library . On success returns the number of bytes written to the output buffer .
pub(crate) fn write_packet<T>(conn: &mut OssuaryConnection,
                                stream: &mut T, data: &[u8],
                                kind: PacketType) -> Result<usize, OssuaryError>
where T: std::io::Write {
    let msg_id = conn.local_msg_id as u16;
    conn.write_buf[0..2].copy_from_slice(&(data.len() as u16).to_be_bytes());
    conn.write_buf[2..4].copy_from_slice(&msg_id.to_be_bytes());
    conn.write_buf[4..6].copy_from_slice(&(kind as u16).to_be_bytes());
    conn.write_buf[6..8].copy_from_slice(&(0u16).to_be_bytes());
    conn.write_buf[8..8+data.len()].copy_from_slice(&data);
    conn.write_buf_used = 8 + data.len();
    conn.local_msg_id += 1;
    let written = write_stored_packet(conn, stream)?;
    Ok(written)
}
pub ( crate ) fn write_packet < T > ( conn : & mut OssuaryConnection , stream : & mut T , data : & [ u8 ] , kind : PacketType ) -> Result < usize , OssuaryError > where T : std :: io :: Write { let msg_id = conn . local_msg_id as u16 ; conn . write_buf [ 0 .. 2 ] . copy_from_slice ( & ( data . len ( ) as u16 ) . to_be_bytes ( ) ) ; conn . write_buf [ 2 .. 4 ] . copy_from_slice ( & msg_id . to_be_bytes ( ) ) ; conn . write_buf [ 4 .. 6 ] . copy_from_slice ( & ( kind as u16 ) . to_be_bytes ( ) ) ; conn . write_buf [ 6 .. 8 ] . copy_from_slice ( & ( 0u16 ) . to_be_bytes ( ) ) ; conn . write_buf [ 8 .. 8 + data . len ( ) ] . copy_from_slice ( & data ) ; conn . write_buf_used = 8 + data . len ( ) ; conn . local_msg_id += 1 ; let written = write_stored_packet ( conn , stream ) ? ; Ok ( written ) }
Write a packet to the OssuaryConnection's internal packet buffer
All packets are buffered internally because there is no guarantee that a
complete packet can be written without blocking, and Ossuary is a non
blocking library.
Write a packet to the OssuaryConnection ' s internal packet buffer All packets are buffered internally because there is no guarantee that a complete packet can be written without blocking and Ossuary is a non blocking library .
conn
&mut OssuaryConnection
stream
&mut T
data
&[u8]
kind
PacketType
conn
&mut OssuaryConnection
stream
&mut T
data
&[u8]
kind
PacketType