Skip to content

vector<byte> support? #676

Answered by poor-circle
jjqcat asked this question in Q&A
May 11, 2024 · 3 comments · 3 replies
Discussion options

You must be logged in to vote
  1. struct_pack支持序列化你的结构体到vector<byte>
custom data{};
auto buffer = struct_pack::serialize<std::vector<std::byte>>(data);
auto res = struct_pack::deserialize<std::vector<std::byte>>(buffer);
  1. coro_rpc支持直接使用custom作为函数参数,不需要你手动序列化:
void hi(custom data);
void call(coro_rpc::coro_rpc_client& client,custom data) {
     client.call<hi>(data);
}
  1. 如果你特别想要手动接管序列化/反序列化,也不是不可以:
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);
}
  1. 也可以使用attachment传递数据:
void hi() {
   auto ctx = coro_rpc::get_context();
   std::string_view attachment = ctx->get_request_attachment

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by poor-circle
Comment options

You must be logged in to vote
2 replies
@poor-circle
Comment options

@jjqcat
Comment options

Comment options

You must be logged in to vote
1 reply
@poor-circle
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #675 on May 11, 2024 14:23.