前言
睡前学习一下Google protocol buffer
安装protobuf编译器
启动最新版的ubuntu docker镜像,运行apt install protobuf-compiler
书写 .proto 文件
nano lm.helloworld.proto
然后输入
package lm;
message helloworld
{
required int32 id = 1; // ID
required string str = 2; // str
optional int32 opt = 3; //optional field
}
在上例中,package 名字叫做 lm,定义了一个消息 helloworld,该消息有三个成员,类型为 int32 的 id,另一个为类型为 string 的成员 str。opt 是一个可选的成员,即消息中可以不包含该成员。