Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is best file naming style for protobuf? [closed]

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?

like image 342
Yang Bo Avatar asked Dec 13 '12 14:12

Yang Bo


People also ask

What format is proto file?

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.

What encoding does Protobuf use?

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.

Is Protobuf text or binary?

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.

Should I use Protobuf or JSON?

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.


1 Answers

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.

like image 95
Fraser Avatar answered Oct 13 '22 01:10

Fraser