pub struct FrameCodec { /* private fields */ }Expand description
Encodes and decodes WSCALL binary frames.
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 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.
Sourcepub fn decode(&self, frame: &[u8]) -> Result<PacketEnvelope, ProtocolError>
pub fn decode(&self, frame: &[u8]) -> Result<PacketEnvelope, ProtocolError>
Decodes a binary WSCALL frame back into an envelope.
Trait Implementations§
Source§impl Clone for FrameCodec
impl Clone for FrameCodec
Source§fn clone(&self) -> FrameCodec
fn clone(&self) -> FrameCodec
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FrameCodec
impl Debug for FrameCodec
Source§impl Default for FrameCodec
impl Default for FrameCodec
Source§fn default() -> FrameCodec
fn default() -> FrameCodec
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for FrameCodec
impl RefUnwindSafe for FrameCodec
impl Send for FrameCodec
impl Sync for FrameCodec
impl Unpin for FrameCodec
impl UnsafeUnpin for FrameCodec
impl UnwindSafe for FrameCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more