Skip to content

Commit

Permalink
Eliminate space counted as message length (#126)
Browse files Browse the repository at this point in the history
Co-authored-by: William Woodruff <william@yossarian.net>
  • Loading branch information
guest271314 and woodruffw authored Jul 28, 2024
1 parent f57d39b commit 51a6559
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ff2mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 51a6559

Please sign in to comment.