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 @@
+def decode_message(data: bytes) ‑> dict
+
Decode a message from raw bytes.
@staticmethod
+@abstractmethod
+def decode_message(data: bytes) -> dict:
+ """
+ Decode a message from raw bytes.
+ """
+ pass # pragma: no cover
+
def encode_message(message: dict) ‑> bytes
Protocol
:
close
decode_message
drain
is_connected
send_message
Protocol
:
close
decode_message
drain
encode_message
is_connected
P
abort
close
+decode_message
drain
encode_message
is_connected
diff --git a/protocol/protocol.html b/protocol/protocol.html
index 380896aa2..1ac776e56 100644
--- a/protocol/protocol.html
+++ b/protocol/protocol.html
@@ -57,6 +57,14 @@ Module server.protocol.protocol
"""
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
@@ -238,6 +246,14 @@ Ancestors
"""
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
@@ -370,6 +386,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
@@ -678,6 +712,7 @@
abort
close
+decode_message
drain
encode_message
is_connected
diff --git a/protocol/qdatastream.html b/protocol/qdatastream.html
index 939c4e404..7387bea6a 100644
--- a/protocol/qdatastream.html
+++ b/protocol/qdatastream.html
@@ -108,29 +108,15 @@ Module server.protocol.qdatastream
return QDataStreamProtocol.pack_message(json_encoder.encode(message))
- async def read_message(self):
- """
- Read a message from the stream
-
- # Errors
- Raises `IncompleteReadError` on malformed stream.
- """
- try:
- length, *_ = struct.unpack("!I", await self.reader.readexactly(4))
- block = await self.reader.readexactly(length)
- except IncompleteReadError as e:
- if self.reader.at_eof() and not e.partial:
- raise DisconnectedError()
- # Otherwise reraise
- raise
-
- pos, action = self.read_qstring(block)
+ @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 self.read_block(block):
+ for part in QDataStreamProtocol.read_block(data):
try:
message_part = json.loads(part)
if part != action:
@@ -143,6 +129,24 @@ Module server.protocol.qdatastream
pass
return message
+ async def read_message(self):
+ """
+ Read a message from the stream
+
+ # Errors
+ Raises `IncompleteReadError` on malformed stream.
+ """
+ try:
+ length, *_ = struct.unpack("!I", await self.reader.readexactly(4))
+ block = await self.reader.readexactly(length)
+ except IncompleteReadError as e:
+ if self.reader.at_eof() and not e.partial:
+ raise DisconnectedError()
+ # Otherwise reraise
+ raise
+
+ return QDataStreamProtocol.decode_message(block)
+
PING_MSG = QDataStreamProtocol.pack_message("PING")
PONG_MSG = QDataStreamProtocol.pack_message("PONG")
@@ -239,6 +243,27 @@ Classes
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
@@ -255,24 +280,7 @@ Classes
# 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)
Protocol
:
close
decode_message
drain
is_connected
send_message
server.protocol.simple_json
Protocol
: