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
impl Datagram
sourcefn check_add_length(&mut self, length: usize) -> Result<(), DatagramError>
fn check_add_length(&mut self, length: usize) -> Result<(), DatagramError>
Checks if we can add length
number of bytes to the datagram.
sourcepub fn override_cap(&mut self, cap: usize)
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.
sourcepub fn add_bool(&mut self, v: bool) -> Result<(), DatagramError>
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).
sourcepub fn add_u8(&mut self, v: u8) -> Result<(), DatagramError>
pub fn add_u8(&mut self, v: u8) -> Result<(), DatagramError>
Adds an unsigned 8-bit integer value to the datagram.
sourcepub fn add_u16(&mut self, v: u16) -> Result<(), DatagramError>
pub fn add_u16(&mut self, v: u16) -> Result<(), DatagramError>
Adds an unsigned 16-bit integer value to the datagram.
sourcepub fn add_u32(&mut self, v: u32) -> Result<(), DatagramError>
pub fn add_u32(&mut self, v: u32) -> Result<(), DatagramError>
Adds an unsigned 32-bit integer value to the datagram.
sourcepub fn add_u64(&mut self, v: u64) -> Result<(), DatagramError>
pub fn add_u64(&mut self, v: u64) -> Result<(), DatagramError>
Adds an unsigned 64-bit integer value to the datagram.
pub fn add_i8(&mut self, v: i8) -> Result<(), DatagramError>
pub fn add_i16(&mut self, v: i16) -> Result<(), DatagramError>
pub fn add_i32(&mut self, v: i32) -> Result<(), DatagramError>
pub fn add_i64(&mut self, v: i64) -> Result<(), DatagramError>
sourcepub fn add_f32(&mut self, v: f32) -> Result<(), DatagramError>
pub fn add_f32(&mut self, v: f32) -> Result<(), DatagramError>
32-bit IEEE 754 floating point. same bitwise operations.
sourcepub fn add_f64(&mut self, v: f64) -> Result<(), DatagramError>
pub fn add_f64(&mut self, v: f64) -> Result<(), DatagramError>
64-bit IEEE 754 floating point. same bitwise operations.
sourcepub fn add_size(&mut self, v: DgSizeTag) -> Result<(), DatagramError>
pub fn add_size(&mut self, v: DgSizeTag) -> Result<(), DatagramError>
Adds a Datagram / Field length tag to the end of the datagram.
sourcepub fn add_channel(&mut self, v: Channel) -> Result<(), DatagramError>
pub fn add_channel(&mut self, v: Channel) -> Result<(), DatagramError>
Adds a 64-bit channel ID to the end of the datagram.
sourcepub fn add_doid(&mut self, v: DoId) -> Result<(), DatagramError>
pub fn add_doid(&mut self, v: DoId) -> Result<(), DatagramError>
Adds a 32-bit Distributed Object ID to the end of the datagram.
sourcepub fn add_zone(&mut self, v: Zone) -> Result<(), DatagramError>
pub fn add_zone(&mut self, v: Zone) -> Result<(), DatagramError>
Adds a 32-bit zone ID to the end of the datagram.
sourcepub fn add_location(
&mut self,
parent: DoId,
zone: Zone,
) -> Result<(), DatagramError>
pub fn add_location( &mut self, parent: DoId, zone: Zone, ) -> Result<(), DatagramError>
Added for convenience, rather than adding the parent and the zone separately.
sourcepub fn add_data(&mut self, bytes: Vec<u8>) -> Result<(), DatagramError>
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.
sourcepub fn add_string(&mut self, str: &str) -> Result<(), DatagramError>
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.
sourcepub fn add_blob(&mut self, bytes: Vec<u8>) -> Result<(), DatagramError>
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.
sourcepub fn add_buffer(&mut self, size: usize) -> Result<usize, DatagramError>
pub fn add_buffer(&mut self, size: usize) -> Result<usize, DatagramError>
Reserves an amount of bytes in the datagram buffer.
sourcepub fn add_internal_header(
&mut self,
recipients: Vec<Channel>,
sender: Channel,
msg_type: MsgType,
) -> Result<(), DatagramError>
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.
sourcepub fn add_control_header(
&mut self,
msg_type: MsgType,
) -> Result<(), DatagramError>
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.
sourcepub fn get_buffer(&self) -> &[u8] ⓘ
pub fn get_buffer(&self) -> &[u8] ⓘ
Returns a reference to this Datagram
’s byte buffer.
Trait Implementations§
source§impl Add for Datagram
impl Add for Datagram
Appends another datagram’s raw bytes to this datagram.
Consumes the right-hand-side Datagram
.
Auto Trait Implementations§
impl Freeze for Datagram
impl RefUnwindSafe for Datagram
impl Send for Datagram
impl Sync for Datagram
impl Unpin for Datagram
impl UnwindSafe for Datagram
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)