Top 1,000 Features Creators Events Podcasts Extensions Blog Explorer CSV Download

Protocol Buffers

< >

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

#82on PLDB 16Years Old 24kRepos

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 ยท Resources ยท Acknowledgements ยท Part of the World Wide Scroll