Understanding Google Protocol Buffer

Introduction

Learning about Google Protocol Buffer before bed

Installing the protobuf compiler

Start the latest Ubuntu Docker image, run apt install protobuf-compiler

Writing a .proto file

nano lm.helloworld.proto

Then input:

package lm; 
message helloworld 
{ 
   required int32     id = 1;  // ID 
   required string    str = 2;  // str 
   optional int32     opt = 3;  //optional field 
}

In the example above, the package name is lm, and a message called helloworld is defined. This message has three members: an int32 type id, a string type member str. opt is an optional member, meaning the message may not contain this member.

Compiling the proto file

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy