frame_packet_to

Function frame_packet_to 

Source
pub fn frame_packet_to(buf: &[u8], out: &mut [u8]) -> Option<usize>
Expand description

Adds RFC 4571 framing header to a packet, writing into a provided buffer.

Returns the total number of bytes written (header + payload).

§Arguments

  • buf - The packet data to frame
  • out - Output buffer (must be at least buf.len() + 2 bytes)

§Returns

  • Some(n) - Total bytes written to out
  • None - If out is too small or buf exceeds max size

§Example

use rtc_shared::tcp_framing::frame_packet_to;

let packet = b"Hello";
let mut out = [0u8; 100];

let n = frame_packet_to(packet, &mut out).unwrap();
assert_eq!(n, 7); // 2 byte header + 5 byte payload