Google Protocol Buffers是google出品的一个协议生成工具,特点就是跨平台,效率高,速度快,对我们自己的程序定义和使用私有协议很有帮助。
Protocol Buffers入门:
1、去 http://code.google.com/p/protobuf/downloads/list 下载一个源代码包和一个已编译好的二进制包
2、找一个Proto示例代码,使用命令
protoc -I=$SRC_DIR --java_out=$DST_DIR $SRC_DIR/addressbook.proto
将proto文件编译一下即可得到对应的Java源代码。例如 protoc -I=src --java_out=addressbook.proto。
Java项目配置:
1、先用
$ protoc --java_out=src/main/java -I../src ../src/google/protobuf/descriptor.proto
命令把源代码包中的descriptor.proto编译一下,生成一个类。
2、将第一步生成的那个文件连同源代码包中的java/src/main/java中的源代码,一起丢入你的项目工程,这就是基础类库了。
3、之后你就可以写自己的proto文件,然后编译,连同上面的基础类库丢入你的项目工程中,就可以运行了。
C#的配置:
1、Google本身不自带生成C#源码的功能,要使用C#,必须使用一个Csharp port,项目地址是:http://code.google.com/p/protobuf-csharp-port/
2、源码可以从SVN上面Download下来,Download下来之后,需要去下载一个NAnt,然后在项目源码目录下进行命令操作,用来编译生成可执行文件
nant clean build test dist
这步做完会生成几个文件:
ProtoGen.exe - the source code generator
Google.ProtocolBuffers.dll - the library part of the project
ProtoMunge.exe - tool to remove sensitive data from binary messages
ProtoDump.exe - tool to dump a binary message as text
ProtoBench.exe - tool to run performance benchmarks on binary messages
主要是第一个和第二个
第一个ProtoGen.exe是用来生成C#源码的
第二个Google.ProtocolBuffers.dll是用来在项目中进行引用的。
3、在源码中附带了记个proto文件,是根据C#版本专门修改过的,可以拿出来做生成测试,执行以下命令可以得到C#源文件:
protoc --descriptor_set_out=addressbook.protobin --proto_path=protos --include_imports protos\tutorial\addressbook.proto
protogen addressbook.protobin
如果想生成C#源码,需要执行第一步将源文件用Protoc编译一下,编译之后再用Protogen生成一份C#文件,会生成三个文件,只有 AddressBookProtos.cs有用,将这个文件连同Google.ProtocolBuffers.dll一起丢入项目,你就可以使用了。
分享到:
相关推荐
Google Protocol Buffers 在 c# 中的应用
Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. Latest Updates http://protobuf.googlecode.com/svn/trunk/CHANGES.txt Documentation Read the documentation....
中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程中文翻译Google Protocol Buffers中文教程
Protocol Buffers 2.4.1 jar
Google.ProtocolBuffers动态库反编译生成的源代码,用于学习。
google protocol buffers 官网中文教程
google Protocol Buffers
Google Protocol Buffers浅析
Google.ProtocolBuffers.dll类库
google protocol buffers document
Google Protocol Buffers 是一种轻便高效的结构化数据存储格式,可以用于结构化数据串行化,或者说序列化。它很适合做数据存储或 RPC 数据交换格式。可用于通讯协议、数据存储等领域的语言无关、平台无关、可扩展的...
Protocol Buffers - 谷歌的数据交换格式
Protocol Buffers Java开发包(protobuf-java-2.3.0.jar)
Protocol Buffers v3.0.0-alpha-1(Java) release 版本和源代码
在vs2015下编译生成的,最新版本的google的protocol buffers数据交互协议库,可以用于诸如网络传输、配置文件、数据存储等诸多领域。源码里包含了x86和x64编译的库以及一个x86下的可编译运行的测试Demo。
This project contains the implementation of Protocol Buffers for Delphi. From the project was implemented limited functionality necessary for a specific project. At that time, I do not see any sense ...
ProtocolBuffers 英文版PDF 不懂别下
protobuf-swift, 谷歌ProtocolBuffers的谷歌 用于Swift的协议缓冲器 Swift中协议缓冲区的实现。协议缓冲区是一种以高效但可扩展的格式编码结构化数据的方法。 这个项目是基于Google的协议缓冲区的实现。 有关更多...
ProtocolBuffers在即时通讯系统中的应用研究_田源.pdf