pub struct FrameCodec;Expand description
Provides encoding and decoding functionality for frames.
The FrameCodec is responsible for serializing a Frame into a byte stream and
deserializing a byte stream back into a Frame. It handles the creation and parsing
of the frame header, ensuring the correct encoding of all frame fields such as stream ID,
sequence ID, kind, timestamp, and payload.
This is used to package and unpack frames for transmission across a stream, ensuring that all necessary metadata is included alongside the actual payload.
Implementations§
Source§impl FrameCodec
impl FrameCodec
Sourcepub fn encode(frame: &Frame) -> Vec<u8> ⓘ
pub fn encode(frame: &Frame) -> Vec<u8> ⓘ
Encodes a Frame into a byte vector.
This method serializes the Frame’s metadata and payload into a byte stream.
The resulting vector can be transmitted over the stream or saved to a buffer.
§Arguments
frame- TheFrameto be encoded.
§Returns
Returns a vector of bytes that represents the encoded frame. The frame consists of the frame’s length, stream ID, sequence ID, kind, timestamp, and payload.
Sourcepub fn decode(buf: &[u8]) -> Result<DecodedFrame, FrameDecodeError>
pub fn decode(buf: &[u8]) -> Result<DecodedFrame, FrameDecodeError>
Decodes a byte slice into a Frame.
This method takes a byte buffer representing a serialized frame and attempts to parse it
back into a Frame struct. It checks the integrity of the frame, ensuring that the buffer
contains enough data and that all fields can be correctly interpreted.
§Arguments
buf- A byte slice representing the frame to decode.
§Returns
Returns a Result where:
Ok(Frame)contains the decodedFrameobject.Err(FrameStreamError)contains an error if the frame is corrupted or malformed.
The method will return an error if the buffer is too short or if the frame data does not conform to the expected structure.