GoogleProtocolBuffer了解

前言

睡前学习一下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 是一个可选的成员,即消息中可以不包含该成员。

编译proto文件

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计