how to get FFI array from node-ffi-napi

Viewed 59

i use node-ffi-napi to call rust ffi fixU32_decode

#[no_mangle]
pub extern "C" fn fixU32_decode(raw: *const libc::c_char) -> *mut u32 {
    let str_raw = unsafe { CStr::from_ptr(raw) }.to_str().unwrap().to_string();
    let bytes_raw = hex::decode(str_raw).unwrap();
    let mut u8_fixed: [u32; 6] = Decode::decode(&mut &bytes_raw[..]).unwrap();
    println!("fixU32_decode input {:?}",u8_fixed);
    let ptr = u8_fixed.as_mut_ptr();
    std::mem::forget(u8_fixed);
    ptr
}

let libm = ffi.Library(rootPath + "/lib/libscale_ffi.dylib", {
   'fixU32_decode': [ref.refType("uint"), ['string']],
}
let value = libm.fixU32_decode("010000000200000003000000040000000500000006000000")

how to unpack fixU32_decode return value to convert array ?

0 Answers
Related