WAMPv1 uses JSON as a message payload format. This is simple, fulfills its purpose, and has some nice aspects:
- JSON parsers/serializers are available for many languages/platfoms
- for browsers, JSON is builtin and native
- its not perfect, but works
However, there are (at least) 2 situations where JSON is a pain:
- I need to transfer binary data .. i.e. load WebGL textures, vectors, sound whatever via WAMP
- I am on a restricted device .. Arduino, other MCUs, with very little memory, but want to use WAMP
Further, WebSocket (WAMP default transport) already allows for binary message payload.
It would thus be neat to have a 2nd additional (optional) message payload format for WAMP.
A simple, binary transparent one. Simple. No fancy IDL+compiler stuff!
http://en.wikipedia.org/wiki/Bencode
For the WebSocket transport binding of WAMP, that could be frictionless to do:
If its a text WS message, JSON is assumed/expected.
If its a binary WS message, Bencode is assumed/expected.
There are 2 aspects to think through:
a) WAMP itself
b) the payloads transferred via WAMP
a)
Both JSON and Bencode have:
strings
integers
arrays
The strings used in WAMP (for URIs or Error Desc) MUST BE UTF8. So that translates without problems.
However, WAMPv1 uses "bool" and "null":
i) PUBLISH has = bool
ii) EVENT has always a payload body, which MAY BE null.
iii) CALLRESULT has always a payload body, which MAY BE null.
None of that is essential.
i) use 0/1 integer
ii+iii) just omitting the value would work too.
b)
There might be 3 kinds of clients: text-only, binary-only, can-do-both
So for app payload (i.e. RPC Call arguments, or Publish event payload) we need to map between:
text <=> binary format
There are different possibilities for mapping. I.e. map JSON null to 0, map it to "null", or "". Likewise a Bencode string, could map to UTF8, or HEX.
A sane way would to make the kind of mapping performed a property of the
RPC proc
PubSub topic
A specific RPC proc could say: If you call me with Bencode, I will assume all Bencode strings to be UTF8 and forward those plain to JSON clients. Or it could say: if you call be with Bencode, I assume strings are really binary and convert all to Base64 for JSON clients.
That would then apply to any string inside the payload. So I could NOT say: arg1 = Base64, arg2 = UTF8
The latter would require essentially an IDL. And that is no longer simple.