Struct middleman::PackedMessage
[−]
[src]
pub struct PackedMessage(_);
This structure represents the serialized form of some Message
-implementing structure.
Dealing with a PackedMessage may be suitable when:
(1) You need to send/store/receive a message but don't need to actually use it yourself.
(2) You want to serialize a message once, and send it multiple times.
(3) You want to read and discard a message whose type is unknown.
NOTE: The packed message maps 1:1 with the bytes that travel over the TcpStream. As such,
packed messages also contain the 4-byte length preable. The user is discocuraged from
manipulating the contents of a packed message. The recv
statement relies on consistency
of packed messages
Methods
impl PackedMessage
[src]
pub fn new<M: Message>(m: &M) -> Result<Self, PackingError>
[src]
Create a new PakcedMessage from the given Message
-implementing struct
pub fn unpack<M: Message>(&self) -> Result<M, Box<ErrorKind>>
[src]
Attempt to unpack this Packedmessage given a type hint. This may fail if the PackedMessage isn't internally consistent or the type doesn't match that of the type used for serialization.
pub fn into_raw(self) -> Vec<u8>
[src]
Unwrap the byte buffer comprising this PackedMessage
pub fn from_raw(v: Vec<u8>) -> Self
[src]
Accept the given byte buffer as the basis for a PackedMessage
WARNING: Use this at your own risk! The recv
functions and their variants rely on
the correct contents of messages to work correcty.
NOTE: The first 4 bytes of a the buffer are used to store the length of the payload.
pub fn byte_len(&self) -> usize
[src]
Return the number of bytes this packed message contains. Maps 1:1 with the bit complexity of the message sent over the network.
pub fn get_raw(&self) -> &Vec<u8>
[src]
Acquire an immutable reference to the internal buffer of the packed message.
pub fn get_mut_raw(&mut self) -> &mut Vec<u8>
[src]
Acquire a mutable reference to the internal buffer of the packed message.
WARNING: Contents of a PackedMessage represent a delicata internal state. Sending an internally inconsistent PackedMessage will compromise the connection. Use at your own risk!