我正在为protobuf消息寻找类似xpath的查询语言.例如,对于下面显示的Person消息[借用开发者指南] message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE
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可能会很昂贵,特别是对于大型Proto对象.
任何帮助深表感谢.
谢谢,
伊尔凡