DEV Community

Cover image for ProtocolBuffers - TL;DR
Ketan Parmar
Ketan Parmar

Posted on

ProtocolBuffers - TL;DR

  • Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.
  • Protocol buffers are also known as protobuf
  • Protocol buffers are developed by Google for internal use. It is available for the public in 2008.
  • Protobuf is binary serialize protocol, unlike JSON and XML which are text-based human-readable protocol.
  • It’s non-human-readable because of binary serialize.
  • Apache Thrift, Ion, Fast Buffers, FlatBuffers, Cap’n Proto, SBE (Simple Binary Encoding) are some of the alternatives of Protocol Buffers.
  • It emphasizes simplicity and performance
  • The current version is 3.14.0 which was released on Nov-2020.
  • It uses .proto file extension.
  • It has a language specification. (
  • To define structure in Protocol buffers. It uses “message” keyword. A message is like a class or structure in C++ and Java.
  • It also supports nested messages (structure) same as OOPs programming language.
  • Protocol Buffers support C++, C#, Dart, Go, Java, Python, Ruby and other popular languages.
  • It has double, float, int32, int 64, uint32, uint64, bool, string, bytes and many other data types. Data type also has default values like C++ or Java’s data type. - For string, the default value is the empty string, For bools, the default value is false, For numeric types, the default values is zero.
  • Protocol buffers support enums, Map, Any and Array.
  • Protocol buffers support optional, repeated and required field
  • Protocol buffers message has field number, field number must be a unique number in the message. The field number is used to identify the field in message binary format. The smallest field number you can specify is 1, and the largest is 229–1, or 536,870,911. You also cannot use the numbers 19000 through 19999. Github Repo:
  • Protocol buffers come with the command-line tool protoc. Protoc compiles .proto file into specific language code.
  • Example
Go Language output

protoc -I=$SRC_DIR — go_out=$DST_DIR $SRC_DIR/addressbook.proto
Enter fullscreen mode Exit fullscreen mode
Java output
protoc -I=$SRC_DIR — java_out=$DST_DIR $SRC_DIR/addressbook.proto
Enter fullscreen mode Exit fullscreen mode

Top comments (0)