First attempt at binding the open invite function

This commit is contained in:
Cecylia Bocovich 2022-11-09 14:40:53 -05:00
parent 1b285cff42
commit ff905db53a
2 changed files with 37 additions and 0 deletions

View File

@ -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"

View File

@ -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")
}