Calling cpp function from NodeJS which has argument const int16_t *bar but getting error unbound type

110 views Asked by At

I am trying to call CPP function from NodeJS

typedef struct foo {

    uint8_t     *data;
    int         dataSize;

} foo ;

foo *ExtractBar(const int16_t *bar);

I have tried nbind library in NodeJS. but getting unbound type error.

uint16 = Int16Array.from('12345');
uint16.fill(0);
lib.ExtractBar(uint16);

I have also tried ffi-napi npm module. but from that I was getting segmentation fault error. can anyone help me please on how to pass correct argument from NodeJS code. I am not sure how to create similar structure in NodeJS-

const int16_t *bar
1

There are 1 answers

1
siniarskimar On

Usually you have to have a reference to a variable as JavaScript is a garbage collected language.

Specifically to nbind, have a look at this and this. You want to pass from NodeJS an buffer of uint16 so you could use nbind::Buffer.