Struct connect::ConnectDatagram[][src]

pub struct ConnectDatagram { /* fields omitted */ }

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]

impl Sink<ConnectDatagram> for ConnectionWriter[src]

type Error = ConnectionWriteError

The type of value produced by the sink when an error occurs.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.