Description
I am opening this issue to enable proper BSON handling when using rosbridge in ROS 2. The goal is to use the more efficient BSON format for handling relatively large messages, like sensor_msgs/msg/PointCloud2, because serializing them to text with JSON creates significant overhead.
Related Issues
This issue is related to the following previously closed issues:
I assume these were not closed because the bug was fixed, but were automatically closed as "not planned" due to a long period of inactivity.
Environment
- Library Version:
2.0.1
- ROS Version:
Humble
- Platform / OS:
Ubuntu 22.04.5 LTS (on arm64)
Steps To Reproduce
In the current ros2 branch, the on_message function in websocket_handler.py attempts to decode all incoming binary messages as UTF-8. This prevents the bson_only_mode from working as intended.
- Launch
rosbridge_server with bson_only_mode enabled.
ros2 launch rosbridge_server rosbridge_websocket_launch.xml bson_only_mode:=true
- Run a client that sends a message containing BSON-encoded binary data (which is not valid UTF-8).
Expected Behavior
When launched with bson_only_mode:=True, BSON binary messages should be processed correctly without causing a decoding error.
Actual Behavior
The rosbridge_server throws a UnicodeDecodeError and either crashes or outputs an error log.
Proposed Solution
I believe this issue can be resolved by applying the following patch to websocket_handler.py.
--- a/rosbridge_server/src/rosbridge_server/websocket_handler.py
+++ b/rosbridge_server/src/rosbridge_server/websocket_handler.py
@@ -158,15 +158,13 @@
@log_exceptions
def on_message(self, message):
- if isinstance(message, bytes):
- message = message.decode("utf-8")
- self.incoming_queue.push(message)
-
+ if self.bson_only_mode and isinstance(message, bytes):
+ # BSON ONLY MODE: push binary directly
+ self.incoming_queue.push(message)
+ else:
+ if isinstance(message, bytes):
+ message = message.decode("utf-8")
+ self.incoming_queue.push(message)
Next Steps
Could you please provide your feedback on this approach? If this direction is acceptable, I am prepared to create a pull request.
/cc @jacobperron
Description
I am opening this issue to enable proper BSON handling when using
rosbridgein ROS 2. The goal is to use the more efficient BSON format for handling relatively large messages, likesensor_msgs/msg/PointCloud2, because serializing them to text with JSON creates significant overhead.Related Issues
This issue is related to the following previously closed issues:
I assume these were not closed because the bug was fixed, but were automatically closed as "not planned" due to a long period of inactivity.
Environment
2.0.1HumbleUbuntu 22.04.5 LTS (on arm64)Steps To Reproduce
In the current
ros2branch, the on_message function inwebsocket_handler.pyattempts to decode all incoming binary messages as UTF-8. This prevents thebson_only_modefrom working as intended.rosbridge_serverwithbson_only_modeenabled.Expected Behavior
When launched with
bson_only_mode:=True, BSON binary messages should be processed correctly without causing a decoding error.Actual Behavior
The
rosbridge_serverthrows aUnicodeDecodeErrorand either crashes or outputs an error log.Proposed Solution
I believe this issue can be resolved by applying the following patch to
websocket_handler.py.Next Steps
Could you please provide your feedback on this approach? If this direction is acceptable, I am prepared to create a pull request.
/cc @jacobperron