Protocol Buffers是谷歌提供的一种用来序列化结构体数据的机制,相似于XML。官网上这么定义:html
Protocol buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.git
在proto中定义message以后,编译器会给每一个field生成一个class。每一个class生成一些方法,以foo为例:github
message Person { required string name = 1; required int32 id = 2; optional string foo = 3; }
则其中的foo会自动生成一些系列的方法,ui
bool has_foo() const: 返回field是否被设置 int32 foo() const: 返回当前值 void set_foo(int32 value): 设置field的值 void clear_foo(): 清除field的值 string* mutable_foo():返回string field的指针
##参考google
https://github.com/google/protobuf指针
http://www.searchtb.com/2012/09/protocol-buffers.htmlcode
https://developers.google.com/protocol-buffers/?hl=zh-cnorm
https://developers.google.com/protocol-buffers/docs/reference/cpp-generated?hl=zh-cnhtm