Read a framed message: 4-byte big-endian length + JSON payload
(reader: asyncio.StreamReader)
| 298 | |
| 299 | |
| 300 | async def read_frame(reader: asyncio.StreamReader) -> dict[str, Any]: |
| 301 | """Read a framed message: 4-byte big-endian length + JSON payload""" |
| 302 | header = await reader.readexactly(HEADER_SIZE) |
| 303 | (length,) = struct.unpack(">I", header) |
| 304 | |
| 305 | if length > MAX_PAYLOAD_BYTES: |
| 306 | raise ValueError(f"Payload too large: {length} > {MAX_PAYLOAD_BYTES}") |
| 307 | |
| 308 | payload_bytes = await reader.readexactly(length) |
| 309 | payload_str = payload_bytes.decode("utf-8") |
| 310 | |
| 311 | return json.loads(payload_str) |
| 312 | |
| 313 | |
| 314 | def write_frame_sync(payload: dict[str, Any]) -> bytes: |
no outgoing calls
no test coverage detected