Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath like query for protobuf messages

I am looking for a xpath like query language for protobuf messages. For example, for the Person message shown below [ borrowed from the Developer guide ]

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;
}

I would like to have methods like

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

One way is to convert the proto to Json and use a JsonPath/JsPath API's. But it may be expensive to convert to Json everytime especially for large Proto objects.

Any help is much appreciated.

Thanks, Irfan

like image 701
Irfan Avatar asked Feb 13 '15 17:02

Irfan


People also ask

What is faster than protobuf?

TL;DR — encoding and decoding string-intensive data in JavaScript is faster with JSON than it is with protobuf. When you have structured data in JavaScript, which needs to be sent over the network (for another microservice for example) or saved into a storage system, it first needs to be serialized.

Is protobuf more efficient than JSON?

Protobuf, the binary format crafted by Google, surpasses JSON performance even on JavaScript environments like Node. js/V8 and web browsers.

Can proto3 import proto2?

It's possible to import proto3 message types and use them in your proto2 messages, and vice versa. However, proto2 enums cannot be used in proto3 syntax.

Is protobuf a gRPC?

Protobuf is the most commonly used IDL (Interface Definition Language) for gRPC. It's where you basically store your data and function contracts in the form of a proto file.


1 Answers

Support for that is coming in protobuf v3: https://github.com/google/protobuf/blob/4644f99d1af4250dec95339be6a13e149787ab33/src/google/protobuf/field_mask.proto

like image 67
Igor Gatis Avatar answered Oct 08 '22 17:10

Igor Gatis