Struct common::protocol::MessageOrderer
source · [−]pub struct MessageOrderer<S, R> { /* private fields */ }
Expand description
Owns any relevant state and provides the functions needed to use the gameplay message protocol with a specific peer who has a matching MessageOrderer.
Provides two sets of send/receive functions: one to pass in received UDP
datagrams and get UDP datagrams to send, another for sending and receiving
messages of the generic types S
and R
. The peer’s MessageOrderer must
have the same S
and R
types, except flipped.
Implementations
sourceimpl<S: Serialize + DeserializeOwned + Clone, R: Serialize + DeserializeOwned> MessageOrderer<S, R>
impl<S: Serialize + DeserializeOwned + Clone, R: Serialize + DeserializeOwned> MessageOrderer<S, R>
sourcepub fn new(encryption_key: [u8; 32]) -> MessageOrderer<S, R>
pub fn new(encryption_key: [u8; 32]) -> MessageOrderer<S, R>
Creates a new MessageOrderer with the given key. One should be created for each peer, so the client should have one, and the server should have multiple.
sourcepub fn send(&mut self, message: S)
pub fn send(&mut self, message: S)
Send a message. Note that this only adds the message to this struct’s queue, and needs to be separately sent to the intended recipient over UDP.
sourcepub fn transport_recv<D: Display>(
&mut self,
peer_id: D,
encrypted_datagram: &mut [u8]
)
pub fn transport_recv<D: Display>(
&mut self,
peer_id: D,
encrypted_datagram: &mut [u8]
)
Pass in a UDP datagram’s bytes to be handled as a received message, produced on the other end by MessageOrderer::transport_send. The address is just for logging.
peer_id
is just used for tagging logs appropriately.
sourcepub fn transport_send<D: Display>(&mut self, peer_id: D) -> Option<Vec<u8>>
pub fn transport_send<D: Display>(&mut self, peer_id: D) -> Option<Vec<u8>>
Returns a UDP datagram to send if there’s anything to send. The other end should pass the datagram to MessageOrderer::transport_recv.
peer_id
is just used for tagging logs appropriately.
Auto Trait Implementations
impl<S, R> RefUnwindSafe for MessageOrderer<S, R> where
R: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, R> Send for MessageOrderer<S, R> where
R: Send,
S: Send,
impl<S, R> Sync for MessageOrderer<S, R> where
R: Sync,
S: Sync,
impl<S, R> Unpin for MessageOrderer<S, R> where
R: Unpin,
S: Unpin,
impl<S, R> UnwindSafe for MessageOrderer<S, R> where
R: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more