Binary data

#1

Does Autobahn support binary data?

I came across
https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_packer

and after some hacking came up with:

void pack_binary(msgpack::object& obj, const unsigned char* data, uint32_t len)
{
msgpack::sbuffer sbuf;
msgpack::packermsgpack::sbuffer packer(sbuf);
packer.pack_bin(len); // pack header and size
packer.pack_bin_body(reinterpret_cast<const char *>(data), len); // pack payload

msgpack::unpacked msg;
msgpack::unpack(&msg, sbuf.data(), sbuf.size());

obj = msg.get();

}

method(autobahn::wamp_invocation invocation)
{

autobahn::wamp_arguments status;
autobahn::wamp_kw_arguments res;

unsigned char data[500] = { 0x00, 0x00, 0x0f, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f,
                   0x6f, 0x7f, 0x8f, 0x9f, 0xaf, 0xbf, 0xcf, 0xdf,
                   0xef, 0xff, 0x00 };
pack_binary(res["thumbnail"], data, 500);

invocation->result(status, res);

}

But that is ugly and is definitely a hack. I also don’t know if it works because I have not been able to figure out how to write the receiving end of it.

Is there a proper way to do this? I figure I could also convert the data to base64, but rather avoid that if possible.

My ‘server’ is going to be written in cpp and the ‘client’ is going to be written in python.

Thanks,

John

0 Likes

#2

Okay, I figured out how to do it with a std::vector<uint8_t> and positional arguments:

    {
    int arg1 = 42;
    int arg2 = 1341234243;

    std::vector<uint8_t> thumb = { 0x00, 0x00, 0x0f, 0x1f, 0x2f, 0x3f,
                             0x4f, 0x5f, 0x6f, 0x7f, 0x8f, 0x9f,
                             0xaf, 0xbf, 0xcf, 0xdf, 0xef, 0xff, 0x00 };

    typedef std::tuple<int, int, std::vector<uint8_t> > ThumbTuple;
    ThumbTuple result = make_tuple(arg1, arg2, thumb);

}

I have not figured out the syntax for keyword arguments, but I am getting closer.

John

···

On Mon, Mar 21, 2016 at 11:00 AM John P Poet jpp...@gmail.com wrote:

Does Autobahn support binary data?

0 Likes