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