Struct strymon_communication::message::MessageBuf
[−]
[src]
pub struct MessageBuf { /* fields omitted */ }
A MessageBuf
represents a contiguous buffer of MessagePack
encoded objects. It can be used as a multi-part message to allow partial
deserialization. Partial messages can be inserted using the push
method
and are read in first-in, first-out order by the pop
method.
MessageBuf is a convenience wrapper around
bytes::BytesMut
and thus inherets the same properties: No allocation is required for small
objects; clones are reference-counted and implement copy-on-write semantics.
Methods
impl MessageBuf
[src]
pub fn new<S: Serialize>(item: S) -> Result<Self>
[src]
Create a new message buffer containing the serialized object.
pub fn empty() -> Self
[src]
Create a new, empty message.
Use one of the From
impls to construct a message from an already
existing buffer or object.
pub fn is_empty(&self) -> bool
[src]
Returns true if the contained bytes have a length of zero.
pub fn push<S: Serialize>(&mut self, item: S) -> Result<()>
[src]
Serialize and append an item to the message buffer.
pub fn pop<D: DeserializeOwned>(&mut self) -> Result<D>
[src]
Remove and deserialize the top item in the message buffer.
The object is not modified and kept in the buffer if deserialization fails.
The push
and pop
operations implement FIFO semantics.
pub fn peek<'de, D: Deserialize<'de>>(&'de self) -> Result<D>
[src]
Peek at the top item in the message buffer. This borrows the buffer for zero-copy deserialization.
pub fn write<W: Write>(&self, writer: &mut W) -> Result<()>
[src]
Copies the contained bytes into the provided writer.
Prepends the size of the message in bytes as a big-endian 32 bit unsigned integer.
pub fn read<R: Read>(reader: &mut R) -> Result<Option<MessageBuf>>
[src]
Reads a message from a reader, expecting a frame length prefix.
If first read of the message length field fails with an
ErrorKind::UnexpectedEof
then Ok(None)
is returned to indicate
that the reader closed gracefully. All other read errors, most notably
ErrorKind::WouldBlock
, are propagated verbatim.
Trait Implementations
impl Clone for MessageBuf
[src]
fn clone(&self) -> MessageBuf
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Debug for MessageBuf
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl PartialEq for MessageBuf
[src]
fn eq(&self, __arg_0: &MessageBuf) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &MessageBuf) -> bool
[src]
This method tests for !=
.