Struct onc_rpc::RpcMessage
source · pub struct RpcMessage<T, P>{ /* private fields */ }
Expand description
An Open Network Computing RPC message, generic over a source of bytes (T
)
and a payload buffer (P
).
Implementations§
source§impl<'a> RpcMessage<&'a [u8], &'a [u8]>
impl<'a> RpcMessage<&'a [u8], &'a [u8]>
sourcepub fn from_bytes(buf: &'a [u8]) -> Result<Self, Error>
👎Deprecated since 0.3.0: prefer the TryFrom
impl instead
pub fn from_bytes(buf: &'a [u8]) -> Result<Self, Error>
TryFrom
impl insteadDeserialises a new RpcMessage
from buf
.
Buf must contain exactly 1 message - if buf
contains an incomplete
message, or buf
contains trailing bytes after the message
Error::IncompleteMessage
is returned.
source§impl<T, P> RpcMessage<T, P>
impl<T, P> RpcMessage<T, P>
sourcepub fn new(xid: u32, message_type: MessageType<T, P>) -> Self
pub fn new(xid: u32, message_type: MessageType<T, P>) -> Self
Construct a new RpcMessage
with the specified transaction ID and
message body.
sourcepub fn serialise_into<W: Write>(&self, buf: W) -> Result<(), Error>
pub fn serialise_into<W: Write>(&self, buf: W) -> Result<(), Error>
Write this RpcMessage
into buf
, advancing the cursor to the end of
the serialised message. buf
must have capacity for at least
RpcMessage::serialised_len()
bytes from the current cursor position.
This method allows the caller to specify the underlying buffer used to hold the serialised message to enable reuse and pooling.
sourcepub fn serialise(&self) -> Result<Vec<u8>, Error>
pub fn serialise(&self) -> Result<Vec<u8>, Error>
Serialise this RpcMessage
into a new Vec
.
The returned vec will be sized exactly to contain this message. Calling this method is the equivalent of:
let mut buf = Vec::with_capacity(msg.serialised_len() as usize);
let mut c = Cursor::new(buf);
msg.serialise_into(&mut c);
sourcepub fn serialised_len(&self) -> u32
pub fn serialised_len(&self) -> u32
Returns the on-wire length of this message once serialised, including the message header.
sourcepub fn message(&self) -> &MessageType<T, P>
pub fn message(&self) -> &MessageType<T, P>
The MessageType
contained in this request.
sourcepub fn call_body(&self) -> Option<&CallBody<T, P>>
pub fn call_body(&self) -> Option<&CallBody<T, P>>
Returns the CallBody
in this request, or None
if this message is
not a RPC call request.
sourcepub fn reply_body(&self) -> Option<&ReplyBody<T, P>>
pub fn reply_body(&self) -> Option<&ReplyBody<T, P>>
Returns the ReplyBody
in this request, or None
if this message is
not a RPC response.
Trait Implementations§
source§impl<T, P> Debug for RpcMessage<T, P>
impl<T, P> Debug for RpcMessage<T, P>
source§impl<T, P> PartialEq for RpcMessage<T, P>
impl<T, P> PartialEq for RpcMessage<T, P>
source§fn eq(&self, other: &RpcMessage<T, P>) -> bool
fn eq(&self, other: &RpcMessage<T, P>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> TryFrom<&'a [u8]> for RpcMessage<&'a [u8], &'a [u8]>
impl<'a> TryFrom<&'a [u8]> for RpcMessage<&'a [u8], &'a [u8]>
source§fn try_from(v: &'a [u8]) -> Result<Self, Self::Error>
fn try_from(v: &'a [u8]) -> Result<Self, Self::Error>
Deserialises a new RpcMessage
from buf
.
Buf must contain exactly 1 message - if buf
contains an incomplete
message, or buf
contains trailing bytes after the message
Error::IncompleteMessage
is returned.