cargo fmt
This commit is contained in:
parent
962c48afbd
commit
de622349b5
1 changed files with 21 additions and 16 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::io::{self, BufRead, Write};
|
use std::io::{self, BufRead, Write};
|
||||||
use serde::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
struct Message {
|
struct Message {
|
||||||
|
|
@ -18,14 +18,9 @@ enum Body {
|
||||||
node_ids: Vec<String>,
|
node_ids: Vec<String>,
|
||||||
},
|
},
|
||||||
#[serde(rename = "init_ok")]
|
#[serde(rename = "init_ok")]
|
||||||
InitOk {
|
InitOk { in_reply_to: u64 },
|
||||||
in_reply_to: u64,
|
|
||||||
},
|
|
||||||
#[serde(rename = "echo")]
|
#[serde(rename = "echo")]
|
||||||
Echo {
|
Echo { msg_id: u64, echo: String },
|
||||||
msg_id: u64,
|
|
||||||
echo: String,
|
|
||||||
},
|
|
||||||
#[serde(rename = "echo_ok")]
|
#[serde(rename = "echo_ok")]
|
||||||
EchoOk {
|
EchoOk {
|
||||||
msg_id: u64,
|
msg_id: u64,
|
||||||
|
|
@ -44,11 +39,15 @@ fn main() {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let mut stdout = io::stdout();
|
let mut stdout = io::stdout();
|
||||||
let mut node_id = String::new();
|
let mut node_id = String::new();
|
||||||
|
|
||||||
for line in stdin.lock().lines() {
|
for line in stdin.lock().lines() {
|
||||||
let input: Message = serde_json::from_str(&line.unwrap()).unwrap();
|
let input: Message = serde_json::from_str(&line.unwrap()).unwrap();
|
||||||
match input.body {
|
match input.body {
|
||||||
Body::Init { msg_id, node_id: id, .. } => {
|
Body::Init {
|
||||||
|
msg_id,
|
||||||
|
node_id: id,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
node_id = id;
|
node_id = id;
|
||||||
let output = Message {
|
let output = Message {
|
||||||
src: node_id.clone(),
|
src: node_id.clone(),
|
||||||
|
|
@ -60,7 +59,7 @@ fn main() {
|
||||||
let output_json = serde_json::to_string(&output).unwrap();
|
let output_json = serde_json::to_string(&output).unwrap();
|
||||||
writeln!(stdout, "{}", output_json).unwrap();
|
writeln!(stdout, "{}", output_json).unwrap();
|
||||||
stdout.flush().unwrap();
|
stdout.flush().unwrap();
|
||||||
},
|
}
|
||||||
Body::Echo { msg_id, echo } => {
|
Body::Echo { msg_id, echo } => {
|
||||||
let output = Message {
|
let output = Message {
|
||||||
src: node_id.clone(),
|
src: node_id.clone(),
|
||||||
|
|
@ -74,12 +73,18 @@ fn main() {
|
||||||
let output_json = serde_json::to_string(&output).unwrap();
|
let output_json = serde_json::to_string(&output).unwrap();
|
||||||
writeln!(stdout, "{}", output_json).unwrap();
|
writeln!(stdout, "{}", output_json).unwrap();
|
||||||
stdout.flush().unwrap();
|
stdout.flush().unwrap();
|
||||||
},
|
}
|
||||||
Body::Error { in_reply_to, code, text } => {
|
Body::Error {
|
||||||
eprintln!("Error received (in_reply_to: {}, code: {}, text: {})", in_reply_to, code, text);
|
in_reply_to,
|
||||||
},
|
code,
|
||||||
|
text,
|
||||||
|
} => {
|
||||||
|
eprintln!(
|
||||||
|
"Error received (in_reply_to: {}, code: {}, text: {})",
|
||||||
|
in_reply_to, code, text
|
||||||
|
);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue