pub struct FrameBuilder { /* private fields */ }Expand description
Builder for RedWire Frames.
Construct with FrameBuilder::request for client requests,
FrameBuilder::reply_to for response frames (carries the
request’s correlation id), or FrameBuilder::unsolicited for
server-initiated frames (correlation id 0). All other fields are
optional.
Implementations§
Source§impl FrameBuilder
impl FrameBuilder
Sourcepub fn request(correlation_id: u64) -> Self
pub fn request(correlation_id: u64) -> Self
Client request frame. Carries the caller’s new correlation id so the server can echo it in its reply.
Sourcepub fn reply_to(correlation_id: u64) -> Self
pub fn reply_to(correlation_id: u64) -> Self
Reply to a request frame. Echoes the caller’s correlation id so the client can pair the response with the request.
Sourcepub fn unsolicited() -> Self
pub fn unsolicited() -> Self
Server-initiated frame with no request to echo (correlation
id 0). Used for notices, unsolicited Bye, etc.
pub fn kind(self, kind: MessageKind) -> Self
pub fn payload(self, payload: Vec<u8>) -> Self
pub fn stream_id(self, stream_id: u16) -> Self
Sourcepub fn flags(self, flags: Flags) -> Self
pub fn flags(self, flags: Flags) -> Self
Replace the flag set wholesale. Most callers should prefer
Self::more_frames / Self::compress over poking flags
directly — this exists for the Cancel / Compress / Notice
control frames that carry caller-defined bits.
Sourcepub fn more_frames(self, more: bool) -> Self
pub fn more_frames(self, more: bool) -> Self
Mark this frame as part of a multi-frame reply. Pass false
(the default) on the last frame of the burst — the
MORE_FRAMES last-frame invariant is enforced at build()
time by the flag bit.
Sourcepub fn compress(self, yes: bool) -> Self
pub fn compress(self, yes: bool) -> Self
Request that the encoder zstd-compress the payload. The
codec falls back to plaintext + cleared flag if the payload
is incompressible (see Self::build).
Sourcepub fn build(self) -> Result<Frame, BuildError>
pub fn build(self) -> Result<Frame, BuildError>
Finalize the frame.
Enforces:
kind()was set (otherwiseBuildError::KindMissing).- Plaintext encoded size <=
MAX_FRAME_SIZE(otherwiseBuildError::PayloadTooLarge) — checked against the plaintext payload, since the wire form after compression can only shrink. MORE_FRAMESflag mirrors themore_frames(bool)call.COMPRESSEDflag is set only when compression was requested and the payload looks compressible. A trivial incompressibility heuristic (“the payload is empty or too short for zstd to reduce”) drops the flag here so the encoded bytes match the flag.