Struct zmq::Message [−][src]
pub struct Message { /* fields omitted */ }
Holds a 0MQ message.
A message is a single frame, either received or created locally and then
sent over the wire. Multipart messages are transmitted as multiple
Message
s.
In rust-zmq, you aren’t required to create message objects if you use the
convenience APIs provided (e.g. Socket::recv_bytes()
or
Socket::send()
). However, using message objects can make multiple
operations in a loop more efficient, since allocated memory can be reused.
Implementations
impl Message
[src]
impl Message
[src]pub fn new() -> Message
[src][−]
Create an empty Message
.
pub unsafe fn with_capacity_unallocated(len: usize) -> Message
[src][−]
This method has an unintuitive name, and should not be needed.
Create a Message
preallocated with len
uninitialized bytes.
Since it is very easy to introduce undefined behavior using this function, its use is not recommended, and it will be removed in a future release. If there is a use-case that cannot be handled efficiently by the safe message constructors, please file an issue.
pub fn with_size(len: usize) -> Message
[src][−]
Create a Message
with space for len
bytes that are initialized to 0.
pub fn with_capacity(len: usize) -> Message
[src][−]
This method has a name which does not match its semantics. Use with_size
instead
Create a Message
with space for len
bytes that are initialized to 0.
pub fn from_slice(data: &[u8]) -> Message
[src][−]
Use the From
trait instead.
Create a Message
from a &[u8]
. This will copy data
into the message.
This is equivalent to using the From<&[u8]>
trait.
pub fn as_str(&self) -> Option<&str>
[src][−]
Return the message content as a string slice if it is valid UTF-8.
pub fn get_more(&self) -> bool
[src][−]
Return the ZMQ_MORE
flag, which indicates if more parts of a multipart
message will follow.
pub fn gets<'a>(&'a mut self, property: &str) -> Option<&'a str>
[src][−]
Query a message metadata property.
Non-UTF8 values
The zmq_msg_gets
man page notes “The encoding of the property and
value shall be UTF8”. However, this is not actually enforced. For API
compatibility reasons, this function will return None
when
encountering a non-UTF8 value; so a missing and a non-UTF8 value cannot
currently be distinguished.
This is considered a bug in the bindings, and will be fixed with the next API-breaking release.