Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with non-ASCII strings #102

Closed
YtvwlD opened this issue Aug 29, 2017 · 3 comments
Closed

Problems with non-ASCII strings #102

YtvwlD opened this issue Aug 29, 2017 · 3 comments

Comments

@YtvwlD
Copy link

YtvwlD commented Aug 29, 2017

When I run

client.get do |topic,message|
    puts message.encoding

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.

@YtvwlD YtvwlD changed the title Problems with non-ASCII string Problems with non-ASCII strings Aug 29, 2017
@njh
Copy link
Owner

njh commented Aug 30, 2017

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.

@YtvwlD
Copy link
Author

YtvwlD commented Aug 31, 2017

Oh, okay. That sounds reasonable. I just assumed that all strings were UTF-8 because of this comment.

@njh
Copy link
Owner

njh commented Aug 31, 2017

Ah, yeah. But the payload isn't a string 😨

@njh njh closed this as completed Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants