Packing struct in Boost Asio buffer

前端 未结 3 1401
悲&欢浪女
悲&欢浪女 2021-01-18 21:18

I\'m looking for a way to send a packet made of a custom data structure through a socket with Boost Asio. At the moment I understand that you can send a string with the stan

3条回答
  •  天涯浪人
    2021-01-18 22:16

    here is some example which works for me:

    void callback(STRUCT_A& s)
    {
      f_strand.post(boost::bind(f, boost::asio::buffer(&s, sizeof(s))));
    }
    
    void f(boost::asio::mutable_buffers_1 v)
    {
      STRUCT_A *a = boost::asio_buffer_cast(v);
    }
    

提交回复
热议问题