Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 grpc were developed in parallel, I wanted to reach out to the grpc community as well.

Source: Removal of unknown fields

like image 776
Joshua Avatar asked Apr 08 '15 03:04

Joshua


People also ask

How do you repeat in Protobuf?

When you use the protoc command to generate the java object it will create a Foo Object which will have its own builder method on it. //Creates the builder object Builder builder = Package. Foo. newBuilder(); //populate the repeated field.

What does repeated in Protobuf mean?

repeated : this field can be repeated any number of times (including zero) in a well-formed message. The order of the repeated values will be preserved.

Can Protobuf fields be null?

Protobuf treats strings as primitive types and therefore they can not be null. Instead of checking if the string is not null use standard libraries, like apache commons, to check if the string is not blank. This is clear that the value will be inserted if the value is not blank.

Why was required removed from proto3?

We dropped required fields in proto3 because required fields are generally considered harmful and violating protobuf's compatibility semantics.


1 Answers

Getting rid of field presence for primitives makes Protobuf more "natural" and efficient in many languages, since primitives in C/C++, Java, C#, and Go must be present. In such languages, if you want presence information you "box" the primitive by making it a pointer to a primitive.

Protobuf 3 gets rid of presence for primitives but still has it for messages. Thus, you can use the same "boxing" technique for Protobuf. Protobuf now has standard messages that box primitives.

like image 85
Eric Anderson Avatar answered Sep 20 '22 19:09

Eric Anderson