Skip to main content

CallBuf

Struct CallBuf 

Source
pub struct CallBuf { /* private fields */ }
Expand description

Payload of an outgoing RPC call, with room reserved ahead of it for the record mark and call header the driver writes when it sends the call.

Encoding arguments straight into a CallBuf lets the driver frame the call in place: it fills the reserved prefix and hands the buffer to the socket without copying or shifting the payload. Callers read only the payload; append_with hands a serializer the record buffer to extend in place, with the prefix kept reserved.

Implementations§

Source§

impl CallBuf

Source

pub const PREFIX_LEN: usize

Bytes reserved ahead of the payload: a 4-byte record mark and the 40-byte RFC 5531 CALL header with AUTH_NONE credentials and verifier. The driver only ever sends that header, so this is a constant of the wire format.

Source

pub fn new() -> Self

Buffer with an empty payload.

Prefer RpcSender::call_buf, which recycles a spent buffer instead of allocating. There is deliberately no Default: a buffer should come from a sender unless there is none.

Source

pub fn append_with<R>(&mut self, f: impl FnOnce(&mut Vec<u8>) -> R) -> R

Append to the payload through the record buffer itself.

f receives the whole record Vec<u8>, the reserved prefix followed by the payload so far, appends to it, and its return value is passed back. Generated protocol clients serialize their argument tuple this way, straight into the buffer with the XDR serializer they were generated against, so the driver sends the record without copying it and this crate carries no serializer dependency of its own.

f must only append. The buffer is kept at least PREFIX_LEN long afterwards, so an f that shortens it cannot unreserve the prefix; the driver overwrites the prefix bytes when it frames the call, so their contents never matter.

Source

pub fn payload(&self) -> &[u8] ⓘ

The payload bytes.

Source

pub fn extend_from_slice(&mut self, bytes: &[u8])

Append bytes to the payload.

Trait Implementations§

Source§

impl Debug for CallBuf

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.