How to write to a boost::asio::mutable_buffer?

时光毁灭记忆、已成空白 提交于 2019-12-05 16:17:32

boost::asio::buffer_cast<>() is what you should use to get access to the pointer used by the buffer. boost::asio::buffer_size() is what you should use to get access to the size used.

e.g.

const std::string test("test");
const size_t len = std::min(boost::asio::buffer_size(mybuf), test.length());
memcpy(boost::asio::buffer_cast<void *>(mybuf),
    test.c_str(),
    len);
const std::string test2("test");
boost::asio::mutable_buffer offset = mybuf + len;
const size_t len2 = std::min(boost::asio::buffer_size(offset), test2.length());
memcpy(boost::asio::buffer_cast<void *>(offset),
    test.c_str(),
    len2);

boost::asio::mutable_buffer offset2 = offset + len2;

See also:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!