Top 1K Features Creators Events Podcasts Books Extensions Interviews Blog Explorer CSV

Protocol Buffers

< >

Protocol Buffers is an open source interface design language created in 2008.

#89on PLDB 16Years Old 24kRepos
Homepage · Wikipedia · Docs

Protocol Buffers is a method of serializing structured data. It is useful in developing programs to communicate with each other over a wire or for storing data. The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data. Read more on Wikipedia...


Example from the web:
message Person { required string name = 1; required int32 id = 2; optional string email = 3; }
Example from Linguist:
package tutorial; option java_package = "com.example.tutorial"; option java_outer_classname = "AddressBookProtos"; message Person { required string name = 1; required int32 id = 2; optional string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { required string number = 1; optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phone = 4; } message AddressBook { repeated Person person = 1; }
Example from Wikipedia:
// polyline.cpp #include "polyline.pb.h" // generated by calling "protoc polyline.proto" Line* createNewLine(const std::string& name) { // create a line from (10, 20) to (30, 40) Line* line = new Line; line->mutable_start()->set_x(10); line->mutable_start()->set_y(20); line->mutable_end()->set_x(30); line->mutable_end()->set_y(40); line->set_label(name); return line; } Polyline* createNewPolyline() { // create a polyline with points at (10,10) and (20,20) Polyline* polyline = new Polyline; Point* point1 = polyline->add_point(); point1->set_x(10); point1->set_y(10); Point* point2 = polyline->add_point(); point2->set_x(20); point2->set_y(20); return polyline; }
Protocol Buffers Keywords
syntax import weak public package option repeated oneof map reserved to max enum message service rpc stream returns package optional true false

Language features

Feature Supported Example Token
Integers ✓ // \d+[LlUu]*
Floats ✓ // (\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*
Hexadecimals ✓ // 0x[0-9a-fA-F]+[LlUu]*
Octals ✓ // 0[0-7]+[LlUu]*
Access Modifiers ✓
Booleans ✓ true false
MultiLine Comments ✓ /* A comment */ /* */
Strings ✓
Comments ✓ // A comment
Line Comments ✓ // A comment //
Semantic Indentation X
View source
- Build the next great programming language · About · Search · Keywords · Livestreams · Labs · Resources · Acknowledgements · Part of the World Wide Scroll