Read a length-prefixed buffer from the stream
(stream: asyncio.StreamReader)
| 21 | |
| 22 | |
| 23 | async def prefixed_recv(stream: asyncio.StreamReader) -> bytes: |
| 24 | """Read a length-prefixed buffer from the stream""" |
| 25 | # Read the next 4 byte prefix |
| 26 | prefix = await stream.readexactly(4) |
| 27 | |
| 28 | # Convert the prefix back into an integer for the next message length |
| 29 | n = int.from_bytes(prefix, "big") |
| 30 | |
| 31 | # Read in the full message buffer |
| 32 | return await stream.readexactly(n) |
| 33 | |
| 34 | |
| 35 | # Define some request types. We set `tag=True` on each type so they can be used |
no outgoing calls
no test coverage detected
searching dependent graphs…