wip: protocol parser
This commit is contained in:
parent
944c872cd8
commit
6f8249a683
89
Cargo.lock
generated
Normal file
89
Cargo.lock
generated
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "distributed-systems-flyio"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.10"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.73"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dd5e8a1f1029c43224ad5898e50140c2aebb1705f19e67c918ebf5b9e797fe1"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.34"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "22a37c9326af5ed140c86a46655b5278de879853be5573c01df185b6f49a580a"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.193"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.193"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.109"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb0652c533506ad7a2e353cce269330d6afd8bdfb6d75e0ace5b35aacbd7b9e9"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.45"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0eae3c679c56dc214320b67a1bc04ef3dfbd6411f6443974b5e4893231298e66"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
|
@ -6,3 +6,5 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
serde = { version = "1.0.193", features = ["serde_derive"] }
|
||||||
|
serde_json = "1.0.109"
|
||||||
|
|
25
src/lib.rs
Normal file
25
src/lib.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
use std::io::{stdin, stdout, Stdin, Stdout};
|
||||||
|
|
||||||
|
pub struct Malestorm {
|
||||||
|
stdin: Stdin,
|
||||||
|
stdout: Stdout,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Malestorm {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
stdin: stdin(),
|
||||||
|
stdout: stdout(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Malestorm {
|
||||||
|
pub fn run(self) {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read() {}
|
||||||
|
|
||||||
|
fn write() {}
|
||||||
|
}
|
|
@ -1,3 +1,10 @@
|
||||||
|
#![allow(special_module_name)]
|
||||||
|
|
||||||
|
mod lib;
|
||||||
|
mod types;
|
||||||
|
|
||||||
|
use crate::lib::Malestorm;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("Hello, world!");
|
let program = Malestorm::default();
|
||||||
}
|
}
|
||||||
|
|
51
src/types.rs
Normal file
51
src/types.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct Message {
|
||||||
|
pub src: String,
|
||||||
|
pub dest: String,
|
||||||
|
pub body: MessageBody,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub(crate) struct MessageBody {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
message_type: String,
|
||||||
|
msg_id: i64,
|
||||||
|
in_reply_to: Option<i64>,
|
||||||
|
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub message: MessageEnum,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub enum MessageEnum {}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
pub fn extraneous_fields_fail() {
|
||||||
|
let body = "{
|
||||||
|
\"src\": \"c1\",
|
||||||
|
\"dest\": \"n1\",
|
||||||
|
\"body\": {
|
||||||
|
\"type\": \"echo\",
|
||||||
|
\"msg_id\": 1,
|
||||||
|
\"echo\": \"Please echo 35\"
|
||||||
|
}
|
||||||
|
}";
|
||||||
|
|
||||||
|
let resp: Result<Message, serde_json::Error> = serde_json::from_str(body);
|
||||||
|
|
||||||
|
if resp.is_ok() {
|
||||||
|
eprintln!("successfully parsed into Message {:#?}", resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
eprintln!("{:#?}", resp);
|
||||||
|
|
||||||
|
assert!(resp.is_err());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user