ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Not sure what you mean by converting to bytes, since everything is represented as bytes internally. You're constructing a string on the line
ss << "hello world " << count;
so that's what you're sending. The string stream operator will take count
, turn it into a string, append it to "hello world " and return it through the c_str()
call. If you want to know how long that string is, then use strlen()
. The double
needs sizeof(double)
bytes (probably 8, if your machine is like mine). Any string representation of a double with more than 8 characters will use more space. If you really want to send a double
, create a message type with a double
field.
More than that is getting sent, though, since the underlying networking layers are adding protocol wrappers to everything that gets sent out. In general, I'd advise against trying to optimize things at this level, unless you're seeing a performance problem. Unless you understand linux networking and how ROS uses it at a pretty fine-grained level, you might end up doing a lot of work for little gain.