diff --git a/crates/lox-wasm/Cargo.toml b/crates/lox-wasm/Cargo.toml new file mode 100644 index 0000000..0ed661c --- /dev/null +++ b/crates/lox-wasm/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "lox-bindings" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +lox = { git = "https://git-crysp.uwaterloo.ca/iang/lox.git" } +wasm-bindgen = "0.2" +serde_json = "1.0.87" diff --git a/crates/lox-wasm/src/lib.rs b/crates/lox-wasm/src/lib.rs new file mode 100644 index 0000000..e368d9d --- /dev/null +++ b/crates/lox-wasm/src/lib.rs @@ -0,0 +1,23 @@ +use wasm_bindgen::prelude::*; +use lox::OPENINV_LENGTH; +use lox::proto::*; +use serde_json; + +#[wasm_bindgen] +extern { + #[wasm_bindgen(js_namespace = console)] + pub fn log(s: &str); +} + +#[wasm_bindgen] +pub fn open_invite(invite: &[u8]) { + + let (request, _state) = open_invite::request(&validate_invite(invite)); + let serialized_request = serde_json::to_string(&request).unwrap(); + log(&format!("request: {}", serialized_request)); +} + + +fn validate_invite(invite: &[u8]) -> [u8; OPENINV_LENGTH] { + invite.try_into().expect("slice with incorrect length") +}