qicosmos / rest_rpc

modern C++(C++11), simple, easy to use rpc framework
MIT License
1.66k stars 365 forks source link

data is packed... when subscript(... [](string_view data) #8

Open objects76 opened 4 years ago

objects76 commented 4 years ago

On examples/client/main.cpp....

client.subscribe("key", [](string_view data) { std::cout << csprintf("%d.%d ", gettid(), LINE).c_str() << "key= " << &data[1] << "\n"; std::cout << "what is first char of string_view is " << (int)data[0] << std::endl; });

the data is packed....

so I've changed callback_sub in rpc_client.cpp. Is it right? thank you...

    void callback_sub(const boost::system::error_code& ec, string_view result) {
        ....
            //it->second(data);
            rpc_service::msgpack_codec codec2;
            auto str = codec2.unpack<std::string>(data.data(), data.size());
            it->second(str);
                     ....
    }
qicosmos commented 4 years ago

yes, you need do serialization for the result.

qicosmos commented 4 years ago

You could call as to deserialize, it's more simple. If not match the type you will get an exception.

as<string>(result)
objects76 commented 4 years ago

Thank you ... I've update with as(result);