protobuf消息的类xpath查询
我正在为protobuf消息寻找一种类似xpath的查询语言。例如,对于下面显示的Person消息[从开发者指南中借用]protobuf消息的类xpath查询,xpath,protocol-buffers,jsonpath,Xpath,Protocol Buffers,Jsonpath,我正在为protobuf消息寻找一种类似xpath的查询语言。例如,对于下面显示的Person消息[从开发者指南中借用] message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
我想有这样的方法
XPBQuery.get(person, "$.id") ==> returns the id
XPBQuery.get(person, "$.name") ==> returns the name
XPBQuery.get(person, "$.phone.number[0]") ==> returns the first phone number
一种方法是将proto转换为Json并使用JsonPath/JsPath API。但每次转换为Json可能代价高昂,尤其是对于大型原型对象
非常感谢您的帮助
谢谢,
Irfan在protobuf v3中提供了对该问题的支持:同时,我正在寻找一个类似问题的解决方案,我发现:
- (python)
- (爪哇)
- (爪哇)
(我没有使用这些库作为我的目标语言是C++,但希望这可以帮助其他人)< /P>
祝你好运 我不知道这是否已经存在,但如果不存在,您可以通过Protobuf描述符和反射接口来实现(不要与Java反射混淆——Protobuf反射由Protobuf库提供)。参见<代码> com。谷歌.ToBuff.java中的消息< /C> >谷歌>::原代码::C++中的反射< /代码>。我想去掉JSON.NET(支持JSONPath)并使用ProtoBuf,但由于缺乏查询功能,我无法使用它