简介
Google Protocol Buffer( 简称 Protobuf) 是 Google 公司内部的混合语言数据标准,目前已经正在使用的有超过 48,162 种报文格式定义和超过 12,183 个 .proto 文件。他们用于 RPC 系统和持续数据存储系统。
Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的序列化结构数据格式。目前提供了 C++、Java、Python 三种语言的 API。
Protocol buffers are a flexible, efficient, automated mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages. You can even update your data structure without breaking deployed programs that are compiled against the "old" format.
protoc 命令使用
使用步骤如下:
- 下载:https://github.com/protocolbuffers/protobuf/releases/tag/v3.6.1
- 解压: 解压到任意目录
-
配置path: 在windows中配置对应的path路径,如下图所示
windows path路径配置
- 执行protoc命令:
protoc --proto_path=IMPORT_PATH1 --proto_path=IMPORT_PATH2 --cpp_out=DST_DIR --java_out=DST_DIR --python_out=DST_DIR --go_out=DST_DIR --ruby_out=DST_DIR --objc_out=DST_DIR --csharp_out=DST_DIR path/to/file.proto
命令行执行:



F:\protoc-3.6.1-win32\bin>protoc.exe -I=F:\protoc-3.6.1-win32\include -I=. --ja
a_out=. addressbook.proto
配置对应的include环境变量
未了避免每次都要指定protocol buffer对应的include路径,可以在windows 环境变量中新建一个环境变量:PROTOC_INCLUDE,其值指向protocol buffer对应的include目录,如我的就是F:\protoc-3.6.1-win32\include,对应配置截图如下:

bat文件运行
新建一个bat文件protoc.bat,内容如下所示:
@echo off
@echo off
protoc.exe -I=%PROTOC_INCLUDE% %*
像protoc.exe一样使用protoc.bat,唯一的好处就是不用指定protocol buffer对应的include目录了,运行命令截图如下所示:

网友评论