First attempt at binding the open invite function
This commit is contained in:
parent
1b285cff42
commit
ff905db53a
|
@ -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"
|
|
@ -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")
|
||||||
|
}
|
Loading…
Reference in New Issue