vector<byte> support? #676
-
我想将一个结构体数据,通过byte数组传递,远程端手动再转换成我的结构体数据,有什么办法吗?是否可以通过vector进行转换,如 struct custom data; RPC 函数调用时传递 vecData 谢谢 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
custom data{};
auto buffer = struct_pack::serialize<std::vector<std::byte>>(data);
auto res = struct_pack::deserialize<std::vector<std::byte>>(buffer);
void hi(custom data);
void call(coro_rpc::coro_rpc_client& client,custom data) {
client.call<hi>(data);
}
void hi(std::span<std::byte> data/*or use std::vector<std::byte>&,with once more copy*/);
void call(coro_rpc::coro_rpc_client& client, std::vector<std::byte>& vec) {
client.call<hi>(vec);
}
void hi() {
auto ctx = coro_rpc::get_context();
std::string_view attachment = ctx->get_request_attachment(); /*zero-copy by string_view*/
}
void call(coro_rpc::coro_rpc_client& client, std::string_view attachment) {
client.set_req_attachment(attachment); /*zero-copy by string_view*/
client.call<hi>();
} |
Beta Was this translation helpful? Give feedback.
-
我期望的是手动接管序列化/反序列化 返回值类型也可以是std::vectorstd::byte 吗 |
Beta Was this translation helpful? Give feedback.
-
验证 void call(coro_rpc::coro_rpc_client& client, std::vectorstd::byte& vec) ,链接通不过,编译可以,这个引用 & 去掉可以 |
Beta Was this translation helpful? Give feedback.
vector<byte>