diff --git a/protocol/index.html b/protocol/index.html index 48421371c..dd4449927 100644 --- a/protocol/index.html +++ b/protocol/index.html @@ -345,6 +345,14 @@

Params

""" pass # pragma: no cover + @staticmethod + @abstractmethod + def decode_message(data: bytes) -> dict: + """ + Decode a message from raw bytes. + """ + pass # pragma: no cover + def is_connected(self) -> bool: """ Return whether or not the connection is still alive @@ -477,6 +485,24 @@

Subclasses

Static methods

+
+def decode_message(data: bytes) ‑> dict +
+
+

Decode a message from raw bytes.

+
+ +Expand source code + +
@staticmethod
+@abstractmethod
+def decode_message(data: bytes) -> dict:
+    """
+    Decode a message from raw bytes.
+    """
+    pass  # pragma: no cover
+
+
def encode_message(message: dict) ‑> bytes
@@ -843,6 +869,27 @@

Errors

return QDataStreamProtocol.pack_message(json_encoder.encode(message)) + @staticmethod + def decode_message(data: bytes) -> dict: + _, action = QDataStreamProtocol.read_qstring(data) + if action in ("PING", "PONG"): + return {"command": action.lower()} + + message = json.loads(action) + try: + for part in QDataStreamProtocol.read_block(data): + try: + message_part = json.loads(part) + if part != action: + message.update(message_part) + except (ValueError, TypeError): + if "legacy" not in message: + message["legacy"] = [] + message["legacy"].append(part) + except (KeyError, ValueError): + pass + return message + async def read_message(self): """ Read a message from the stream @@ -859,24 +906,7 @@

Errors

# Otherwise reraise raise - pos, action = self.read_qstring(block) - if action in ("PING", "PONG"): - return {"command": action.lower()} - - message = json.loads(action) - try: - for part in self.read_block(block): - try: - message_part = json.loads(part) - if part != action: - message.update(message_part) - except (ValueError, TypeError): - if "legacy" not in message: - message["legacy"] = [] - message["legacy"].append(part) - except (KeyError, ValueError): - pass - return message + return QDataStreamProtocol.decode_message(block)

Ancestors

@@ -1071,6 +1084,7 @@

Inherited members

  • Protocol: