Create Serde structs for messages
This commit is contained in:
parent
e5c68b0c37
commit
0fab0e8c56
3 changed files with 35 additions and 1 deletions
|
@ -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"
|
||||
|
|
|
@ -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
31
src/net/mod.rs
Normal 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 },
|
||||
}
|
Loading…
Reference in a new issue