Struct connect::ConnectDatagram [−][src]
A simple size-prefixed packet format containing a version tag, recipient tag, and message body.
The version tag is decided by the library version and used to maintain backwards compatibility with previous datagram formats.
Implementations
impl ConnectDatagram
[src]
pub fn new(recipient: u16, data: Vec<u8>) -> Result<Self, DatagramError>
[src]
Creates a new ConnectDatagram
based on an intended recipient and message body.
The version tag is decided by the library version and used to maintain backwards compatibility with previous datagram formats.
This will return a EmptyMessage error if the data
parameter contains no bytes, or in other words, when there is no message body.
This will return a TooLargeMessage error if the data
parameter contains a buffer size greater than 100,000,000 (bytes), or 100MB.
pub fn version(&self) -> u16
[src]
Gets the version number of the datagram.
pub fn recipient(&self) -> u16
[src]
Gets the recipient of the datagram.
pub fn data(&self) -> Option<&Vec<u8>>
[src]
Gets the message body of the datagram.
pub fn take_data(&mut self) -> Option<Vec<u8>>
[src]
Takes ownership of the message body of the datagram.
pub fn size(&self) -> usize
[src]
Calculates the size-prefixed serialized byte-size of the datagram.
This will include the byte-size of the size-prefix.
pub fn encode(self) -> Vec<u8>
[src]
Serializes the datagram.
pub fn decode(buffer: Vec<u8>) -> Result<Self, DatagramError>
[src]
Deserializes the datagram from a buffer.
The buffer should not contain the size-prefix, and only contain the byte contents of the struct (version, recipient, and message body).
Trait Implementations
impl Clone for ConnectDatagram
[src]
fn clone(&self) -> ConnectDatagram
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Sink<ConnectDatagram> for ConnectionWriter
[src]
type Error = ConnectionWriteError
The type of value produced by the sink when an error occurs.
fn poll_ready(
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
_cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn start_send(
self: Pin<&mut Self>,
item: ConnectDatagram
) -> Result<(), Self::Error>
[src]
self: Pin<&mut Self>,
item: ConnectDatagram
) -> Result<(), Self::Error>
fn poll_flush(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
fn poll_close(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Result<(), Self::Error>>
Auto Trait Implementations
impl RefUnwindSafe for ConnectDatagram
[src]
impl Send for ConnectDatagram
[src]
impl Sync for ConnectDatagram
[src]
impl Unpin for ConnectDatagram
[src]
impl UnwindSafe for ConnectDatagram
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,