Questions tagged [proto3]

Protocol Buffers - Google's data interchange format

Google Protocol Buffers questions related to version 3 of the Protocol Buffer format should be tagged with this tag.

At this time proto3 is still in alpha stage.

About Versioning

When protobuf was initially opensourced it implemented Protocol Buffers language version 2 (aka proto2), which is why the version number started from v2.0.0. From v3.0.0, a new language version (proto3) is introduced while the old version (proto2) will continue to be supported.

146 questions
368
votes
4 answers

Why required and optional is removed in Protocol Buffers 3

I'm recently using gRPC with proto3, and I've noticed that required and optional has been removed in new syntax. Would anyone kindly explain why required/optional are removed in proto3? Such kind of constraints just seem necessary to make definition…
yjzhang
  • 4,859
  • 3
  • 19
  • 21
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
38
votes
9 answers

golang protobuf remove omitempty tag from generated json tags

I am using google grpc with a json proxy. for some reason i need to remove the omitempty tags from the struct generated in the *.pb.go files. if i have a proto message like this message Status { int32 code = 1; string message = 2; } The…
sadlil
  • 3,077
  • 5
  • 23
  • 36
36
votes
1 answer

How to mark rpc as deprecated

If I have a service like this: service MyService { rpc GetThings(GetThingsRequest) returns (GetThingsResponse); } How would I mark GetThings as deprecated? I know how to mark fields or messages as deprecated but I can't find any information about…
Jan Hančič
  • 53,269
  • 16
  • 95
  • 99
27
votes
5 answers

Check if a field has been set in protocol buffer 3

I am migrating a java application from protocol buffers 2 to protocol buffer 3. In proto 2 to check if a field is set you have hasfield() method for which an example Java code generated is: public boolean hasText() { return ((bitField0_ &…
user1798617
  • 271
  • 1
  • 3
  • 3
19
votes
3 answers

gRPC / Protobuf interface versioning

Let's say we use gRCP/Protobuf to connect many application. Those application are developped and released at their own team, with their own speed. Over time there will be different version of the the same app (e.g. desktop apps install on user PCs)…
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
18
votes
2 answers

Protocol buffer3 and json

Protocol buffer v3 claims, that library is json friendly (https://developers.google.com/protocol-buffers/docs/proto3#json), but I cannot find how to achieve get that mapping. Should I add some plugin, or some option into protoc, or call something…
lofcek
  • 1,165
  • 2
  • 9
  • 18
10
votes
1 answer

Can a proto3 optional field be changed to repeated without breaking wire compatibility?

Let's say that I have a proto3 message defined as follows, for use as a gRPC request (i.e. using protobuf's binary encoding): message MyRequest { string name = 1; } Can I change my server (i.e. the reader of the message) to use the following…
paulkernfeld
  • 2,171
  • 1
  • 16
  • 16
8
votes
1 answer

generic protobuf deserializer in Java

I'm trying to write a generic java class that can be used to deserialize/parse any protobuf message. Here's how the code should look in a perfect world: public abstract class ProtoDeserializer { public T deserialize(final…
maja
  • 17,250
  • 17
  • 82
  • 125
8
votes
2 answers

Exception handling in gRPC

I have a server written in Java and client written in PHP. How can client catch exception from server if anything goes wrong? I can't find anything about exception handling in gRPC documentation. Thank you!
Kevin
  • 1,403
  • 4
  • 18
  • 34
8
votes
1 answer

How can unknown field functionality be replicated in proto3?

Google has removed unknown fields in proto3. I would love to hear the reasoning behind this choice. Also, if anyone has any way to replicate the proto2 behavior I would love to hear it. If it matters, we are writing our code in Go. As proto3 and…
Joshua
  • 317
  • 2
  • 6
7
votes
1 answer

Pragmattic use of AutoMapper with Google Protocol Buffers 3

I want to use AutoMapper with proto3, but the biggest problem I have is in mapping from a source property that may allow null into a proto that never does. When doing such population manually, one must do something like this: var proto = new…
me--
  • 1,978
  • 1
  • 22
  • 42
7
votes
1 answer

Map List with Mapstruct from Java POJO to Protobuf (proto3)

I'm trying to map some POJOs from Java to Protobuf (proto3). Some of them contain Lists. While mapping lists with POJOs (for example List) is no problem, I'm getting a UnsupportedOperationException. Example with List (this works…
Liso
  • 195
  • 5
  • 15
7
votes
1 answer

Reading comments from .proto files using a Protocol Buffers descriptor object

I am currently revisiting a project using Google Protocol Buffers. In the project I want to make use of the features Descriptors and Reflection of Protocol Buffers. The official documentation states that the comments of .proto files can be…
Florian Wolters
  • 3,820
  • 5
  • 35
  • 55
6
votes
2 answers

Stopping omission of default values in Protocol Buffers

I have a proto schema defined as below, message User { int64 id = 1; bool email_subscribed = 2; bool sms_subscribed = 3; } Now as per official proto3 documentation, default values are not serialized to save space during wire transmission.…
doto
  • 403
  • 1
  • 5
  • 9
1
2 3
9 10