如何在 protobuf 中存储嵌套的响应数据?
How to store back the nested response data in protobuf?
我正在使用 GRPC 远程调用数据库并以 .proto 文件给出的响应格式存储数据。我的程序是基于CPP编程的:
// similar .proto file
message FinalResponse
{
repeated IntermediateResponse finals = 1;
}
message IntermediateResponse
{
string name = 1;
InitialResponse foo = 2;
}
enum InitialResponse
{
COUNTRY_UNKNOWN = 0;
COUNTRY_INDIA = 1;
}
就我而言,请求消息为空(无字段),因此未在此处显示。我浏览了协议缓冲区文档并尝试了这个:
// firstly called the database and stored the intermediateResponse in a vector<pair<string, string>> data
//pseudo-code below:
FinalResponse result;
for cur_data in data:
{
IntermediateResponse *interResp = result.add_finals();
interResp->set_name(cur_data.first);
interResp->set_foo(static_cast<InitialResponse>(cur_data.second));
}
当我执行此操作时,没有 syntax/build 错误,但 grpc 状态显示我们没有收到任何回复:
ERROR - (12) No message returned for unary request
我想澄清一下服务是来自服务器端的 运行 并且客户端也能够检测到该服务,我怀疑通过数据库返回的数据可能没有正确存储在响应中消息,因此 GRPC 推断我们没有取回任何数据。请为此提出一些解决方法?
看起来可能是服务器端的问题,现在经过相同的更改,它能够正确存储响应。
可能服务器宕机了一段时间并返回错误。
我正在使用 GRPC 远程调用数据库并以 .proto 文件给出的响应格式存储数据。我的程序是基于CPP编程的:
// similar .proto file
message FinalResponse
{
repeated IntermediateResponse finals = 1;
}
message IntermediateResponse
{
string name = 1;
InitialResponse foo = 2;
}
enum InitialResponse
{
COUNTRY_UNKNOWN = 0;
COUNTRY_INDIA = 1;
}
就我而言,请求消息为空(无字段),因此未在此处显示。我浏览了协议缓冲区文档并尝试了这个:
// firstly called the database and stored the intermediateResponse in a vector<pair<string, string>> data
//pseudo-code below:
FinalResponse result;
for cur_data in data:
{
IntermediateResponse *interResp = result.add_finals();
interResp->set_name(cur_data.first);
interResp->set_foo(static_cast<InitialResponse>(cur_data.second));
}
当我执行此操作时,没有 syntax/build 错误,但 grpc 状态显示我们没有收到任何回复:
ERROR - (12) No message returned for unary request
我想澄清一下服务是来自服务器端的 运行 并且客户端也能够检测到该服务,我怀疑通过数据库返回的数据可能没有正确存储在响应中消息,因此 GRPC 推断我们没有取回任何数据。请为此提出一些解决方法?
看起来可能是服务器端的问题,现在经过相同的更改,它能够正确存储响应。
可能服务器宕机了一段时间并返回错误。