0

com/crossbario/autobahn-cpp for subscribe to events from server. Server is not my own, i just need to collect information from it, but i have problem with format.

I have this event and can't figure out correct type for such complicated case:

RX message: event [2934398464921086, 7994968764510011, {},[{"type":"Event", "data":{"type":"order", "weight":"1141.13200000", "value":"0.09000000"}}], {"point":81632796}]

auto s1 = session->subscribe( "topic",
    [](const autobahn::wamp_event& event) {
        for( int i = 0; i< event.number_of_arguments(); i++) {
            try {
                typedef /*some type*/ ARGS;
                ARGS arguments;
                arguments = event.argument<ARGS>(i);
            }
            catch (const std::bad_cast& e) {
                std::cerr << "Casting exception: " << e.what() << std::endl;
            }
            std::cout << "Got event: " << event.number_of_arguments() << std::endl;
        }
    }).then([](boost::future<autobahn::wamp_subscription> sub) {
        std::cout << "Subscribed with ID " << sub.get().id() << std::endl;
    }
);

Can somebody help me?

xanm
  • 41
  • 3

1 Answers1

0

I solved problem.

    void check_type( const msgpack::object& obj, int identSize=0)
    {

        std::string ident = "";
        for(int i=1;i<=identSize; i++)
            ident += " ";

        if( obj.type == msgpack::type::ARRAY)
            std::cout << ident << "ARRAY" << std::endl;
        else if( obj.type == msgpack::type::NIL)
            std::cout << ident << "NIL" << std::endl;
        else if( obj.type == msgpack::type::BOOLEAN)
            std::cout << ident << "BOOLEAN" << std::endl;
        else if( obj.type == msgpack::type::POSITIVE_INTEGER)
            std::cout << ident << "POSITIVE_INTEGER" << std::endl;
        else if( obj.type == msgpack::type::NEGATIVE_INTEGER)
            std::cout << ident << "NEGATIVE_INTEGER" << std::endl;
        else if( obj.type == msgpack::type::STR)
        {
            std::string v = obj.as<std::string>();
            std::cout << ident << "STR: "<< v << std::endl;
        }
        else if( obj.type == msgpack::type::BIN)
            std::cout << ident << "BIN" << std::endl;
        else if( obj.type == msgpack::type::EXT)
            std::cout << ident << "EXT" << std::endl;
        else if( obj.type == msgpack::type::MAP)
        {
            std::cout << ident << "MAP size:" << obj.via.map.size << std::endl;
            for( int i = 0; i< obj.via.map.size; i++)
            {
                std::cout << ident+" " << "Key:" << i << std::endl;
                check_type(obj.via.map.ptr[i].key, identSize+2);
                std::cout << ident+" " << "Value:" << i << std::endl;
                check_type(obj.via.map.ptr[i].val, identSize+2);
            }

        }
        else
            std::cout<< "Udefined" << std::endl;
    }

    msgpack::object argument = event.argument<msgpack::object>(i);
    check_type( argument);

What i do is just convert event argument from autobahn to msgpack::object and then go through it with checking type.

xanm
  • 41
  • 3