MCPcopy
hub / github.com/benoitc/gunicorn / read_message_async

Method read_message_async

gunicorn/ctl/protocol.py:133–156  ·  view source on GitHub ↗

Read one message from an async reader. Args: reader: asyncio StreamReader Returns: Decoded message dictionary

(reader)

Source from the content-addressed store, hash-verified

131
132 @staticmethod
133 async def read_message_async(reader) -> dict:
134 """
135 Read one message from an async reader.
136
137 Args:
138 reader: asyncio StreamReader
139
140 Returns:
141 Decoded message dictionary
142 """
143 # Read length prefix
144 length_data = await reader.readexactly(4)
145 length = struct.unpack('>I', length_data)[0]
146
147 if length > ControlProtocol.MAX_MESSAGE_SIZE:
148 raise ProtocolError(f"Message too large: {length}")
149
150 # Read payload
151 payload_data = await reader.readexactly(length)
152
153 try:
154 return json.loads(payload_data.decode('utf-8'))
155 except json.JSONDecodeError as e:
156 raise ProtocolError(f"Invalid JSON: {e}")
157
158 @staticmethod
159 async def write_message_async(writer, data: dict):

Calls 3

ProtocolErrorClass · 0.85
decodeMethod · 0.80
readexactlyMethod · 0.45