Protocol Buffers - Hello World

  • brew install protobuf
  • compile protocol
export SRC_DIR=.
export DST_DIR=.
protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/hello.proto
  • compile cpp
clang++ -std=c++11 main.cpp hello.pb.cc -I /usr/local/include -L /usr/local/lib -lprotobuf
  • run
./a.out
  • output
100
200
12345
  • serialized file: ./test_data.log