Questions tagged [protocol-buffers]

For questions about Google's protocol buffers

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages.

https://developers.google.com/protocol-buffers

7638 questions
96
votes
4 answers

Protocol Buffers versus JSON or BSON

Does anyone have any information on the performance characteristics of Protocol Buffers versus BSON (binary JSON) or versus JSON in general? Wire size Serialization speed Deserialization speed These seem like good binary protocols for use over…
Jeff Meatball Yang
  • 37,839
  • 27
  • 91
  • 125
91
votes
4 answers

What is the correct Protobuf content type?

JSON has application/json as a standard. For protobuf some people use application/x-protobuf, but I saw something as odd as application/vnd.google.protobuf being proposed. Do we have an RFC or some other standard that I can use as a reference for…
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
91
votes
2 answers

Protobuf RPC Service method without parameters

I'm trying to describe an RPC service using Google's Protocol Buffers service WhoamiService { rpc WhoAreYou() returns (Whoami) {} } message Whoami { optional bytes request_id = 1; optional string hostname = 2; optional string message =…
Michael Robinson
  • 1,985
  • 2
  • 21
  • 31
89
votes
4 answers

Google Protocol Buffers: JavaScript Example

Is it a good choice to use Google Protocol Buffers in JavaScript or is it better to do it with JSON? Also it'd be great if someone can give me a simple example about Protocol Buffers implementation in JavaScript. The documentation on the Google's…
nikolakoco
  • 1,343
  • 1
  • 12
  • 22
89
votes
16 answers

ImportError: No module named google.protobuf

I am following this guide and using the exact sample of addressbook.proto. Post the content of compiler generated addressbook_pb2.py file as well. When I run the following simple program, there is error saying, cannot find google.protobuf, any ideas…
Lin Ma
  • 9,739
  • 32
  • 105
  • 175
86
votes
7 answers

Error using import in .proto file

I tried importing a proto file named test1.proto to another proto file named test2.proto using the import statement import "com/test/test1.proto"; But i get the following error com/test/test1.proto: File not found. test2.proto: Import…
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
85
votes
1 answer

How to return an array in Protobuf service rpc

I have the following schema in my .proto file: service MyService { rpc GetItem (ItemQuery) returns (Item) { } } message ItemQuery { int id = 1; } message Item { int id = 1; string name = 2; } Now I want to add another rpc…
Shoham
  • 7,014
  • 8
  • 40
  • 40
83
votes
19 answers

Error "protoc-gen-go: program not found or is not executable"

I am trying to build a sample application with Go gRPC, but I am unable to generate the code using "protoc" I have installed the required libraries and Go packages using: go get -u google.golang.org/grpc go get -u…
Mayank Gupta
  • 1,779
  • 1
  • 13
  • 19
83
votes
3 answers

Why are there no custom default values in proto3?

The proto2 version of Protocol Buffers allows to specify default values for message elements: optional double scaling_factor = 3 [default = 1.0]; Why is this no longer possible in proto3? I consider this a neat feature to save additional bytes on…
Daniel Pauli
  • 963
  • 1
  • 7
  • 8
82
votes
8 answers

How to bring a gRPC defined API to the web browser

We want to build a Javascript/HTML gui for our gRPC-microservices. Since gRPC is not supported on the browser side, we thought of using web-sockets to connect to a node.js server, which calls the target service via grpc. We struggle to find an…
Oliver
  • 1,007
  • 1
  • 9
  • 10
80
votes
1 answer

How to get top-level protobuf enum value name by number in python?

For example, I have proto-file File.proto: enum Test { ONE = 1; TWO = 2; } I generate file File_pb2.py with protoc from File.proto. I want in a python-code get string "ONE" (that corresponds to the name of File_pb2.ONE) by value 1 (that…
abyss.7
  • 13,882
  • 11
  • 56
  • 100
79
votes
4 answers

Protobuf cannot find shared libraries

I have installed protobuf by using following commands: ./configure make make check make install However when I run protoc I get following error: protoc: error while loading shared libraries: libprotoc.so.8: cannot open shared object file: No such…
Kshitiz Sharma
  • 17,947
  • 26
  • 98
  • 169
78
votes
4 answers

How do I represent a UUID in a protobuf message?

I want to attach a UUID to a field in my protobuf User message example. message User { // field containing id as UUID type required string email; optional string name; } I know that protobuf messages do not yet support the UUID type. I've…
Edward Maxedon
  • 1,151
  • 2
  • 11
  • 17
78
votes
3 answers

Handling null values in protobuffers

I am working on something which fetches data from database and constructs protobuff message. Given the possibility that null values can be fetched from the database for certain fields , I will get Null-pointer exception while trying to construct the…
Aarish Ramesh
  • 6,745
  • 15
  • 60
  • 105
76
votes
11 answers

Java: JSON -> Protobuf & back conversion

I have an existing system, which is using protobuf-based communication protocol between GUI and server. Now I would like to add some persistence, but at the moment protobuf messages are straight converted to a third-party custom objects. Is there a…
Denis Kulagin
  • 8,472
  • 17
  • 60
  • 129