[英]how to put a python dictionary in a protobuf message?
Suppose we have this Json blob:假设我们有这个 Json blob:
{
"thing": {
"x": 1,
"str": "hello,
"params": {
"opaque": "yes",
"unknown": 1,
"more": ...
}
}
}
The contents of params is unknown. params 的内容未知。 All we know is that it's a dictionary.
我们只知道它是一本字典。 How do we define a protobuf message that can parse it?
我们如何定义可以解析它的 protobuf 消息?
// file: thing.proto
message Thing {
uint32 x = 1;
string str = 2;
WhatGoesHere? params = 3;
}
[Edit] Moved solution to answer as per comment. [编辑] 移动解决方案以根据评论回答。
Solutions: Use google provided messages.解决方案:使用谷歌提供的消息。
// file: solution.proto
import "google/protobuf/struct.proto";
message Solution1 {
uint32 x = 1;
string str = 2;
google.protobuf.Struct params = 3;
}
message Solution2 {
uint32 x = 1;
string str = 2;
map<string, google.protobuf.Value> params = 3;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.