-
Notifications
You must be signed in to change notification settings - Fork 61
Closed
Description
I cannot seem to figure this one out. I'm sure the answer is simple, I just cannot get it right. Any help would be appreciated.
I'm using ref-array with node-ffi. I have a c library function which has a signature like this:
var ArrayType = require('ref-array')
var int8Array = ArrayType(ref.types.int8, 10000);
var uint32Ptr = ref.refType('uint32');
var libmylibrary = ffi.Library('libmylibrary', { ...,
'readData': [ 'int' , [int8Array, uint32Ptr ] ]
});readData populates the int8Array with a collection of header(uint16) and body (basically structures) pairs. The uint32Ptr argument is populated with the total number of bytes written to the passed int8Array.
My problem is that after I call readData, I cannot figure out how to reinterpret pieces of the int8Array as another data type. I'm fairly confident that the readData call is populating the array correctly.
I need to do something like this:
libmylibrary.readData(int8ArrayInst, uint32PtrInst);
var currentPosi = 0;
var endPosi = uint32PtrInst.deref();
while (currentPosi < endPosi) {
var bodyLength = howToDoThis.reinterpret(int8ArrayInst, currentPosi, ref.types.uint16);
currentPosi += ref.types.uint16.size;
var bodyData = howToDoThis.reinterpret(int8ArrayInst, currentPosi, myTypes.someStruct);
currentPosi += bodyLength;
}Is this possible?
Metadata
Metadata
Assignees
Labels
No labels