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
impl Message
pub fn new( header: Header, query: Vec<u8>, body: Vec<u8>, ) -> Result<Self, RepeError>
pub fn builder() -> MessageBuilder
pub fn to_vec(&self) -> Vec<u8> ⓘ
Sourcepub fn serialized_len(&self) -> usize
pub fn serialized_len(&self) -> usize
Wire size of the serialized message: HEADER_SIZE + query.len() + body.len().
O(1); does not serialize.
Sourcepub fn write_to<W: Write>(&self, w: &mut W) -> Result<()>
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).
Sourcepub fn into_wire_bytes(self) -> Vec<u8> ⓘ
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.
pub fn from_slice(buf: &[u8]) -> Result<Self, RepeError>
pub fn from_slice_exact(buf: &[u8]) -> Result<Self, RepeError>
pub fn is_error(&self) -> bool
pub fn error_code(&self) -> Option<ErrorCode>
pub fn error_message_utf8(&self) -> Option<String>
pub fn query_utf8(&self) -> String
pub fn query_str(&self) -> Result<&str, Utf8Error>
pub fn body_utf8(&self) -> String
pub fn json_body<T: DeserializeOwned>(&self) -> Result<T, RepeError>
pub fn beve_body<T: DeserializeOwned>(&self) -> Result<T, RepeError>
Sourcepub fn decode_typed_slice<T: BeveTypedSlice>(&self) -> Result<Vec<T>, RepeError>
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>.
Sourcepub fn decode_complex_slice<T: BeveTypedSlice>(
&self,
) -> Result<Vec<Complex<T>>, RepeError>
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.