eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.91k stars 2.37k forks source link

JSON with binary data #2213

Open nagy opened 3 years ago

nagy commented 3 years ago

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:

If you think this change makes sense, I can give its implementation a try.

ralight commented 3 years ago

Yes ok, that sounds like a sensible suggestion please have a go :)