随笔 - 70, 文章 - 0, 评论 - 9, 引用 - 0
数据加载中……

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文件

posted on 2011-01-20 09:20 seahouse 阅读(3408) 评论(0)  编辑 收藏 引用 所属分类: 数据


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理