Created
May 29, 2017 11:21
-
-
Save dherman/19957aca05ad331a352e36421976c79a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addon = require('../native'); | |
var array1 = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7]); | |
var array2 = new Uint8Array(addon.munge(array1.buffer)); | |
console.log(array1); | |
console.log(array2); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use neon::js::binary::JsArrayBuffer; | |
fn munge(call: Call) -> JsResult<JsArrayBuffer> { | |
let scope = call.scope; | |
let mut buffer = call.arguments.require(scope, 0)?.check::<JsArrayBuffer>()?; | |
buffer.grab(|mut contents| { | |
// modify the input buffer | |
contents[0] = 42; | |
}); | |
// return a new buffer | |
JsArrayBuffer::new(16) | |
} | |
register_module!(m, { | |
m.export("munge", munge) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment