From 51a655952bd7788d10064362c96a2f9e2c69c4c1 Mon Sep 17 00:00:00 2001 From: guest271314 Date: Sun, 28 Jul 2024 11:35:15 -0700 Subject: [PATCH] Eliminate space counted as message length (#126) Co-authored-by: William Woodruff --- ff2mpv.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ff2mpv.py b/ff2mpv.py index b0eb4f0..dfd5b8d 100755 --- a/ff2mpv.py +++ b/ff2mpv.py @@ -49,7 +49,11 @@ def get_message(): def send_message(message): - content = json.dumps(message).encode("utf-8") + # https://stackoverflow.com/a/56563264 + # https://docs.python.org/3/library/json.html#basic-usage + # To get the most compact JSON representation, you should specify + # (',', ':') to eliminate whitespace. + content = json.dumps(message, separators=(",", ":")).encode("utf-8") length = struct.pack("@I", len(content)) sys.stdout.buffer.write(length) sys.stdout.buffer.write(content)