MCPcopy
hub / github.com/msgspec/msgspec / prefixed_send

Function prefixed_send

examples/asyncio-kv/kv.py:12–20  ·  view source on GitHub ↗

Write a length-prefixed buffer to the stream

(stream: asyncio.StreamWriter, buffer: bytes)

Source from the content-addressed store, hash-verified

10# length-prefixed framing makes it easier for the reader to determine the
11# boundaries of each message before passing it to msgspec to be decoded.
12async def prefixed_send(stream: asyncio.StreamWriter, buffer: bytes) -> None:
13 """Write a length-prefixed buffer to the stream"""
14 # Encode the message length as a 4 byte big-endian integer.
15 prefix = len(buffer).to_bytes(4, "big")
16
17 # Write the prefix and buffer to the stream.
18 stream.write(prefix)
19 stream.write(buffer)
20 await stream.drain()
21
22
23async def prefixed_recv(stream: asyncio.StreamReader) -> bytes:

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…