proto2和proto3生成go代码的区别

 

proto2和proto3

proto2生成的go文件中,结构体成员使用的是指针。

 

废话不说,开始测试!

 

文件名:test.proto,下面分别是proto3和proto2

1 syntax = "proto3";
2 package example;
3 option go_package="../testpb";
4 
5 message Person {
6     string Name = 1;
7     int32 Age = 2;
8     string From = 3;
9 }

1
syntax = "proto2"; 2 package example; 3 option go_package="../testpb"; 4 5 message Person { 6 required string Name = 1; 7 required int32 Age = 2; 8 required string From = 3; 9 }

 

 go语言代码生成:

protoc --go_out=. .\test.proto

生成如下test.pb.go文件。

 

 比较proto3和proto2时生成的go文件,发现proto2生成的go文件中,结构体成员使用的是指针,如下:

proto3

 

proto2

 

 

 

beyound compare进行比较

 

 

 

 

 

这里是比较生成go代码的差别,来感受proto3和proto2

 

posted on 2021-10-08 16:50  yuzyong  阅读(700)  评论(0编辑  收藏  举报