Sending Protobuf Messages with boost::asio

前端 未结 2 1905
长情又很酷
长情又很酷 2020-12-08 22:56

I\'m trying to hack a client together in C++ using Google\'s Protocol Buffers and boost::asio.

My problem is that I don\'t know how I can feed the protobuf message t

2条回答
  •  长情又很酷
    2020-12-08 23:37

    I don't know much about Google's Protocol buffer, but try the following:

    PlayerInfo info;
    info.set_name(name);
    // ...
    
    boost::asio::streambuf b;
    std::ostream os(&b);
    info.SerializeToOstream(&os);
    
    boost::asio::write(*sock, b);
    

提交回复
热议问题