working somewhat

This commit is contained in:
Robin Appelman 2021-07-23 23:20:01 +02:00
commit c8f89db913
15 changed files with 13382 additions and 13 deletions

View file

@ -1,22 +1,41 @@
mod utils;
use wasm_bindgen::prelude::*;
use tf_demo_parser::{Demo, MessageType};
use tf_demo_parser::demo::header::Header;
use tf_demo_parser::demo::parser::{RawPacketStream, DemoHandler, NullHandler, Encode};
use tf_demo_parser::demo::packet::{Packet, PacketType};
use tf_demo_parser::demo::message::Message;
use std::error::Error;
use bitbuffer::{BitWriteStream, LittleEndian, BitRead, BitWrite};
extern crate web_sys;
// A macro to provide `println!(..)`-style syntax for `console.log` logging.
macro_rules! log {
( $( $t:tt )* ) => {
web_sys::console::log_1(&format!( $( $t )* ).into());
}
}
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}
#[wasm_bindgen]
pub fn unlock(input: &[u8]) -> Vec<u8> {
set_panic_hook();
log!("got {} bytes", input.len());
let mut out_buffer = Vec::with_capacity(input.len());
{
let mut out_stream = BitWriteStream::new(&mut out_buffer, LittleEndian);

View file

@ -1,10 +0,0 @@
pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
// `set_panic_hook` function at least once during initialization, and then
// we will get better error messages if our code ever panics.
//
// For more details see
// https://github.com/rustwasm/console_error_panic_hook#readme
#[cfg(feature = "console_error_panic_hook")]
console_error_panic_hook::set_once();
}