[][src]Trait udp_netmsg::Datagram

pub trait Datagram: Downcast {
    fn from_buffer(buffer: Cursor<Vec<u8>>) -> Box<dyn Datagram>
    where
        Self: Sized
;
fn to_buffer(&self) -> Vec<u8>;
fn header() -> u32
    where
        Self: Sized
; fn get_header(&self) -> u32
    where
        Self: Sized
, { ... } }

This Trait must be implemented on any struct that you wish to use as a UDP datagram

Required methods

fn from_buffer(buffer: Cursor<Vec<u8>>) -> Box<dyn Datagram> where
    Self: Sized

Called when a datagram with a matching header_id is received This method should use parse the bytes (easy with the byteorder crate) and return a copy of itself

fn to_buffer(&self) -> Vec<u8>

Called when sending a udp datagram This method should take the internal variables of the struct and convert them to bytecode (easy with the byteorder crate) and return the buffer

fn header() -> u32 where
    Self: Sized

Static method used to define the header_id.

Loading content...

Provided methods

fn get_header(&self) -> u32 where
    Self: Sized

An additional necessary method to make this crate work. Will not be touched by the user

Loading content...

Methods

impl dyn Datagram

pub fn is<__T: Datagram>(&self) -> bool

Returns true if the trait object wraps an object of type __T.

pub fn downcast<__T: Datagram>(self: Box<Self>) -> Result<Box<__T>, Box<Self>>

Returns a boxed object from a boxed trait object if the underlying object is of type __T. Returns the original boxed trait if it isn't.

pub fn downcast_ref<__T: Datagram>(&self) -> Option<&__T>

Returns a reference to the object within the trait object if it is of type __T, or None if it isn't.

pub fn downcast_mut<__T: Datagram>(&mut self) -> Option<&mut __T>

Returns a mutable reference to the object within the trait object if it is of type __T, or None if it isn't.

Implementors

Loading content...