pub struct FrameBuilder { /* private fields */ }Expand description
Builder for server-emitted Frames.
Construct with 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 reply_to(correlation_id: u64) -> FrameBuilder
pub fn reply_to(correlation_id: u64) -> FrameBuilder
Reply to a request frame. Echoes the caller’s correlation id so the client can pair the response with the request.
Sourcepub fn unsolicited() -> FrameBuilder
pub fn unsolicited() -> FrameBuilder
Server-initiated frame with no request to echo (correlation
id 0). Used for notices, unsolicited Bye, etc.
pub fn kind(self, kind: MessageKind) -> FrameBuilder
pub fn payload(self, payload: Vec<u8>) -> FrameBuilder
pub fn stream_id(self, stream_id: u16) -> FrameBuilder
Sourcepub fn flags(self, flags: Flags) -> FrameBuilder
pub fn flags(self, flags: Flags) -> FrameBuilder
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) -> FrameBuilder
pub fn more_frames(self, more: bool) -> FrameBuilder
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) -> FrameBuilder
pub fn compress(self, yes: bool) -> FrameBuilder
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.
Trait Implementations§
Source§impl Clone for FrameBuilder
impl Clone for FrameBuilder
Source§fn clone(&self) -> FrameBuilder
fn clone(&self) -> FrameBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for FrameBuilder
impl RefUnwindSafe for FrameBuilder
impl Send for FrameBuilder
impl Sync for FrameBuilder
impl Unpin for FrameBuilder
impl UnsafeUnpin for FrameBuilder
impl UnwindSafe for FrameBuilder
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request