c++ - 如何转换 boost::beast 的响应回应?
问题描述
我需要转换boost::beast::http::response<boost::beast::http::buffer_body>
为boost::beast::http::response<boost::beast::http::string_body>
.
使用野兽的 api 这样做的优雅而有效的方法是什么?
附言
我认为序列化和解析不是那么有效,也许有更好的方法。但如果这是解决方案,因为我是野兽新手,我也很高兴看到一个优雅的代码示例。
谢谢,大卫。
解决方案
好的,我设法做到了
boost::beast::http::response<boost::beast::http::string_body> string_response;
boost::beast::http::response<boost::beast::http::buffer_body> buffer_response;
std::string response_body
// Do stuff to read the response and fill the response_body using the buffer
string_response.base() = buffer_response.base();
string_response.body() = response_body;
事实证明,标头有一个复制构造函数,所以我所要做的就是分配字符串主体..
因此,如果复制构造函数是有效的(很可能是这样),那么这个解决方案也是有效的。
推荐阅读
- css - css - 轮播不显示在页面上
- c++ - 排序函数和优先级队列c ++中的比较器
- json - 在 Go 中解组通过 MQTT 发布的 JSON 对象
- ios - CVMetalTextureCache创建参数
- ios - 当我实际上可以访问该标识符时如何修复错误“使用未解析的标识符”
- android - 没有应用程序可以使用 Kotlin 执行此操作 Android Intent
- vba - 软返回宏
- android - 任务 ':app:transformClassesWithDesugarForDebug' Cordova Gradle Ionic 执行失败
- php - Laravel 黄昏验证自定义用户模型
- swift - Swift - 指向函数参数的“预期类型”错误