MCPcopy
hub / github.com/msgspec/msgspec / prefixed_recv

Function prefixed_recv

examples/asyncio-kv/kv.py:23–32  ·  view source on GitHub ↗

Read a length-prefixed buffer from the stream

(stream: asyncio.StreamReader)

Source from the content-addressed store, hash-verified

21
22
23async 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

Callers 2

handle_connectionMethod · 0.85
requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…