test.proto文件
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15syntax = "proto3";//指定proto文件版本 package go; //指定文件缩放的package名 //定义对象 message Test { enum PhoneType //枚举消息类型 { MOBILE = 0; //proto3版本中,首成员必须为0,成员不应有相同的值 HOME = 1; WORK = 2; } int32 flag = 1; //定义变量、类型以及消息中的位置 map<string, string> extension = 2; //定义map对象 repeated int32 list = 3; //定义整型数组 PhoneType type = 4;//定义枚举类型 }
test1.proto文件
复制代码
1
2
3
4
5
6
7
8syntax = "proto3"; package go; import "test.proto"; //引入其他proto文件 message Test1 { go.Test testFlag = 1; string name = 2; }
生成go文件命令:
复制代码
1protoc --go_out=./go/ -I ./proto test.proto test1.proto
protobuf和GO数据类型对比
probuf | go | |
---|---|---|
布尔类型 | bool | bool |
双精度浮点 | dobule | float64 |
单精度浮点 | float | flaot32 |
32位整数 | int32 | int32 |
无符号32位整数 | unit32 | unit32 |
64位整数 | int64 | int63 |
无符号64位整数 | unit64 | unit64 |
转载于:https://my.oschina.net/u/1780148/blog/1845071
最后
以上就是幸福热狗最近收集整理的关于Golang中Proto编写和生成的全部内容,更多相关Golang中Proto编写和生成内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复