Skip to main content

Message

Struct Message 

Source
pub struct Message {
    pub header: Header,
    pub query: Vec<u8>,
    pub body: Vec<u8>,
}

Fields§

§header: Header§query: Vec<u8>§body: Vec<u8>

Implementations§

Source§

impl Message

Source

pub fn new( header: Header, query: Vec<u8>, body: Vec<u8>, ) -> Result<Self, RepeError>

Source

pub fn builder() -> MessageBuilder

Source

pub fn to_vec(&self) -> Vec<u8> ⓘ

Source

pub fn serialized_len(&self) -> usize

Wire size of the serialized message: HEADER_SIZE + query.len() + body.len(). O(1); does not serialize.

Source

pub fn write_to<W: Write>(&self, w: &mut W) -> Result<()>

Write the message to w without allocating an intermediate frame buffer.

Equivalent to w.write_all(&self.to_vec()) byte-for-byte, but emits the header, query, and body in three writes instead of building a single owned Vec<u8>. Useful when the body is large (e.g. multi-MiB chunks).

Source

pub fn into_wire_bytes(self) -> Vec<u8> ⓘ

Consume the message and produce its wire-frame bytes.

Prefer this over to_vec on outbound paths where the Message is being shipped to a sink that takes an owned Vec<u8> (e.g. the WebSocket writer): to_vec always allocates a fresh frame buffer and copies the body into it, whereas into_wire_bytes reuses the body allocation when it already has the spare capacity to host the header and query prefix.

Fast path (zero new allocations, one body memcpy to shift to the back): triggers when body.capacity() >= HEADER_SIZE + query.len() + body.len(). Callers that care about streaming throughput can guarantee the fast path by constructing the body via Vec::with_capacity(body_len + HEADER_SIZE + query.len()) and then passing it to MessageBuilder::body_bytes.

Slow path: when the body has no spare capacity for the prefix, a fresh Vec<u8> is allocated. The byte output is identical to to_vec.

Source

pub fn from_slice(buf: &[u8]) -> Result<Self, RepeError>

Source

pub fn from_slice_exact(buf: &[u8]) -> Result<Self, RepeError>

Source

pub fn is_error(&self) -> bool

Source

pub fn error_code(&self) -> Option<ErrorCode>

Source

pub fn error_message_utf8(&self) -> Option<String>

Source

pub fn query_utf8(&self) -> String

Source

pub fn query_str(&self) -> Result<&str, Utf8Error>

Source

pub fn body_utf8(&self) -> String

Source

pub fn json_body<T: DeserializeOwned>(&self) -> Result<T, RepeError>

Source

pub fn beve_body<T: DeserializeOwned>(&self) -> Result<T, RepeError>

Source

pub fn decode_typed_slice<T: BeveTypedSlice>(&self) -> Result<Vec<T>, RepeError>

Decode a BEVE typed-numeric-array body into a Vec<T> via a single bounds-checked bulk read, bypassing serde.

The decode counterpart of MessageBuilder::body_typed_slice, and the whole-body fast path for a high-throughput numeric payload. Errors with RepeError::UnexpectedBodyFormat if the body is not BodyFormat::Beve, or RepeError::Beve if the bytes are not a typed numeric array of T (wrong element class/width, or a truncated payload). Works on any BEVE typed numeric array, including one produced by serde via body_beve over a Vec<T>.

Source

pub fn decode_complex_slice<T: BeveTypedSlice>( &self, ) -> Result<Vec<Complex<T>>, RepeError>

Decode a BEVE complex-array body into a Vec<Complex<T>> via a single bounds-checked bulk read, bypassing serde.

The complex counterpart of decode_typed_slice and the decode counterpart of MessageBuilder::body_complex_slice. Same error contract.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Message

Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Message

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<R> IntoTypedResponse<R> for R

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V