- 浏览: 171501 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
boz.lee:
不错, 好多地方因为这里而出错
全局变量和局部变量在内存里的区别 -
issllx:
看到此文后对iteye深表遗憾
Yahoo S4 -
wohenshuaiba:
请问你有这个的代码吗?
k均值聚类(K-means) -
yxwang0615:
大神:
apr-1.3.3.tar.bz2
apr-util- ...
log4cxx编译方法 -
yxwang0615:
比csdn上的说的清楚干练,早看到这个就好了,我编了一天
p ...
log4cxx编译方法
Welcome to the developer documentation for protocol buffers – a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more. This documentation is aimed at Java, C++, or Python developers who want to use protocol buffers in their applications. This overview introduces protocol buffers and tells you what you need to do to get started – you can then go on to follow the tutorials or delve deeper into protocol buffer encoding. API reference documentation is also provided for all three languages, as well as language and style guides for writing 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. You specify how you want the information you're serializing to be structured by defining protocol buffer message types in As you can see, the message format is simple – each message type has one or more uniquely numbered fields, and each field has a name and a value type, where 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, allowing you to structure your data hierarchically. You can specify optional fields, required fields, and repeated fields. You can find more information about writing Once you've defined your messages, you run the protocol buffer compiler for your application's language on your Then, later on, you could read your message back in: 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. You'll find a complete reference for using generated protocol buffer code in the API Reference section, and you can find out more about how protocol buffer messages are encoded in Protocol Buffer Encoding. Protocol buffers have many advantages over XML for serializing structured data. Protocol buffers: For example, let's say you want to model a while the corresponding protocol buffer message (in protocol buffer text format) is: When this message is encoded to the protocol buffer binary format (the text format above is just a convenient human-readable representation for debugging and editing), it would probably be 28 bytes long and take around 100-200 nanoseconds to parse. The XML version is at least 69 bytes if you remove whitespace, and would take around 5,000-10,000 nanoseconds to parse. Also, manipulating a protocol buffer is much easier: Whereas with XML you would have to do something like: 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 Download the package – this contains the complete source code for the Java, Python, and C++ protocol buffer compilers, as well as the classes you need for I/O and testing. To build and install your compiler, follow the instructions in the README. Once you're all set, try following the tutorial for your chosen language – this will step you through creating a simple application that uses protocol buffers. Protocol buffers were initially developed at Google to deal with an index server request/response protocol. Prior to protocol buffers, there was a format for requests and responses that used hand marshalling/unmarshalling of requests and responses, and that supported a number of versions of the protocol. This resulted in some very ugly code, like: Explicitly formatted protocols also complicated the rollout of new protocol versions, because developers had to make sure that all servers between the originator of the request and the actual server handling the request understood the new protocol before they could flip a switch to start using the new protocol. Protocol buffers were designed to solve many of these problems: However, users still needed to hand-write their own parsing code. As the system evolved, it acquired a number of other features and uses: Protocol buffers are now Google's lingua franca for data – at time of writing, there are 48,162 different message types defined in the Google code tree across 12,183Developer Guide
.proto
files.What are protocol buffers?
How do they work?
.proto
files. Each protocol buffer message is a small logical record of information, containing a series of name-value pairs. Here's a very basic example of a .proto
file that defines a message containing information about a person: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;
}
.proto
files in the Protocol Buffer Language Guide..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 – so, for instance, if your chosen language is C++, running the compiler on the above example will generate a class called Person
. You can then use this class in your application to populate, serialize, and retrieve Person
protocol buffer messages. You might then write some code like this: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;
Why not just use XML?
person
with a name
and an email
. In XML, you need to do: <person>
<name>John Doe</name>
<email>jdoe@example.com</email>
</person>
# Textual representation of a protocol buffer.
# This is *not* the binary format used on the wire.
person {
name: "John Doe"
email: "jdoe@example.com"
}
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;
.proto
file).Sounds like the solution for me! How do I get started?
A bit of history
if (version == 3) {
...
} else if (version > 4) {
if (version == 5) {
...
}
...
}
.proto
files. They're used both in RPC systems and for persistent storage of data in a variety of storage systems.
发表评论
-
小对象的分配技术
2011-03-21 12:01 1466小对象分配技术是Loki提高效率的有效途径,Loki里广 ... -
Techniques of Protocol Buffers Developer Guide
2010-12-07 10:39 1124Techniques Streaming Multip ... -
Protocol Buffer Basics: C++
2010-12-07 10:38 1034Protocol Buffer Basics: C++ ... -
Encoding of Protocol Buffers Developer Guide
2010-12-07 10:37 940Encoding A Simple Message ... -
Style Guide of Protocol Buffers Developer Guide
2010-12-07 10:36 786Style Guide This document pr ... -
Language Guide of Protocol Buffers Developer Guide
2010-12-07 10:34 1048Language Guide Defining A M ... -
字节序
2010-12-01 21:03 953这几天又开始做网络方面的应用了,既然是网络编程,字节序肯定 ... -
全局变量和局部变量在内存里的区别
2010-11-09 21:55 2221一、预备知识—程序的内存分配 一个由c/C++编译 ... -
JobFlow要继续考虑的问题
2010-09-17 22:35 938小记: 1.把作业队列的概念扩展为作业池JobPool,提供 ... -
C++单例不可继承
2010-09-17 17:24 1490C++语言和单例的特性决定了单例不可继承。 单例有如下几项要 ... -
C++静态成员与静态成员函数小结
2010-09-16 15:48 1055类中的静态成员真是个让人爱恨交加的特性。我决定好好总结一下静态 ... -
log4cxx编译方法
2010-09-08 10:30 19991、下载http://logging.apache.o ... -
优秀的框架工具
2010-09-08 10:13 1139zookeeper Hadoop的子项目,可靠地分布式小文件 ... -
关于auto_ptr的忠告
2010-08-26 16:21 9211.auto_ptr不能用于数组,因为它调用的是delet ... -
snprintf与strncpy效率对比
2010-07-20 09:31 1583一直以为strncpy效率优于snprintf. 无意中在网上 ... -
用Valgrind查找内存泄漏和无效内存访问
2010-07-20 09:29 1958Valgrind是x86架构Linux上的多重用途代码剖析和内 ... -
头文件互包含于名字空间的相关问题
2010-07-17 20:27 1057c/c++里面头文件的使用 ... -
C++库介绍
2010-04-02 16:30 1522基础类1、 Dinkumware C++ ... -
C++中头文件相互包含的几点问题
2010-04-02 16:29 1029一、类嵌套的疑问 C++ ...
相关推荐
for MTL in Deep Learning, gives an overview of the literature, and discusses recent advances. In particular, it seeks to help ML practitioners apply MTL by shedding light on how MTL works and ...
### GSM系统概述与协议架构详解 #### 一、GSM系统的背景与发展 全球移动通信系统(Global System for Mobile Telecommunications,简称GSM)是欧洲电信标准协会(CEPT)定义的一套标准化体系,旨在为泛欧地区的...
zebos 7.5.1 guide is for routing engineers and other networking professionals who need an overview of the functions and features of the ZebOS.
Overview of data mining. Emphasis is placed on basic data mining concepts. Techniques for uncovering interesting data patterns hidden in large data sets.
unit 1 overview of IT industry
Overview of the OMG Data Distribution Service
Overview of the System Engineering Process System Engineering 系统工程 信息化 ERP 大数据
An overview of gradient descent optimization algorithms
A Technical Overview of VP9--the Latest Open-Source Video Codec Google has recently finalized a next generation open-source video codec called VP9, as part of the libvpx repository of the WebM project...
overview of MTL by first giving a definition of MTL. Then several different settings of MTL are introduced, including multi-task supervised learning, multi-task unsupervised learning, multi-task semi...
If Alice and Bob each know their own private key and the other's public key, they can communicate securely, through any number of public key based protocols such as IPSec, PGP, S/MIME, or SSL....
its results, and then vanished back under the same cloak of secrecy under which it had been developed. Now for the first time, details of the architecture and algorithms can be revealed.
该文件为CCSDS发布的《空间通信协议概览》(Overview of Space Communications Protocols),版本号为CCSDS 130.0-G-2,属于绿色手册系列,发布日期为2007年12月。该文档作为一份信息报告,详细介绍了由CCSDS推荐的...
HEVC/H.265标准综述文章 视频编码,算法,H.264/AV1 Inter prediction Intra prediciton Overview High efficiency video coding (HEVC) standard PDF
The RANdom SAmple Consensus (RANSAC) algorithm proposed by Fischler and Bolles [1] is a general parameter estimation approach designed to cope with a large proportion of outliers in the input data....
Abstract: Servlet program running in the server-side, dynamically generated Web page with the traditional CGI and many other similar compared to CGI technology, Java Servlet with a more efficient, ...
Overview of DriverStudio Tools
Liu Yang撰写的文章《An Overview of Distance Metric Learning》是一篇经典的度量学习综述论文,它对度量学习领域内的问题进行了分类,并详细总结了每类问题下现有的工作及其本质联系、优势和不足。 文章首先介绍...