Create Serde structs for messages

This commit is contained in:
Tangent Wantwight 2020-05-18 20:53:28 -04:00
parent e5c68b0c37
commit 0fab0e8c56
3 changed files with 35 additions and 1 deletions

View File

@ -10,6 +10,7 @@ env_logger = "0.7"
futures = "0.3"
log = "0.4"
structopt = "0.3"
serde = "1"
serde = {version = "1", features = ["derive"]}
serde_json = "1"
tokio = {version = "0.2", features = ["macros"]}
warp = "0.2"

View File

@ -7,6 +7,8 @@ use structopt::StructOpt;
use warp::{serve, ws, ws::Ws, Filter};
use ws::Message;
pub mod net;
#[derive(StructOpt)]
/// Server for base2020 lockstep protocol for multiplayer games.
struct Args {

31
src/net/mod.rs Normal file
View File

@ -0,0 +1,31 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Debug)]
#[serde(tag = "t")]
pub enum ClientMessage<I, S> {
#[serde(rename = "s")]
SetState { s: S },
#[serde(rename = "i")]
Input { i: I },
#[serde(rename = "g")]
GetState { c: usize, s: S },
}
#[derive(Serialize, Debug)]
pub struct Meta {
helo: Option<String>,
version: &'static str,
}
#[derive(Serialize, Debug)]
#[serde(tag = "t")]
pub enum ServerMessage<I, S> {
#[serde(rename = "m")]
Meta { m: Meta },
#[serde(rename = "s")]
SetState { u: i8, s: S },
#[serde(rename = "i")]
Input { i: I },
#[serde(rename = "g")]
GetState { c: usize },
}