pub struct Frame {
pub opcode: u16,
pub flags: u8,
pub stream_id: u32,
pub payload: Vec<u8>,
}Expand description
A decoded frame: header fields + the raw payload bytes (CBOR section plus any trailing raw-vector section, undivided at this layer).
Fields§
§opcode: u16§flags: u8§stream_id: u32§payload: Vec<u8>Implementations§
Source§impl Frame
impl Frame
Sourcepub fn new(opcode: u16, flags: u8, stream_id: u32, payload: Vec<u8>) -> Self
pub fn new(opcode: u16, flags: u8, stream_id: u32, payload: Vec<u8>) -> Self
Build a frame from its parts.
Sourcepub fn encode(&self) -> Result<Vec<u8>, FrameError>
pub fn encode(&self) -> Result<Vec<u8>, FrameError>
Serialize the frame to a wire-ready byte vector: the 32-byte header with both CRC32C fields computed, followed by the payload.
§Errors
FrameError::OversizePayload if payload.len() exceeds
MAX_PAYLOAD_BYTES — the u24 length field physically cannot
represent more.
This returns rather than panics because the length is caller data: a
caller encoding a large document would otherwise take down the process
(or abort the task) instead of getting an error they can handle. Python
raises OversizePayload and TypeScript throws FrameError for the same
input; this SDK used to be the only one that panicked.
§Panics
Never. The one expect below slices the first HEADER_SIZE bytes of a
buffer this function just allocated as HEADER_SIZE + payload.len(), so
the conversion cannot fail; it documents an invariant rather than
guarding a reachable case.
Sourcepub fn decode(bytes: &[u8]) -> Result<(Frame, &[u8]), FrameError>
pub fn decode(bytes: &[u8]) -> Result<(Frame, &[u8]), FrameError>
Decode a single frame off the front of bytes, returning the
frame and the unconsumed tail so a caller can loop over a stream.
Validates magic / version / reserved bytes / reserved flag bits,
verifies the header CRC, then checks payload_len against
MAX_PAYLOAD_BYTES before slicing the payload, and finally
verifies the payload CRC.
§Panics
Never. The slice indexing below is all bounds-checked against
HEADER_SIZE and payload_len before it runs.