"""Chrome Native Messaging stdio protocol helpers.""" from __future__ import annotations import json import struct def read_exact_stream(stream, n: int) -> bytes | None: buf = b"" while len(buf) < n: chunk = stream.read(n - len(buf)) if not chunk: return None buf += chunk return buf def read_native_message(stream) -> dict | None: raw_len = read_exact_stream(stream, 4) if raw_len is None: return None msg_len = struct.unpack(" None: data = json.dumps(msg).encode("utf-8") stream.write(struct.pack("