Fixed (de)serialization
This commit is contained in:
parent
ba7b52364d
commit
e1cacce3b0
59
src/main.rs
59
src/main.rs
|
@ -1,6 +1,7 @@
|
|||
mod models;
|
||||
use models::{player, board, piece, networking};
|
||||
use models::{player, board, piece, networking::Action};
|
||||
use clap::{Arg, App, SubCommand};
|
||||
use serde_json::Value;
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("Khetamine")
|
||||
|
@ -8,37 +9,42 @@ fn main() {
|
|||
.author("oysteikt, felixalb")
|
||||
.about("Play Khet with your friends!")
|
||||
.arg(Arg::with_name("serve")
|
||||
.short("s")
|
||||
.long("serve")
|
||||
.help("Run as game server, your friend connects as client."))
|
||||
.short("s")
|
||||
.long("serve")
|
||||
.help("Run as game server, your friend connects as client."))
|
||||
.arg(Arg::with_name("connect")
|
||||
.short("c")
|
||||
.help("Connect to a server")
|
||||
.value_name("ADRESS")
|
||||
.takes_value(true))
|
||||
.short("c")
|
||||
.help("Connect to a server")
|
||||
.value_name("ADRESS")
|
||||
.takes_value(true))
|
||||
.arg(Arg::with_name("v")
|
||||
.short("v")
|
||||
.multiple(true)
|
||||
.help("Sets the level of verbosity"))
|
||||
.short("v")
|
||||
.multiple(true)
|
||||
.help("Sets the level of verbosity"))
|
||||
.subcommand(SubCommand::with_name("test")
|
||||
.about("Runs various tests")
|
||||
.version("1.3")
|
||||
.author("felixalb"))
|
||||
.about("Runs various tests")
|
||||
.version("1.3")
|
||||
.author("felixalb"))
|
||||
.get_matches();
|
||||
|
||||
// println!("{}", &serialize_move(models::networking::Action::Rotate {
|
||||
|
||||
// let testMove: Result<Action, serde_json::Error> = deserialize_move(serialize_move(
|
||||
// models::networking::Action::Rotate {
|
||||
// from: (2, 2),
|
||||
// rot: models::networking::RotationDirection::Positive
|
||||
// }));
|
||||
|
||||
// }
|
||||
// ));
|
||||
// match testMove {
|
||||
// Ok(act) => { println!("It works! Actions for days"); },
|
||||
// Err(e) => { println!("Somethings wrong: {}", e);
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
fn serialize_move(action: models::networking::Action) -> String {
|
||||
}
|
||||
|
||||
fn serialize_move(action: models::networking::Action) -> String {
|
||||
let serialized = serde_json::to_string(&action);
|
||||
match serialized {
|
||||
Ok(s) => {
|
||||
// println!("{}", s);
|
||||
return s;
|
||||
},
|
||||
Err(_e) => {
|
||||
|
@ -47,3 +53,12 @@ fn serialize_move(action: models::networking::Action) -> String {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_move(json: String) -> Result<Action, serde_json::Error> {
|
||||
let obj= serde_json::from_str(&json);
|
||||
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -9,7 +9,6 @@ pub enum RotationDirection {
|
|||
pub type Position = (u8, u8);
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Action {
|
||||
Move {from: Position, to: Position},
|
||||
Rotate {from: Position, rot: RotationDirection},
|
||||
|
|
Loading…
Reference in New Issue