Created
April 1, 2023 15:49
-
-
Save xtrntr/cb0ec1f0e07bfba8cd6dbad961ae2b87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
... | |
loop { | |
match handle.read_line(&mut buffer) { | |
Ok(bytes_read) => { | |
let mut object: Value = serde_json::from_str(&buffer).unwrap(); | |
... | |
// Modify the "body" object to include the desired fields | |
let msg_type: String = object["body"]["type"].to_string(); | |
match msg_type.as_str() { | |
"init" => object["body"].as_object_mut().unwrap().insert("type".to_string(), json!("init_ok")), | |
"echo" => object["body"].as_object_mut().unwrap().insert("type".to_string(), json!("echo_ok")), | |
_ => { | |
println!("{}", msg_type.as_str() == "echo"); | |
print_type_of(&msg_type); | |
None | |
} | |
}; | |
... | |
} | |
Err(error) => { | |
eprintln!("Error reading from stdin: {}", error); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment