I am currently playing with v3.0.0-alpha-2 Google Protocol Buffers .
As far as I understand, v3 removes the required keyword, extensions keyword and default values โโfor fields to simplify the proto language.
What I do not know is the meaning of the optional keyword in proto3.
Example:
syntax = "proto3"; package fw.example; message ExampleMessage { optional string optional_string = 1; string normal_string = 2; }
Question: What is the difference between optional_string and normal_string other than name and tag?
I already read the following resources (they seem to be the only publicly available yet for v3 protobuf):
But they donโt even mention the optional keyword.
- Is
optional deprecated in proto3 since a field is always optional? - How can I force mandatory fields with proto3 to be completed if
required gone?
It seems that in proto3 you can no longer distinguish between undefined fields and fields set by the client for the (implicit) default value.
Is it best to wrap each proto3 message in a language-specific class? I use C ++ and I need to make sure certain fields are set. It seems that validation should be done manually in language-specific source text in contrast with proto2.
Can someone enlighten me, what is the best approach to apply proto3 restrictions, but allow the evolution of the circuit? At the moment, I think the new API should be written around proto3 messages, so the client does not deal directly with the code generated by proto3, but with custom API code. Is that right?
Maybe someone can show me a concrete example for discussion.
I'm pretty confused, as the v3 release notes say the following:
We recommend that new users of protocol buffers use proto3. However, we do not usually recommend that existing users migrate from proto2 from proto3 due to the incompatibility API, and we will continue to support proto2 for a long time.
If proto3 is the way to work, why is everything more complicated? It seems to me that I need to write a lot more code than with proto2.