crossbario / autobahn-cpp

WAMP for C++ in Boost/Asio
https://crossbar.io/autobahn
Boost Software License 1.0
251 stars 104 forks source link

Invalid serialization of unordered_map with integer key type #180

Closed kbirken closed 6 years ago

kbirken commented 6 years ago

When trying to publish an object of type std::unordered_map<uint32_t, std::string>, Crossbar.io claims that there is an invalid serialization and cuts the connection. The publishing is done with code similar to this:

typedef std::unordered_map<uint32_t, std::string> MyMap;
MyMap m;
m[12] = "foo";
m[32] = "bar";
m[52] = "zap";
std::tuple<MyMap> arguments(m);
session->publish("com.examples.subscriptions.topic1", arguments);

Crossbar reports this on the console as:

017-12-13T06:53:02+0000 [Router       3911] ApplicationSession started.
2017-12-13T06:53:14+0000 [Router       3911] invalid serialization of WAMP message (must be string or buffer, not int)
2017-12-13T06:53:14+0000 [Router       3911] WampRawSocketProtocol: WAMP Protocol Error (invalid serialization of WAMP message (must be string or buffer, not int)) - aborting connection
2017-12-13T06:53:14+0000 [Router       3911] WampRawSocketProtocol: connection lost: reason = '[Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionAborted'>: Connection was aborted locally, using.

If the key type of the map is changed to std::string, it works like a charm :-). So probably integer key types are not serialized in a way which is WAMP-compatible.

kbirken commented 6 years ago

Are there any insights on this so far? Can I help by providing some further information?

oberstet commented 6 years ago

also, we are still on msgpack v1 https://github.com/crossbario/autobahn-cpp/issues/95

msgpack v1 has another issue: https://github.com/crossbario/autobahn-cpp/issues/166

meejah commented 6 years ago

Using the crossbar container from https://github.com/crossbario/crossbar-starter/ and the example client from "autobahn-cpp" in the same repo, I can get your example code above to successfully send that map (and have a Python subscriber receive it). Also the other way around. This is the exact subprotocol I see:

HTTP/1.1 101 Switching Protocols
Server: Crossbar
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Protocol: wamp.2.msgpack.batched

How does this differ from @kbirken's setup?

oberstet commented 6 years ago

Here is a complete example using integer maps, built using our AutobahnCpp toolchain images - and easy super easy to use: https://github.com/crossbario/crossbar-starter/blob/master/autobahn-cpp/app/client.cpp#L14

So, can't reproduce, closing. @kbirken