autobahn-js
autobahn-js copied to clipboard
Binary object to Base64 support
Does autobahn-js support conversion of binary objects to Base64, as per section 14 of the WAMP spec?
If a Base64 string were manually constructed with a leading '\0', and passed as an RPC argument, would it break Autobahn|JS?
This isn't implemented yet. But since the refactoring of serializers, this could now be done at one place:
https://github.com/crossbario/autobahn-js/blob/master/package/lib/serializer.js#L22
JSON.stringify and JSON.parse don't know about the WAMP binary conversion thing, so that code needs to be expanded:
- serialize needs to walk over the
objlooking for binaries and replace those with the string encoding as per WAMP spec before putting the obj intoJSON.serialize - unserialize needs to walk over the unserialized payload coming out of
JSON.parseafter unserialization, and replace strings that start with\ 0with a decoded binary
In fact, we've just recently implemented this in AutobahnPython and Crossbar.io. Which finally allows to fix this here too, since we can now test the feature.
Would it make sense to be able to configure base64 as a serializer for the REST bridge? This seems like it would be handy because unless I am missing something, a method written to return some binary can currently not be called via REST bridge, only over websocket.
@chrisbarber yes, that would make sense: https://github.com/crossbario/crossbar/issues/1079
When this is done, then AB JS needs bits too.
But the issue here is to add support for transparent binaries over JSON in AB JS over regular transports (WebSocket/RawSocket) ..
there now is CI test coverage for binary payloads via https://github.com/crossbario/autobahn-js/blob/master/test/test_binary.js
to activate the tests for json, uncomment this: https://github.com/crossbario/autobahn-js/blob/caa775adbdecfe835a294b721f990e558009f87f/test/test.js#L60