Skip to main content

ResponseFrame

Struct ResponseFrame 

Source
pub struct ResponseFrame<'a> {
    pub status: u32,
    pub request_id: u64,
    pub payload: &'a [u8],
}
Expand description

Decoded response frame with request ID for request-response correlation (the server framing).

Wire format: [status:4 LE][length:4 LE][request_id:8 LE][payload:N] where status = 0 for success, non-zero for error code.

Fields§

§status: u32§request_id: u64§payload: &'a [u8]

Implementations§

Source§

impl<'a> ResponseFrame<'a>

Source

pub const HEADER_SIZE: usize = 16

Size of the frame header: [status:4][length:4][request_id:8].

Source

pub fn decode(buf: &'a [u8]) -> Result<(Self, usize), WireError>

Decode a response frame from a complete buffer.

The length field covers request_id(8) + payload(N).

§Errors

Returns WireError::UnexpectedEof if the buffer is too short.

Source

pub fn encode_ok( request_id: u64, payload: &[u8], out: &mut BytesMut, ) -> Result<(), WireError>

Encode a successful response with payload.

The length field = 8 (request_id) + payload.len().

§Errors

Returns WireError::PayloadTooLarge if payload exceeds u32 capacity.

Source

pub fn encode_error(status: NonZeroU32, request_id: u64, out: &mut BytesMut)

Encode an error response (status code, no payload, preserves request_id).

Source

pub const fn is_ok(&self) -> bool

Returns true if this is a success response.

Source

pub const fn encoded_size(payload_len: usize) -> Option<usize>

Total encoded size for a given payload length.

Returns None if HEADER_SIZE + payload_len overflows usize.

Trait Implementations§

Source§

impl<'a> Debug for ResponseFrame<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ResponseFrame<'a>

§

impl<'a> RefUnwindSafe for ResponseFrame<'a>

§

impl<'a> Send for ResponseFrame<'a>

§

impl<'a> Sync for ResponseFrame<'a>

§

impl<'a> Unpin for ResponseFrame<'a>

§

impl<'a> UnsafeUnpin for ResponseFrame<'a>

§

impl<'a> UnwindSafe for ResponseFrame<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.