From bb8f11246ad96667aa30c0056a7c1f10e11acbcb Mon Sep 17 00:00:00 2001 From: Ivan Nikolic Date: Mon, 9 Feb 2026 12:11:49 +0800 Subject: [PATCH] Allow LCM encoder to pass through raw bytes Skip lcm_encode() when the message is already bytes, avoiding unnecessary re-encoding. --- dimos/protocol/pubsub/encoders.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dimos/protocol/pubsub/encoders.py b/dimos/protocol/pubsub/encoders.py index 886856af4f..6b2056fa8b 100644 --- a/dimos/protocol/pubsub/encoders.py +++ b/dimos/protocol/pubsub/encoders.py @@ -105,7 +105,9 @@ class LCMTopicProto(Protocol): class LCMEncoderMixin(PubSubEncoderMixin[LCMTopicProto, DimosMsg, bytes]): """Encoder mixin for DimosMsg using LCM binary encoding.""" - def encode(self, msg: DimosMsg, _: LCMTopicProto) -> bytes: + def encode(self, msg: DimosMsg | bytes, _: LCMTopicProto) -> bytes: + if isinstance(msg, bytes): + return msg return msg.lcm_encode() def decode(self, msg: bytes, topic: LCMTopicProto) -> DimosMsg: