Write framed message: 4-byte big-endian length + JSON payload. Args: sock: Connected socket. payload: Message payload dictionary. Raises: ProtocolError: If payload exceeds maximum size.
(self, sock: socket.socket, payload: dict[str, Any])
| 152 | self._client_id = _generate_client_id() |
| 153 | |
| 154 | def _write_frame(self, sock: socket.socket, payload: dict[str, Any]) -> None: |
| 155 | """Write framed message: 4-byte big-endian length + JSON payload. |
| 156 | |
| 157 | Args: |
| 158 | sock: Connected socket. |
| 159 | payload: Message payload dictionary. |
| 160 | |
| 161 | Raises: |
| 162 | ProtocolError: If payload exceeds maximum size. |
| 163 | """ |
| 164 | payload_bytes = json.dumps(payload, ensure_ascii=False).encode("utf-8") |
| 165 | length = len(payload_bytes) |
| 166 | |
| 167 | if length > MAX_PAYLOAD_BYTES: |
| 168 | raise ProtocolError( |
| 169 | f"Payload too large: {length} > {MAX_PAYLOAD_BYTES}", |
| 170 | "PAYLOAD_TOO_LARGE", |
| 171 | ) |
| 172 | |
| 173 | header = struct.pack(">I", length) |
| 174 | sock.sendall(header + payload_bytes) |
| 175 | |
| 176 | def _read_frame(self, sock: socket.socket) -> dict[str, Any]: |
| 177 | """Read framed message: 4-byte header + JSON payload. |
no test coverage detected