cvm-rs: merge guac and jpeg libs together into one
doesn't really need to be two seperate libraries. also preperation for other funnies the build script has been replaced with a much saner justfile which uses much saner "yarn workspace" invocations instead of blindly cding all over the place
This commit is contained in:
48
cvm-rs/src/guac_js.rs
Normal file
48
cvm-rs/src/guac_js.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use neon::prelude::*;
|
||||
use crate::guac;
|
||||
|
||||
fn guac_decode_impl<'a>(cx: &mut FunctionContext<'a>) -> JsResult<'a, JsArray> {
|
||||
let input = cx.argument::<JsString>(0)?.value(cx);
|
||||
|
||||
match guac::decode_instruction(&input) {
|
||||
Ok(data) => {
|
||||
let array = JsArray::new(cx, data.len());
|
||||
|
||||
let conv = data
|
||||
.iter()
|
||||
.map(|v| cx.string(v))
|
||||
.collect::<Vec<Handle<JsString>>>();
|
||||
|
||||
for (i, str) in conv.iter().enumerate() {
|
||||
array.set(cx, i as u32, *str)?;
|
||||
}
|
||||
|
||||
return Ok(array);
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
let err = cx.string(format!("{}", e));
|
||||
return cx.throw(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn guac_encode_impl<'a>(cx: &mut FunctionContext<'a>) -> JsResult<'a, JsString> {
|
||||
let mut elements: Vec<String> = Vec::with_capacity(cx.len());
|
||||
|
||||
// Capture varadic arguments
|
||||
for i in 0..cx.len() {
|
||||
let input = cx.argument::<JsString>(i)?.value(cx);
|
||||
elements.push(input);
|
||||
}
|
||||
|
||||
Ok(cx.string(guac::encode_instruction(&elements)))
|
||||
}
|
||||
|
||||
pub fn guac_decode(mut cx: FunctionContext) -> JsResult<JsArray> {
|
||||
guac_decode_impl(&mut cx)
|
||||
}
|
||||
|
||||
pub fn guac_encode(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
guac_encode_impl(&mut cx)
|
||||
}
|
||||
Reference in New Issue
Block a user