ROSBridge and sensor_msgs/Image - Why am I getting an extra byte?
I have ROSBridge server running on my host and a client I wrote connected to it. I can send and receive messages just fine. I have not had any trouble sending strings and numbers, however, when I try to send an image (of type sensor_msgs/Image) from the server to the client, something really peculiar happens.
For test purposes, I'm sending a 1 x 1 pixel image of encoding bgr8. If I send a red pixel (ie BGR value is {0,0,255}), and do rostopic echo /myImage/data
, I see {0,0,255} printed to terminal. Just as expected.
However, when I receive the message on my client, the data field actually has 4 bytes of data instead of 3 (I should get 1 byte per color). I cannot figure out where this extra byte comes from, nor how to format the 4 bytes of data to get back my original BGR value.
Here is the pattern I've found so far. The following are hex values of the data I sent from the server (left side) and received on the client (right side). Sorry for the weird spacing... I couldn't figure out how to enter tabs an spaces on this website.
--Sent From Server (BGR Hex) --- Received At Client
----------- 00 00 00 ---------------------- 41 41 41 41 -----
----------- FF FF FF --------------------- 2F 2F 2F 2F -----
----------- 00 00 FF ---------------------- 41 41 44 2F -----
----------- 00 FF 00 ---------------------- 41 50 38 41 -----
----------- FF 00 00 ---------------------- 2F 77 41 41 -----
Once again, I have no idea what's happening here. I believe the endianness of the message may be an issue as well, but it doesn't help explain where the extra byte of data is coming from. Any insight would really be appreciated.