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

Add support for automatic JSON conversion #60

Open
njh opened this issue Mar 7, 2015 · 4 comments
Open

Add support for automatic JSON conversion #60

njh opened this issue Mar 7, 2015 · 4 comments

Comments

@njh
Copy link
Owner

njh commented Mar 7, 2015

No description provided.

@njh
Copy link
Owner Author

njh commented Sep 12, 2016

Also (automatic?) gzip compression?

There is a magic number at the beginning of the file. Just read the first two bytes and check if they are equal to 0x1f8b

@skandragon
Copy link

While this sounds wonderful in some ways, what about the 100 other protocols? Isn't this feature creep?

@njh
Copy link
Owner Author

njh commented Nov 29, 2016

Yes, that is partly why I didn't rush into implementing it. But it could be that there is a way

However JSON is very popular with MQTT:

  1. MQTT recommends (but doesn't require) using human readable, text based payloads
  2. JSON is very concise/compact
  3. JSON maps directly into high-level programming language features.

I have been very frustrated with HTTP libraries, where there first thing I have to do in my code is if content_type = "application/json" then JSON.parse.

There would certainly need to be a way of turning it on and off. I was imagining something like:

client.convert_payload = :auto     # Automatically parse payloads, hashes/arrays become JSON
client.convert_payload = false     # Disable payload conversion
client.convert_payload = :json     # Parse payloads as JSON, generate JSON

@skandragon
Copy link

Perhaps as an option, but if all I want is MQTT, I should just get MQTT. Handling JSON from within Ruby is stupid simple, and I'd keep your code base clean and focused.

Besides, what happens when the next person asks for XML? :)

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