如何在 protoBuf 中创建动态嵌套对象消息?
How to create dynamic nested object message in protoBuff?
正在尝试创建嵌套动态对象的消息
生成的结束数据结构应如下所示
"content": {
"foo1": "bar1",
"foo2": "bar2"
}
其中内容中的键和值是动态的,可以由客户端定义。
您可以将content
定义为map<string, string>
,这样客户端就可以为其设置任意键值对(字符串类型)。
message Msg {
map<string, string> content = 1;
}
如果值可能是任意类型,您可以尝试google.protobuf.Struct。
正在尝试创建嵌套动态对象的消息
生成的结束数据结构应如下所示
"content": {
"foo1": "bar1",
"foo2": "bar2"
}
其中内容中的键和值是动态的,可以由客户端定义。
您可以将content
定义为map<string, string>
,这样客户端就可以为其设置任意键值对(字符串类型)。
message Msg {
map<string, string> content = 1;
}
如果值可能是任意类型,您可以尝试google.protobuf.Struct。