donet_core::datagram::datagram

Struct Datagram

source
pub struct Datagram {
    buffer: Vec<u8>,
    index: usize,
    cap: usize,
}
Expand description

Representation of a new network message (datagram) to be sent.

Fields§

§buffer: Vec<u8>§index: usize§cap: usize

Implementations§

source§

impl Datagram

source

fn check_add_length(&mut self, length: usize) -> Result<(), DatagramError>

Checks if we can add length number of bytes to the datagram.

source

pub fn override_cap(&mut self, cap: usize)

Overrides the byte limit for this Datagram.

It should always be set to the MAX of the size tag type (u16), but it can be overridden for special uses, such as processing large buffers that combine multiple TCP segments.

source

pub fn add_bool(&mut self, v: bool) -> Result<(), DatagramError>

Adds an unsigned 8-bit integer to the datagram that is guaranteed to be one of the values 0x00 (false) or 0x01 (true).

source

pub fn add_u8(&mut self, v: u8) -> Result<(), DatagramError>

Adds an unsigned 8-bit integer value to the datagram.

source

pub fn add_u16(&mut self, v: u16) -> Result<(), DatagramError>

Adds an unsigned 16-bit integer value to the datagram.

source

pub fn add_u32(&mut self, v: u32) -> Result<(), DatagramError>

Adds an unsigned 32-bit integer value to the datagram.

source

pub fn add_u64(&mut self, v: u64) -> Result<(), DatagramError>

Adds an unsigned 64-bit integer value to the datagram.

source

pub fn add_i8(&mut self, v: i8) -> Result<(), DatagramError>

source

pub fn add_i16(&mut self, v: i16) -> Result<(), DatagramError>

source

pub fn add_i32(&mut self, v: i32) -> Result<(), DatagramError>

source

pub fn add_i64(&mut self, v: i64) -> Result<(), DatagramError>

source

pub fn add_f32(&mut self, v: f32) -> Result<(), DatagramError>

32-bit IEEE 754 floating point. same bitwise operations.

source

pub fn add_f64(&mut self, v: f64) -> Result<(), DatagramError>

64-bit IEEE 754 floating point. same bitwise operations.

source

pub fn add_size(&mut self, v: DgSizeTag) -> Result<(), DatagramError>

Adds a Datagram / Field length tag to the end of the datagram.

source

pub fn add_channel(&mut self, v: Channel) -> Result<(), DatagramError>

Adds a 64-bit channel ID to the end of the datagram.

source

pub fn add_doid(&mut self, v: DoId) -> Result<(), DatagramError>

Adds a 32-bit Distributed Object ID to the end of the datagram.

source

pub fn add_zone(&mut self, v: Zone) -> Result<(), DatagramError>

Adds a 32-bit zone ID to the end of the datagram.

source

pub fn add_location( &mut self, parent: DoId, zone: Zone, ) -> Result<(), DatagramError>

Added for convenience, rather than adding the parent and the zone separately.

source

pub fn add_data(&mut self, bytes: Vec<u8>) -> Result<(), DatagramError>

Adds raw bytes to the datagram via an unsigned 8-bit integer vector.

NOTE: not to be confused with Datagram::add_blob, which adds a dclass blob to the datagram.

source

pub fn add_string(&mut self, str: &str) -> Result<(), DatagramError>

Adds a dclass string value to the end of the datagram. A 16-bit length tag prefix with the string’s size in bytes is added.

source

pub fn add_blob(&mut self, bytes: Vec<u8>) -> Result<(), DatagramError>

Adds a dclass blob value (binary data) to the end of the datagram. A 16-bit length tag prefix with the blob’s size in bytes is added.

source

pub fn add_buffer(&mut self, size: usize) -> Result<usize, DatagramError>

Reserves an amount of bytes in the datagram buffer.

source

pub fn add_internal_header( &mut self, recipients: Vec<Channel>, sender: Channel, msg_type: MsgType, ) -> Result<(), DatagramError>

Appends a generic header for messages that are to be routed to one or more role instances within the server cluster.

Use this method to avoid repetitive code for every internal message.

The header is formatted as shown below:

(recipients: u8, recipients: Vec<Channel>, sender: [globals::Channel], message_type: u16)

§Errors

It is an error for the given recipients vector to have a size larger than std::u8::MAX. Else, DatagramError::ImpossibleCast will be returned.

source

pub fn add_control_header( &mut self, msg_type: MsgType, ) -> Result<(), DatagramError>

Appends a control header, which is very similar to a server header, but it always has only one recipient, which is the control channel, and does not require a sender (or ‘from’) channel to be provided.

The sender field is not required as control messages are not routed, meaning that the message director will ONLY receive this message DIRECTLY from a cluster subscriber, so it can be speculated that the sender is the participant on the other end of the connection.

source

pub fn size(&self) -> usize

Returns the size of this Datagram.

source

pub fn get_buffer(&self) -> &[u8]

Returns a reference to this Datagram’s byte buffer.

source

pub fn get_data(&self) -> Vec<u8>

Similar to Self::get_buffer, but returns a copy of the buffer.

Trait Implementations§

source§

impl Add for Datagram

Appends another datagram’s raw bytes to this datagram.

Consumes the right-hand-side Datagram.

source§

type Output = Result<Datagram, DatagramError>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl Clone for Datagram

source§

fn clone(&self) -> Datagram

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Datagram

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Datagram

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl From<Datagram> for DatagramIterator

Create a new DatagramIterator from a Datagram.

source§

fn from(value: Datagram) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.