我是靠谱客的博主 幸福热狗,这篇文章主要介绍Golang中Proto编写和生成,现在分享给大家,希望可以做个参考。

test.proto文件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
syntax = "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
8
syntax = "proto3"; package go; import "test.proto"; //引入其他proto文件 message Test1 { go.Test testFlag = 1; string name = 2; }

生成go文件命令:

复制代码
1
protoc --go_out=./go/ -I ./proto test.proto test1.proto

protobuf和GO数据类型对比

 probufgo
布尔类型boolbool
双精度浮点dobulefloat64
单精度浮点floatflaot32
32位整数int32int32
无符号32位整数unit32unit32
64位整数int64int63
无符号64位整数unit64unit64

 

转载于:https://my.oschina.net/u/1780148/blog/1845071

最后

以上就是幸福热狗最近收集整理的关于Golang中Proto编写和生成的全部内容,更多相关Golang中Proto编写和生成内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(86)

评论列表共有 0 条评论

立即
投稿
返回
顶部