qicosmos / rest_rpc

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

客户端publish字符串数据,服务端接收的数据错误 #116

Closed kpengk closed 5 months ago

kpengk commented 6 months ago

测试用例及结果

客户端通过publish发送8字节的字符串数据ABCDEFGH,服务端通过register_handler注册publish处理函数。

int main() {
    rpc_server server(9000, 1);
    server.register_handler("publish_by_token", [&](rpc_conn conn, std::string key, std::string token, std::string val) {
        std::cout << "server, msg size:" << val.size() << ", msg:" << val << "\n";
    });

    server.register_handler("publish", [&](rpc_conn conn, std::string key, std::string token, std::string val) {
        std::cout << "server, msg size:" << val.size() << ", msg:" << val << "\n";
    });
    server.run();
}
int main() {
    rest_rpc::rpc_client client("127.0.0.1", 9000);
    client.connect();
    client.publish("msg", "ABCDEFGH");
    std::this_thread::sleep_for(std::chrono::seconds(3));
}
server, msg size:9, msg:ˋBCDEFGH

原因分析

客户端rpc_client.hpppublish字符串时,通过msgpack对数据进行了打包,在服务端未进行相应解包导致。 image

qicosmos commented 6 months ago

谢谢报告,晚点看。

qicosmos commented 5 months ago

已经处理了,见单测:https://github.com/qicosmos/rest_rpc/blob/master/tests/test_rest_rpc.cpp#L210 可以拉最新代码验证一下。