pub fn encode_client_into(
packet: &ClientPacket,
destination: &mut [u8],
) -> Result<usize, EncodeError>Expand description
Encode v5 into a disjoint caller slice without allocating. Success initializes exactly the returned prefix and leaves the tail untouched. Every error leaves the entire destination unchanged. Capacity means slice length, not any underlying Vec capacity; there is no internal scratch packet or retained state.
Error precedence: session first (Hello has none); collection length before its elements; elements in slice order, fields in InputFrame::is_valid / PlayerSnapshot::is_valid order; each player validity before duplicate ID; snapshot orphan epochs in slot order after all players. Extension fields are checked in wire order (delta tick order before byte length; pong client, receive, send bounds before send ordering then five-second span). Whole packet bound follows field validation; destination capacity is always last. Unrestricted sequence/nonce/tick/shot_tick values remain unrestricted.
use ferravex_net::{ClientPacket, EncodeError, encode_client_into};
let packet = ClientPacket::Hello { nonce: 7 };
let mut bytes = [99; 16];
assert_eq!(encode_client_into(&packet, &mut bytes[..13]),
Err(EncodeError::Capacity { required: 14, available: 13 }));
assert_eq!(bytes, [99; 16]);
let n = encode_client_into(&packet, &mut bytes).unwrap();
assert_eq!(n, 14);
assert_eq!(&bytes[n..], &[99; 2]);