Besides the rather short Google provided style guide, here are my thoughts on naming Google Protocol Buffer messages.
Use "Message" at the end of message types names.
For Java users, it appears that having java_outer_classname
end in Protos
is standard.
com.example.project.protobuf.MyProtos
, but I don't see a reason to keep it there given that we need to have a containing class, so it could be moved to com.example.protobuf.MyProtos
unless there are no classes in the project's top package.Start enums at 0 to match C/C++.
Use a singular name for a repeated field.
Are there any other standards people use or differ from these?
proto file should be named. MyProtos. proto , my_protos. proto or my-protos.
Renaming a field - With Protobuf content, the field names are only used in generated code. The field number is used to identify fields on the network. Renaming a field isn't a protocol breaking change for Protobuf. However, if a server is using JSON content then renaming a field is a breaking change.
Field numbers are an important part of Protobuf. They're used to identify fields in the binary encoded data, which means they can't change from version to version of your service. The advantage is that backward compatibility and forward compatibility are possible.
Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.
Disclaimer: answer from a Googler using protobufs on a daily basis. I'm by no means representing Google in any way.
Don't do that. Compiled protocol buffers are just a class definition specified by the language you are using, with some improvements. Adding "Message" is extra verbosity. Normally you just use protocol buffers without other class definitions, and even if you use other class definitions, just import java_outer_classname and do a dot from that. You can even put full path of a thing in code to erase one line of import, no problem.
Although not specified officially, it sounds like a good suggestion, because normally you put more than one proto inside a folder.
You normally start with 0. See the protocol buffer language guide.
Yes. Read the following to get some feeling using it: https://developers.google.com/protocol-buffers/docs/javatutorial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With