Member-only story
Implements proto file — Protocol Buffer
Protocol Buffers provide a method for encoding data in a format that is both easy for machines to read, transfer, and process, as well as readable by humans.
Protocol Buffers have a syntax that resembles the following and its file extension is .proto
syntax = "proto3";
option go_package = "example.com/project/protos/fizz";
message Person {
int32 id = 1;
string name = 2;
}
Are there any alternative formats for organizing these data?
Indeed, there are various formats available for data representation such as XML and JSON are the most famous useable format but protocol buffer is fast in terms of performance in comparison to other formats.
In this article we are going to address the following points:
- How to write .proto file
- How to generate programming code using a proto file
How to write a proto file
- The file began with this line
syntax = "proto3";
This line tells the compiler about the version that we are using. Instead of proto3, we could use proto2 but version 3 is the latest version.
- Define package
package foo;