MCPcopy Create free account
hub / github.com/bigdra50/unity-cli / write_frame

Function write_frame

relay/protocol.py:287–297  ·  view source on GitHub ↗

Write a framed message: 4-byte big-endian length + JSON payload

(writer: asyncio.StreamWriter, payload: dict[str, Any])

Source from the content-addressed store, hash-verified

285
286
287async def write_frame(writer: asyncio.StreamWriter, payload: dict[str, Any]) -> None:
288 """Write a framed message: 4-byte big-endian length + JSON payload"""
289 payload_bytes = json.dumps(payload, ensure_ascii=False).encode("utf-8")
290 length = len(payload_bytes)
291
292 if length > MAX_PAYLOAD_BYTES:
293 raise ValueError(f"Payload too large: {length} > {MAX_PAYLOAD_BYTES}")
294
295 header = struct.pack(">I", length) # 4-byte big-endian unsigned int
296 writer.write(header + payload_bytes)
297 await writer.drain()
298
299
300async def read_frame(reader: asyncio.StreamReader) -> dict[str, Any]:

Callers 4

_heartbeat_loopMethod · 0.85
_handle_cli_messageMethod · 0.85
_execute_commandMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected