Skip to content

Instantly share code, notes, and snippets.

@xtrntr
Created April 1, 2023 15:49
Show Gist options
  • Save xtrntr/cb0ec1f0e07bfba8cd6dbad961ae2b87 to your computer and use it in GitHub Desktop.
Save xtrntr/cb0ec1f0e07bfba8cd6dbad961ae2b87 to your computer and use it in GitHub Desktop.
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