Measures Concepts
GitHub icon

Protocol Buffers

Protocol Buffers - Interface design language

< >

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

#139on 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 Token Example
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 · Search · Add Language · Features · Creators · Resources · About · Blog · Acknowledgements · Queries · Stats · Sponsor · Day 605 · feedback@pldb.io · Logout