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

Plugable JSON encoder? #54

Closed
Bartvds opened this issue Dec 19, 2015 · 1 comment
Closed

Plugable JSON encoder? #54

Bartvds opened this issue Dec 19, 2015 · 1 comment

Comments

@Bartvds
Copy link

Bartvds commented Dec 19, 2015

Since the core of channels are JSON messages it'd be cool if we could swap the JSON encoder of the default backends.

My use-case for this is using an encoder that supports inlining the bytes of a pre-encoded JSON objects into a larger dynamic JSON structure (we use metamagic.json package). This saves a cubic ton of CPU cycles on JSON decoding/encoding if you re-use a lot of cachable sub-structures.

Anyway, maybe a json.dumps setting would be good, like a importable path to a callable (defaulting to standard json.dumps). Alternately we could override the default backends but that's a bit too much.

A bonus this also saves the project from the endless json/simplejson/ujson/whateverfastestjsonoftheday debates. 😉

@andrewgodwin
Copy link
Member

There's no need to have this pluggable separately - the channel backend already gets to dictate which serialiser it uses (it just gets passed dicts and is expected to return dicts), so to change this would just mean writing a custom backend with a new serialiser, inheriting from the main one you want to use. I'll make sure the serialise/deserialise functions are broken out into class functions that can be overridden.

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