eclipse-paho / paho.mqtt.golang

Other
2.77k stars 534 forks source link

Feature Request: support json.RawMessage as payload for publishing messages #651

Closed joshuar closed 10 months ago

joshuar commented 1 year ago

Hey there,

I've been using json.RawMessage in a program, as I have a situation where I need to publish different messages that kinda are the same but might have all different bits in the JSON. So json.RawMessage, which is just a []byte anyway, works nicely.

It looks like the client code does not recognise a payload that is a json.RawMessage, so you get an "unknown payload type" error when using it.

Was wondering if there would be a possibility/interest to support json.RawMessage as a payload type?

MattBrittan commented 1 year ago

It would be a very quick addition; feel free to submit a PR (alternatively just converting, []byte(rawMsg) is pretty much a no-op).

MattBrittan commented 10 months ago

I'm going to close this as no PR was forthcoming and I'm unsure how much benefit this delivers (we could end up supporting all kinds of aliases for []byte (it's unfortunate that messages are interface{} but that's not something we can change now).