Skip to main content

Module framing

Module framing 

Source
Available on crate feature std and non-WebAssembly only.
Expand description

Zero-Copy TCP Framing Pipeline

Problem: the old approach did data.clone() + encrypt_in_place() + write(len) + write(data) = 2 syscalls + 1 clone per message. TLS 1.3 (rustls) does the equivalent in a single internal write.

Solution: prepend a 4-byte length header, encrypt the payload in place into the same buffer, then issue a single write_all() — one syscall, no clone. Multiple chunks / frames are coalesced into one buffer before the write.

NOTE: this is a helper for the native TCP path; the production SessionTransport over TCP is TcpSessionTransport (in api/tcp_transport.rs), which carries the same 4-byte big-endian length prefix. PhantomUDP does its own framing elsewhere.

Structs§

FrameReader
Zero-copy frame reader — reads and decrypts from TCP stream
FrameWriter
Zero-copy frame writer — encrypts and writes in a single syscall

Enums§

FrameError
Frame errors

Constants§

FRAME_HEADER_SIZE
Frame header size: 4 bytes for payload length (u32 BE)
MAX_FRAME_PAYLOAD
Maximum frame payload size (before encryption)