gratz
gratz

Reputation: 1616

v8 node buffer of unsigned chars

My knowledge / experience of C is quite limited but I'm trying to create a node addon that uses a node buffer with a C call which expects the buffer to be of type 'unsigned char*' but from what I can see the node buffer Data method provides a 'char*' so the types are incompatible. E.g.

This is how it would be called using c:

int length = 100;
unsigned char buf[length];
int ret = ftdi_read_data(&ftdic, buf, length);

And from what I have read, to use a node buffer you do the following instead:

int length = 100;
node::Buffer *slowBuffer = node::Buffer::New(length);
int ret = ftdi_read_data(&ftdic, node::Buffer::Data(slowBuffer), length);

However this returns the following error when building:

error: invalid conversion from ‘char*’ to ‘unsigned char*’ [-fpermissive]
int ret = ftdi_read_data(&ftdic, node::Buffer::Data(slowBuffer), length);

Is it possible to create a node buffer of type unsigned chars, or achieve this in some other way?

Thanks

Upvotes: 0

Views: 910

Answers (1)

Raymond Connell
Raymond Connell

Reputation: 46

In your addon C code use a cast like this: (unsigned char*)node::Buffer::Data(slowBuffer). This is the usual fix for the specific error shown.

Upvotes: 3

Related Questions