use serde::{Serialize, Deserialize, de::DeserializeOwned}; #[derive(Serialize, Deserialize, PartialEq, Eq)] pub enum PacketType { /// A regular check to ensure the connection is still alive. Ping, } #[derive(Serialize, Deserialize, PartialEq, Eq)] pub enum SocketMethod { /// Authentication and channel identification. Headers, /// A message was sent in the channel. Message, /// A message was deleted in the channel. Delete, /// Forward message from server to client. (Redis pubsub to ws) Forward(PacketType), } #[derive(Serialize, Deserialize)] pub struct SocketMessage { pub method: SocketMethod, pub data: String, } impl SocketMessage { pub fn data(&self) -> T { serde_json::from_str(&self.data).unwrap() } }