【发布时间】:2020-03-05 05:28:55
【问题描述】:
假设我需要从服务器发送到客户端的消息是这样的:
message BatchReply {
bytes data = 1;
repeated int32 shape = 2;
string dtype = 3;
repeated int64 labels = 4;
}
这里shape/dtype只是小变量,可以用几个int空间来表示,而data/labels是大内存缓冲区,最多可以占用1G内存。
我正在尝试使用流发送此消息:
service ImageService {
rpc get_batch (BatchRequest) returns (stream BatchReply) {}
}
我的问题是,我可以找到通过流发送消息的示例都是关于消息结构中只有一个字段的消息,例如:
service TransferFile {
rpc Upload(stream Chunk) returns (Reply) {}
}
message Chunk {
bytes buffer = 1; // here is only on field of buffer, what if there is a field of int val = 2; ?
}
如果Chunk 的结构中有两个字段怎么办。在同一个流送过程中,每次调用set_buffer()时,是否需要调用set_val()?
【问题讨论】:
标签: c++ stream protocol-buffers grpc