Protocol Buffers (协议缓冲) 介绍及安装

Protocol Buffers是Google公司开发的一种数据描述语言,类似于XML能够将结构化数据序列化,可用于数据存储、通信协议等方面。现阶段支

持C++、JAVA、Python等三种编程语言。

它是一种二进制的格式,比使用 xml 进行数据交换快许多。可以把它用于分布式应用之间的数据通信或者异构环境下的数据交换。


http://code.google.com/intl/zh-CN/apis/protocolbuffers/docs/overview.html (介绍)
http://code.google.com/p/protobuf/downloads/list  (下载)

下载安装
编译安装(mingw):
  $ ./configure
  $ make
  $ make check
  $ make install
详细见:README.txt
如果是Micosoft Visual C++,请参考vsprojects/readme.txt.

在MSYS环境下安装完后会自动设置好MSYS下的环境变量(PATH)。建议下载代码的目录也就是将要安装好的目录。


value types can be numbers (integer or floating-point), booleans, strings, raw bytes, or even (as in the example above) other

protocol buffer message types. 
specify optional fields, required fields, and repeated fields.

once you've defined your messages, you run the protocol buffer compiler for your application's language on your .proto file to

generate data access classes. These provide simple accessors for each field (like query() and set_query()) as well as methods to

serialize/parse the whole structure to/from raw bytes.

You can add new fields to your message formats without breaking backwards-compatibility; old binaries simply ignore the new field

when parsing. So if you have a communications protocol that uses protocol buffers as its data format, you can extend your protocol

without having to worry about breaking existing code.

Why not just use XML?
Protocol buffers have many advantages over XML for serializing structured data. Protocol buffers:
are simpler
are 3 to 10 times smaller
are 20 to 100 times faster
are less ambiguous
generate data access classes that are easier to use programmatically.

However, protocol buffers are not always a better solution than XML – for instance, protocol buffers would not be a good way to

model a text-based document with markup (e.g. HTML), since you cannot easily interleave structure with text. In addition, XML is

human-readable and human-editable; protocol buffers, at least in their native format, are not. XML is also – to some extent – self-

describing. A protocol buffer is only meaningful if you have the message definition (the .proto file).

 To build and install your compiler, follow the instructions in the README.


FAQ:
1  编译安装时(make)出现错误:
In file included from google/protobuf/compiler/command_line_interface.cc:54:
./google/protobuf/compiler/subprocess.h:80: error: extra qualification
'google::
protobuf::compiler::Subprocess::' on member 'Win32ErrorMessage'
解决:将src/google/protobuf/compiler/subprocess.h:80的
static string Subprocess::Win32ErrorMessage(DWORD error_code); 修改为:
static string Win32ErrorMessage(DWORD error_code);
参考: http://www.fourmilab.ch/fourmilog/archives/2006-05/000699.html

2  编译时(make)出现错误
g++.exe: c:/msys/1.0/mingw/lib/gcc/mingw32/4.4.0/libstdc++.dll.a: No such file or directory
解决:打开mingw下(D:\Qt\2010.05\mingw\lib\gcc\mingw32\4.4.0)的libstdc++.la (C:\Qt\2010.05\mingw\lib\gcc\mingw32\4.4.0下),将其中的
# Names of this library.

library_names='libstdc++.dll.a'
修改为:
# Names of this library.
library_names='libstdc++.a'

3  编译时(make)出现弹出框错误
"无法启动此程序,因为计算机中丢失libgcc_s_dw2-1.dll。尝试重新安装该程序以解决问题"  或者 
the program can't start because libgcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem. 
检查了windows的环境变量和msys里的环境变量(PATH),都已经包含了C:\Qt\2010.05\mingw\bin,且该目录下有 libgcc_s_dw2-1.dll,但

问题仍然存在
解决:将 libgcc_s_dw2-1.dll(C:\Qt\2010.05\mingw\bin)拷贝到exe的目录下(protoc.exe所在的目录C:\TDDOWNLOAD\protobuf-

2.3.0\src)
网上有说到更新libgcc_s_dw2-1.dll 的方法,未试。
参考:http://forums.codeblocks.org/index.php?topic=11313.0


4  在win7上会存在:执行make install时出现/bin/sh: /bin/install: Permission denied错误。
   解决:将环境变量增加:path:D:\protobuf-2.3.0\src。其中存在protoc.exe文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值