автобан msgmapck распаковать сложного типа переполнение стека

com / crossbario / autobahn-cpp для подписки на события с сервера. Сервер не мой, мне просто нужно собрать с него информацию, но у меня проблема с форматом.

У меня есть это событие, и я не могу определить правильный тип для такого сложного случая:

RX-сообщение: событие [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;
});

Кто-нибудь может мне помочь?

0

Решение

Я решил проблему.

    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);

Я просто конвертирую аргумент события из autobahn в msgpack :: object, а затем проверяю тип.

0

Другие решения

Других решений пока нет …