pub struct FrameCodec { /* private fields */ }Expand description
Encodes and decodes WSCALL binary frames (protocol v2).
Protocol v2 uses a composite payload format: JSON metadata followed by raw binary attachment sections, eliminating the Base64 overhead of protocol v1.
The symmetric ciphers are constructed once when a key is configured and shared
via Arc across every clone of the codec. This avoids redoing the key
schedule (which for AES-256-GCM is especially expensive) on every frame.
Implementations§
Source§impl FrameCodec
impl FrameCodec
Sourcepub fn with_chacha20_key(self, key: [u8; 32]) -> Self
pub fn with_chacha20_key(self, key: [u8; 32]) -> Self
Configures a ChaCha20-Poly1305 key.
The cipher is constructed eagerly so that subsequent frame encoding never pays for the key schedule again.
Sourcepub fn with_aes256_key(self, key: [u8; 32]) -> Self
pub fn with_aes256_key(self, key: [u8; 32]) -> Self
Configures an AES256-GCM key.
The cipher is constructed eagerly so that subsequent frame encoding never pays for the AES key expansion again.
Sourcepub fn with_max_frame_bytes(self, max: usize) -> Self
pub fn with_max_frame_bytes(self, max: usize) -> Self
Sets the maximum total frame size (including the 4-byte length prefix).
Frames exceeding this limit are rejected during encode/decode.
Sourcepub fn max_frame_bytes(&self) -> usize
pub fn max_frame_bytes(&self) -> usize
Returns the configured maximum frame size.
Sourcepub fn encode(&self, packet: &PacketEnvelope) -> Result<Vec<u8>, ProtocolError>
pub fn encode(&self, packet: &PacketEnvelope) -> Result<Vec<u8>, ProtocolError>
Encodes an envelope into a binary WSCALL frame (protocol v2 composite format).
The composite payload layout (before encryption):
| meta_len:u32(be) | JSON_bytes | att_count:u8 | [att sections...] |Sourcepub fn decode(&self, frame: Bytes) -> Result<PacketEnvelope, ProtocolError>
pub fn decode(&self, frame: Bytes) -> Result<PacketEnvelope, ProtocolError>
Decodes a binary WSCALL frame back into an envelope (protocol v2 composite format).
Accepts Bytes so that plaintext attachment payloads can be extracted
via zero-copy slicing of the original buffer (no intermediate Vec).
Trait Implementations§
Source§impl Clone for FrameCodec
impl Clone for FrameCodec
Source§fn clone(&self) -> FrameCodec
fn clone(&self) -> FrameCodec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more