Function encode_server_into

Source
pub fn encode_server_into(
    packet: &ServerPacket,
    destination: &mut [u8],
) -> Result<usize, EncodeError>
Expand description

Server counterpart of encode_client_into, with identical atomicity, tail, allocation and capacity guarantees. Preserves exact v5 float bits.

use ferravex_net::{ServerPacket, encode_server_into, decode_server, MAX_PACKET_BYTES};
let packet = ServerPacket::Welcome { nonce: 0, session: 1, player_id: 0, tick: 4 };
let mut bytes = [0; MAX_PACKET_BYTES];
let n = encode_server_into(&packet, &mut bytes).unwrap();
assert_eq!(decode_server(&bytes[..n]).unwrap(), packet);