Protocol Buffers

Protocol buffers are method of serializing structured data.

Goal

  • Want to use lingua franca in CS.
  • Simplicity and performance. In particular, it was designed to be smaller and faster than XML.

Components

  • Interface description language.
  • IDL compiler: Program that generate source code from the description.

HowTo

  1. Define structure at proto definition file (.proto)
  2. Compile it with protoc.
  3. Use generated file.

Example

$vi test.proto //define 
$protoc test.proto //compile to generate code
$ls
test.pb.cc //for cpp
test.pb.h

HowTo

Caution

  • Prefer use only optional and repeated.