当前位置:网站首页>Protocol Buffer 使用
Protocol Buffer 使用
2022-08-01 20:27:00 【云满笔记】
1. Protocol Buffer 使用
1.1. Prerequisites
- Go, any one of the three latest major releases of Go.
For installation instructions, see Go’s Getting Started guide.
- Protocol buffer compiler,
protoc, version 3.
For installation instructions, see Protocol Buffer Compiler Installation.
- Go plugins for the protocol compiler:
Install the protocol compiler plugins for Go using the following commands:
$ go install google.golang.org/protobuf/cmd/[email protected]
$ go install google.golang.org/grpc/cmd/[email protected]
Update your PATH so that the protoc compiler can find the plugins:
$ export PATH="$PATH:$(go env GOPATH)/bin"
1.2. protoc 工具使用
前面我们用 protoc 来编译 .proto 文件为 go 语言, 为了支持编译为 go, 需要安装 protoc-gen-go 插件, C# 可以安装 protoc-gen-zsharp 插件。
需要注意的是, 转换 .proto 为编程语言, 不一定要安装 protoc。
例如 C# 只需要把 .proto 文件放到项目中, 通过包管理器安装一个库, 就会自动转换为相应的代码。
回归正题, 聊一下 protoc 编译 .proto 文件的命令。
protoc 常用的参数如下:
--proto_path=. #指定proto文件的路径, 填写 . 表示就在当前目录下
--go_out=. #表示编译后的文件存放路径; 如果编译的是 csharp, 则 --csharp_out
--go_opt={
xxx.proto}={
xxx.proto的路径} # 示例: --go_opt=Mprotos/bar.proto=example.com/project/protos/foo
最简单的编译命令:
protoc --go_out=. *.proto
--{xxx}_out 指令是必须的, 因为要输出具体的编程语言代码。
这个输出文件的路径是执行命令的路径, 如果我们不在 .proto 文件目录下执行命令, 则输出的代码便不是相同位置了。为了解决这个问题, 我们可以使用:
--go_opt=paths=source_relative
这样在别的地方执行命令, 生成的代码会跟 .proto 文件放在相同的位置。
1.3. protoc-gen-go
protoc-gen-go is a plugin for the Google protocol buffer compiler to generate Go code. Install it by building this program and making it accessible within your PATH with the name:
protoc-gen-go
The ‘go’ suffix becomes part of the argument for the protocol compiler, such that it can be invoked as:
protoc --go_out=paths=source_relative:. path/to/file.proto
This generates Go bindings for the protocol buffer defined by file.proto. With that input, the output will be written to:
path/to/file.pb.go
See the README and documentation for protocol buffers to learn more:
https://developers.google.com/protocol-buffers/
1.4. 参考
边栏推荐
- "No title"
- Custom command to get focus
- 密码学的基础:X.690和对应的BER CER DER编码
- 17. Load balancing
- 互联网大厂研发流程
- AQS原理和介绍
- 58: Chapter 5: Develop admin management services: 11: Develop [admin face login, interface]; (not measured) (using Ali AI face recognition) (demonstrated, using RestTemplate to implement interface cal
- XSS range intermediate bypass
- 【多任务学习】Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18
- 瀚高数据导入
猜你喜欢

Does LabVIEW really close the COM port using VISA Close?

Buttons with good user experience should not have hover state on mobile phones

数据库单字段存储多个标签(位移操作)

WhatsApp群发实战分享——WhatsApp Business API账号

【kali-信息收集】(1.3)探测网络范围:DMitry(域名查询工具)、Scapy(跟踪路由工具)

Debug一个ECC的ODP数据源
![[Multi-task learning] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18](/img/f3/a8813759e5b4dd4b4132e65672fc3f.png)
[Multi-task learning] Modeling Task Relationships in Multi-task Learning with Multi-gate Mixture-of-Experts KDD18

WhatsApp group sending actual combat sharing - WhatsApp Business API account

密码学的基础:X.690和对应的BER CER DER编码

泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
随机推荐
MongoDB快速上手
Does LabVIEW really close the COM port using VISA Close?
根据Uniprot ID/PDB ID批处理获取蛋白质.pdb文件
Compose实战-实现一个带下拉加载更多功能的LazyColumn
【七夕特别篇】七夕已至,让爱闪耀
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
面试突击70:什么是粘包和半包?怎么解决?
【无标题】
【Social Media Marketing】How to know if your WhatsApp is blocked?
如何写一个vim插件?
KDD2022 | Self-Supervised Hypergraph Transformer Recommendation System
【kali-信息收集】(1.4)识别活跃的主机/查看打开的端口:Nmap(网络映射器工具)
【节能学院】推进农业水价综合改革的意见解读
使用Huggingface在矩池云快速加载预训练模型和数据集
第60章 ApplicationPart自动集成整体性和独立性插件项
57:第五章:开发admin管理服务:10:开发【从MongoDB的GridFS中,获取文件,接口】;(从GridFS中,获取文件的SOP)(不使用MongoDB的服务,可以排除其自动加载类)
线上问题排查常用命令,总结太全了,建议收藏!!
WhatsApp群发实战分享——WhatsApp Business API账号
小数据如何学习?吉大最新《小数据学习》综述,26页pdf涵盖269页文献阐述小数据学习理论、方法与应用
18. Distributed configuration center nacos