RethinkRobotics-opensource / gennodejs

ROS JavaScript message definition and serialization generators
Apache License 2.0
7 stars 21 forks source link

The generated getMessageSize function cannot get correct size of object which has string-type field when unicode string is used #18

Closed oyoungs closed 5 years ago

oyoungs commented 5 years ago

Excuse me. When I use the generated by gennodejs, some problem make me embarrassed.

The generated getMessageSize function cannot get correct size of object which has string-type field when unicode string is used

e.g.

SetString.srv:

string data
---
bool success
string message

When I call the request "{ data: '这是参数' }" ( UTF-8 such as Chinese) It cannot work, and an error like 'RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range' throwed

I read the getMessageSize function in SetString.js It's like this:

static getMessageSize(object) {
    let length = 0;
    length += object.data.length;
    return length + 8;
  }

But I don't think is correct, so I changed it to:

static getMessageSize(object) {
    let length = 0;
    length += Buffer.from(object.data).length;
    return length + 8;
  }

And then, it works Maybe the change I make is not suitable for all, but it worked for my problem. So, I think the generate function must be improved to successfully work for unicode string type

Do you think so?

chris-smith commented 5 years ago

yes this is what #17 is doing. The issue is also resolved if you use messages generated by rosnodejs itself instead of gennodejs.