wampcc icon indicating copy to clipboard operation
wampcc copied to clipboard

How to send binary data ?

Open Green7 opened this issue 8 years ago • 4 comments

MsgPack support binary data. How to send it in wampcc?

Green7 avatar Aug 01 '17 19:08 Green7

Hi, I think you could use base64 encoding. So convert your data into base64 string, and then send it as a string.

darrenjs avatar Aug 02 '17 07:08 darrenjs

:( base64 is not an option in my case. I need good performance beacuse I send a lot of data. Conversion to base64 will increase amount of data by 33% ...

Green7 avatar Aug 02 '17 10:08 Green7

Yeah, base64 does have that size & cpu overhead. But the problem with trying to support binary directly is that it is not part of the JSON specification, so there is going to be undefined behaviour in various scenarios. E.g. what if you have a WAMP callee that replies in msgpack containing binary, but the original caller is using plain JSON? A WAMP router would have to make a decision: does it drop the reply, or send an error to the caller, or something else?

But I think it could be added. The json_value class could be changed to allow a new sub-type, (eg, json_binary or something), and that would only be supported by msgpack (and later cbor); an exception would be thrown if a plain json serialiser was used with such messages. I don't think it is much work to add this, but right now I'm in the middle of a refactor, cleaning up the naming of public api.

darrenjs avatar Aug 02 '17 10:08 darrenjs

I think that is not a problem. Router should handle this kind of request. Calle should know what he does and what kind of data expect. Or when calle uses json router can convert data to base64 ....

Green7 avatar Aug 02 '17 13:08 Green7