惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - mjgforever

sp_executesql和临时表的用法 51 条 ActionScript 3.0 和 Flex 优化技术与实践 open source Flex project list Open Source Replication and Synchronization Tools Written in Java 用SyncML进行异构数据库复制 WF学习系列之六:工作流和宿主程序通讯异常引发的思考 - mjgforever - 博客园 WF学习系列之五:状态机工作流学习 WF学习系列之四:顺序工作流控制台应用程序模板介绍 WF学习系列之三:RuleSet知识点概述 WF学习系列之二:开发工作流知识点概述 WF学习系列之一:WF基本知识点概述 abstract, virtual, override, new 关键字的用法 ArcIMS 安装指南 Protocol Buffers 简介 Protocol Buffers:Google 的数据交换格式 微软vs.VMware:虚拟化中的真实战争 文本文件与二进制文件 字符编码简介:ASCII,Unicode,UTF-8,GB2312 Adobe Flex的十大误解
Google推出Protocol Buffers:争夺网络时代数据格式
mjgforever · 2008-07-10 · via 博客园 - mjgforever

北京时间7月8日消息,据国外媒体报道,谷歌本周一发布了该公司内部使用的开放源代码数据描述语言Protocol Buffers。Protocol Buffers与XML相似,但更简单、更小、更快。

谷歌开放源代码项目经理克里斯·迪邦纳(Chris DiBona)在一篇博文中写道,“我们在网络上传输或在磁盘上存储的几乎所有结构化信息都采用了这种语言。我们认为Protocol Buffers可能对其他人也有用,因此我们决定将它发布为开放源代码软件。”

谷歌软件工程师肯顿·瓦尔达(Kenton Varda)在公司的开放源代码博客上发表文章称,谷歌使用数千种不同的数据格式,其中大多数都是结构化数据格式。XML无法胜任对这些海量结构化数据编码的重任,谷歌于是开发了Protocol Buffers。

瓦尔达将Protocol Buffers比作是一种界面描述语言,但没有界面描述语言的复杂性。他说,Protocol Buffers的主要设计目标之一是简洁。对Protocol Buffers进行解析的速度也很快,比XML要快出至少一个量级。

谷歌的文档称,与具有可比性的XML文件相比,Protocol Buffers文件的尺寸要小3-10倍,解析速度要快20-100倍。

谷歌发布的免费文件包括采用Java、Python和C++编程语言编写的Protocol Buffers编译器源代码。

谷歌在一份文档中表示,该公司还计划将许多其它软件项目发布为开放源代码软件。因为这些项目会用到Protocol Buffers,因此谷歌决定首先将它发布为开放源代码软件。

在Web 2.0 时代,XML格式由于AJAX的风行以及RSS的普及而异军突起。不过随着Python和Ruby On Rails的走红,以及各种API的发布,YAML,JSON也逐渐成名。此次,Google推出了Protocol Buffers,是想让广大编程者方便地使用Google网络传输数据的格式。

什么是Protocol Buffers?

这是Protocol Buffers主页上的一段代码:

message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;

enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
} message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}

repeated PhoneNumber phone = 4;
}

而Protocol Buffers的作用,就是将以上格式的数据类型,自动生成Java, Python, and C++的代码,然后以下一系列代码就可以直接调用了:(C++中)

Person person;
person.set_name("John Doe");
person.set_id(1234);
person.set_email("jdoe@example.com");
fstream output("myfile", ios::out | ios::binary);
person.SerializeToOstream(&output); fstream input("myfile", ios::in | ios::binary);
Person person;
person.ParseFromIstream(&input);
cout << "Name: " << person.name() << endl;
cout << "E-mail: " << person.email() << endl;

相信所有C++编程者都为定义set,get之类的函数感到烦人过吧,而Google做的就是帮助你省去这些麻烦,构造更利于网络传输的数据结构。

与XML的比较 优势

  • 更简单
  • 比XML小3到10倍体积
  • 比XML快20到100倍
  • 更不容易引起歧义
  • 自动生成可编程的类代码
    比较:
    cout << "Name: " << person.name() << endl;

    cout << "E-mail: " << person.email() << endl;
    cout << "Name: "
           << person.getElementsByTagName("name")->item(0)->innerText()
           << endl;
    cout << "E-mail: "
           << person.getElementsByTagName("email")->item(0)->innerText()
           << endl; 劣势

  • 没有层次,所以无法和HTML标记语言打交道
  • 如果没有message的定义,根本无法知道message的意思,而XML是自解释型的。
    Protocol Buffer主页    Protocol Buffer下载