Skeleton of handling msgpackd data

This commit is contained in:
Darren Burns
2024-08-12 16:43:23 +01:00
parent b0eec3a454
commit 92d7558a1f
3 changed files with 18 additions and 0 deletions

View File

@@ -196,6 +196,7 @@ class AppSession(Session):
META = b"M"
DATA = b"D"
PACKED = b"P"
stderr_data = io.BytesIO()
@@ -216,6 +217,7 @@ class AppSession(Session):
on_data = self._connector.on_data
on_meta = self._connector.on_meta
on_packed = self._connector.on_packed
try:
ready = False
for _ in range(10):
@@ -240,6 +242,8 @@ class AppSession(Session):
await self.send_meta({"type": meta_type})
else:
await on_meta(json.loads(payload))
elif type_bytes == PACKED:
await on_packed(payload)
except IncompleteReadError:
# Incomplete read means that the stream was closed

View File

@@ -81,6 +81,13 @@ class _ClientConnector(SessionConnector):
"You may be running a version of Textual unsupported by this version of Textual Web."
)
async def on_packed(self, payload: bytes) -> None:
"""Handle packed data from session.
Args:
payload: Msgpack data to handle.
"""
async def on_close(self) -> None:
await self.client.send(packets.SessionClose(self.session_id, self.route_key))
self.client.session_manager.on_session_end(self.session_id)

View File

@@ -22,6 +22,13 @@ class SessionConnector:
meta: Mapping of meta information.
"""
async def on_packed(self, payload: bytes) -> None:
"""Handle data packed with msgpack from session.
Args:
payload: Msgpack data to handle.
"""
async def on_close(self) -> None:
"""Handle session close."""