Skip to content

Commit

Permalink
fix:binarization_protocol
Browse files Browse the repository at this point in the history
handling typing correctly
  • Loading branch information
JarbasAl committed Jan 3, 2025
1 parent 445be9f commit 358d275
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hivemind_bus_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,17 @@ def on_message(self, *args):
if (isinstance(message, HiveMessage) and message.msg_type == HiveMessageType.BINARY):
self._handle_binary(message)
return
self.emitter.emit('message', message) # raw message
self._handle_hive_protocol(HiveMessage(**message))

if isinstance(message, HiveMessage):
self.emitter.emit('message', message.serialize()) # raw message
self._handle_hive_protocol(message)
elif isinstance(message, str):
self.emitter.emit('message', message) # raw message
self._handle_hive_protocol(HiveMessage(**json.loads(message)))
else:
assert isinstance(message, dict)
self.emitter.emit('message', json.dumps(message, ensure_ascii=False)) # raw message
self._handle_hive_protocol(HiveMessage(**message))

def _handle_binary(self, message: HiveMessage):
assert message.msg_type == HiveMessageType.BINARY
Expand Down

0 comments on commit 358d275

Please sign in to comment.