JSON with binary data
In mosquitto_sub, I would like to receive binary data, while also getting
the other data in a json format. When I try to receive binary data now, I get
an empty string like so:
echo -ne "\x00\xff\x00" | mosquitto_pub --topic hello --stdin-file
$ mosquitto_sub --topic hello -F %j
{"tst":"2021-05-20T11:45:37.807793Z+0200","topic":"hello","qos":0,"retain":0,"payloadlen":3,"payload":""}
Would it make sense to let the payload, in case that it cannot be decoded
into a string, be an array of unsigned integers like [0,255,0]? This format
is already adopted by systemds journalctl. See here:
- https://www.freedesktop.org/software/systemd/man/journalctl.html#-o
- https://www.freedesktop.org/wiki/Software/systemd/json/
If you think this change makes sense, I can give its implementation a try.
Yes ok, that sounds like a sensible suggestion please have a go :)
Looks like the PR never went through but I think if it ever does, there should be an option to preserve the old behavior of empty payload on binary data as the printed messages get hefty in size.