美文网首页
protocol buffer的命令protoc整理

protocol buffer的命令protoc整理

作者: 瑜骐 | 来源:发表于2018-09-25 14:01 被阅读0次

    简介

    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 命令使用

    使用步骤如下:

    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
    
    命令行执行: windows protoc 命令行执行 写入绝对路径时候不支持中文目录,如这样写目录就不支持: protoc 中文目录在命令行中指定不支持 如果是非中文的目录则支持,如下图所示: 非中文目录支持命令行
    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,对应配置截图如下: include环境变量配置截图如下 对应命令行运行截图如下: 使用配置的include环境变量运行截图

    bat文件运行

    新建一个bat文件protoc.bat,内容如下所示:

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

    参考

    1. https://developers.google.com/protocol-buffers/docs/javatutorial

    相关文章

      网友评论

          本文标题:protocol buffer的命令protoc整理

          本文链接:https://www.haomeiwen.com/subject/sjgkoftx.html