From e521179c3e38a0bbf719a696192f343cd8e9dfcb Mon Sep 17 00:00:00 2001 From: tomqext Date: Wed, 25 Mar 2026 10:31:59 +0000 Subject: [PATCH 1/2] fix issue leading to ~20x slowdown in binary json processing --- rosbridge_library/src/rosbridge_library/protocol.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rosbridge_library/src/rosbridge_library/protocol.py b/rosbridge_library/src/rosbridge_library/protocol.py index 829685a70..517ca7bf3 100644 --- a/rosbridge_library/src/rosbridge_library/protocol.py +++ b/rosbridge_library/src/rosbridge_library/protocol.py @@ -127,7 +127,9 @@ def incoming(self, message_string=""): if self.bson_only_mode: self.buffer.extend(message_string) else: - self.buffer = self.buffer + str(message_string) + if isinstance(message_string, bytes): + message_string = message_string.decode('utf-8') + self.buffer = self.buffer + message_string msg = None # take care of having multiple JSON-objects in receiving buffer From 6b1d81d00d91b6aafb39f0f27c2d9fec4c35363c Mon Sep 17 00:00:00 2001 From: tomqext Date: Wed, 25 Mar 2026 10:56:10 +0000 Subject: [PATCH 2/2] log UnicodeDecodeError on invalid UTF-8 --- rosbridge_library/src/rosbridge_library/protocol.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rosbridge_library/src/rosbridge_library/protocol.py b/rosbridge_library/src/rosbridge_library/protocol.py index 517ca7bf3..caccfe110 100644 --- a/rosbridge_library/src/rosbridge_library/protocol.py +++ b/rosbridge_library/src/rosbridge_library/protocol.py @@ -128,7 +128,11 @@ def incoming(self, message_string=""): self.buffer.extend(message_string) else: if isinstance(message_string, bytes): - message_string = message_string.decode('utf-8') + try: + message_string = message_string.decode('utf-8') + except UnicodeDecodeError: + self.log("error", "Received binary message with invalid UTF-8 encoding") + return self.buffer = self.buffer + message_string msg = None