There is a Style Guide for Protocol Buffers. But it does not clearly say how a .proto
file should be named.
MyProtos.proto
, my_protos.proto
or my-protos.proto
, which is the better name?
A . proto file is similar to a JSON file in that it represents structured data, but you can run a compiler on the . proto file to generate code that can read and write the data in the programming language of your choice. For more information about protocol buffers, see Protocol Buffer Developer Guide on Google's site.
Protobuf strings are always valid UTF-8 strings. See the Language Guide: A string must always contain UTF-8 encoded or 7-bit ASCII text.
Protobuf is a binary format, so reading and writing should be done as binary, not text. If you don't want binary format, you should consider using something other than protobuf (there are lots of textual data formats, such as XML, JSON, CSV); just using text abstractions is not enough.
As JSON is textual, its integers and floats can be slow to encode and decode. JSON is not designed for numbers. Also, Comparing strings in JSON can be slow. Protobuf is easier to bind to objects and faster.
I don't believe there's an appropriate answer to how any file "should be named" other than aim for consistency and clarity.
Consistency would mean following the file-naming conventions your project already has for sources and headers. If your sources are named using camel-case, do the same for the proto files. The most common choice seems to me to be the my_protos.proto
version.
Clarity to me means that the file name should give some clue as to the contents. I generally favour naming files after the class which they implement, and usually have a separate file (pair) per class. I would recommend the same for the proto files. I prefer several small proto files each defining a single Message
or very closely related Messages
over a single huge proto file defining all your Messages
in the one place.
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