Closed YtvwlD closed 6 years ago
Hi Niklas,
The payload of a MQTT message is binary (it can't be assumed to be ASCII or UTF-8). Unfortunately Ruby does not have an 'array of bytes' class like other languages do - for example node.js has Buffer. So at the moment, just create a string without specifying a type for it.
I did have a plan to add payload type conversion (see #60) - so maybe passing in :utf8
as the type could be a solution. Or maybe it is better to assume the buffer is utf8 in the first place is a better default.
nick.
Oh, okay. That sounds reasonable. I just assumed that all strings were UTF-8 because of this comment.
Ah, yeah. But the payload isn't a string 😨
When I run
this, I get
ASCII-8BIT
. And subsequent string uses may fail with non-ASCII strings.My code works when I do
message = message.force_encoding('utf-8')
. But this is not optimal.