<i id='gPxG5'><tr id='gPxG5'><dt id='gPxG5'><q id='gPxG5'><span id='gPxG5'><b id='gPxG5'><form id='gPxG5'><ins id='gPxG5'></ins><ul id='gPxG5'></ul><sub id='gPxG5'></sub></form><legend id='gPxG5'></legend><bdo id='gPxG5'><pre id='gPxG5'><center id='gPxG5'></center></pre></bdo></b><th id='gPxG5'></th></span></q></dt></tr></i><div id='gPxG5'><tfoot id='gPxG5'></tfoot><dl id='gPxG5'><fieldset id='gPxG5'></fieldset></dl></div>

<small id='gPxG5'></small><noframes id='gPxG5'>

    <tfoot id='gPxG5'></tfoot>

      <bdo id='gPxG5'></bdo><ul id='gPxG5'></ul>

      <legend id='gPxG5'><style id='gPxG5'><dir id='gPxG5'><q id='gPxG5'></q></dir></style></legend>

        使用 boost::asio 发送 Protobuf 消息

        时间:2023-09-17

              <bdo id='jvSnU'></bdo><ul id='jvSnU'></ul>
              <i id='jvSnU'><tr id='jvSnU'><dt id='jvSnU'><q id='jvSnU'><span id='jvSnU'><b id='jvSnU'><form id='jvSnU'><ins id='jvSnU'></ins><ul id='jvSnU'></ul><sub id='jvSnU'></sub></form><legend id='jvSnU'></legend><bdo id='jvSnU'><pre id='jvSnU'><center id='jvSnU'></center></pre></bdo></b><th id='jvSnU'></th></span></q></dt></tr></i><div id='jvSnU'><tfoot id='jvSnU'></tfoot><dl id='jvSnU'><fieldset id='jvSnU'></fieldset></dl></div>
              <legend id='jvSnU'><style id='jvSnU'><dir id='jvSnU'><q id='jvSnU'></q></dir></style></legend>

              • <small id='jvSnU'></small><noframes id='jvSnU'>

                  <tbody id='jvSnU'></tbody>

                  <tfoot id='jvSnU'></tfoot>
                  本文介绍了使用 boost::asio 发送 Protobuf 消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试使用 Google 的协议缓冲区和 boost::asio 在 C++ 中一起破解客户端.

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

                  我的问题是我不知道如何将 protobuf 消息提供给 asio.我有的是这个:

                  My problem is that I don't know how I can feed the protobuf message to asio. What I have is this:

                  // set up *sock - works
                  PlayerInfo info;
                  info.set_name(name);
                  // other stuff
                  

                  现在我知道以下是错误的,但我还是会发布:

                  Now I know that the following is wrong, but I'll post it anyways:

                  size_t request_length = info.ByteSize();
                  boost::asio::write(*sock, boost::asio::buffer(info, request_length));
                  

                  据我所知,我必须以不同的方式将我的消息打包到缓冲区中 - 但是如何?

                  I got as far as that I know that I have to pack my message differently into the buffer - but how?

                  一般来说,我很难弄清楚 boost::asio 是如何工作的.有一些教程,但它们通常只涵盖发送标准数据格式,例如 ints,它是开箱即用的.我认为我的问题是序列化,但另一方面我了解到 protobuf 应该为我做这件事......现在我很困惑;)

                  Generally speaking, I'm having a hard time figuring out how boost::asio works. There are some tutorials, but they normally just cover sending standard data formats such as ints, which works out-of-the-box. I figured that my problem is serialization, but on the other hand I learned that protobuf should do this for me... and now I'm confused ;)

                  感谢您的帮助!

                  --> Daniel Gehriger 提供了解决方案,非常感谢!

                  --> Daniel Gehriger provided the solution, thanks a lot!

                  推荐答案

                  我不太了解 Google 的 Protocol buffer,但可以尝试以下操作:

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

                  这篇关于使用 boost::asio 发送 Protobuf 消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:TCP 同时打开和自连接预防 下一篇:WinSock2.h 中的重新定义错误

                  相关文章

                  最新文章

                  <tfoot id='c685f'></tfoot>

                    <legend id='c685f'><style id='c685f'><dir id='c685f'><q id='c685f'></q></dir></style></legend>
                      • <bdo id='c685f'></bdo><ul id='c685f'></ul>

                    1. <small id='c685f'></small><noframes id='c685f'>

                    2. <i id='c685f'><tr id='c685f'><dt id='c685f'><q id='c685f'><span id='c685f'><b id='c685f'><form id='c685f'><ins id='c685f'></ins><ul id='c685f'></ul><sub id='c685f'></sub></form><legend id='c685f'></legend><bdo id='c685f'><pre id='c685f'><center id='c685f'></center></pre></bdo></b><th id='c685f'></th></span></q></dt></tr></i><div id='c685f'><tfoot id='c685f'></tfoot><dl id='c685f'><fieldset id='c685f'></fieldset></dl></div>