net_stream/
message_types.rs1use serde::de::DeserializeOwned;
4use serde::Deserialize;
5use serde::Serialize;
6use std::fmt;
7use uuid::Uuid;
8
9pub trait MessageTypes: 'static + fmt::Debug {
14 type TcpToServer: Serialize + DeserializeOwned + fmt::Debug + Clone + Send + Sync + Unpin + 'static;
16
17 type TcpFromServer: Serialize + DeserializeOwned + fmt::Debug + Clone + Send + Sync + Unpin + 'static;
19
20 type UdpToServer: Serialize + DeserializeOwned + fmt::Debug + Clone + Send + Sync + Unpin + 'static;
22
23 type UdpFromServer: Serialize + DeserializeOwned + fmt::Debug + Clone + Send + Sync + Unpin + 'static;
25}
26
27#[derive(Debug, Serialize, Deserialize)]
28pub(crate) enum TcpToServer<M: MessageTypes> {
29 ApplicationLogic(M::TcpToServer),
31}
32
33#[derive(Debug, Serialize, Deserialize)]
34pub(crate) enum TcpFromServer<M: MessageTypes> {
35 ApplicationLogic(M::TcpFromServer),
37
38 Welcome { handshake_uuid: Uuid },
41
42 UdpHandshakeAcknowledged,
45}
46
47#[derive(Debug, Serialize, Deserialize)]
48pub(crate) enum UdpToServer<M: MessageTypes> {
49 ApplicationLogic(M::UdpToServer),
51
52 Hello { handshake_uuid: Uuid },
58}
59
60#[derive(Debug, Serialize, Deserialize)]
61pub(crate) enum UdpFromServer<M: MessageTypes> {
62 ApplicationLogic(M::UdpFromServer),
64
65 Welcome,
67
68 Heartbeat,
70}
71
72impl<M: MessageTypes> Clone for TcpToServer<M> {
74 fn clone(&self) -> Self {
75 match self {
76 Self::ApplicationLogic(msg) => Self::ApplicationLogic(msg.clone()),
77 }
78 }
79}
80impl<M: MessageTypes> Clone for TcpFromServer<M> {
81 fn clone(&self) -> Self {
82 match self {
83 Self::ApplicationLogic(msg) => Self::ApplicationLogic(msg.clone()),
84 Self::Welcome { handshake_uuid } => Self::Welcome {
85 handshake_uuid: *handshake_uuid,
86 },
87 Self::UdpHandshakeAcknowledged => Self::UdpHandshakeAcknowledged,
88 }
89 }
90}
91impl<M: MessageTypes> Clone for UdpToServer<M> {
92 fn clone(&self) -> Self {
93 match self {
94 Self::ApplicationLogic(msg) => Self::ApplicationLogic(msg.clone()),
95 Self::Hello { handshake_uuid } => Self::Hello {
96 handshake_uuid: *handshake_uuid,
97 },
98 }
99 }
100}
101impl<M: MessageTypes> Clone for UdpFromServer<M> {
102 fn clone(&self) -> Self {
103 match self {
104 Self::ApplicationLogic(msg) => Self::ApplicationLogic(msg.clone()),
105 Self::Welcome => Self::Welcome,
106 Self::Heartbeat => Self::Heartbeat,
107 }
108 }
109}