https://developers.google.com/protocol-buffers/docs/overview
Protobuf是一种可以实现内存与外存交换的协议接口。可以理解为一种通信协议.caffe就是使用了这种协议.
protobuf使用前,先编写proto文件,这是描述我们需要配置参数的数据结构。例如:
// See README.txt for information and build instructions.
package tutorial;
option java_package = "com.example.tutorial";
option java_outer_classname = "AddressBookProtos";
message Person {
required string name = 1;
required int32 id = 2; // Unique ID number for this person.
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;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person person = 1;
}
然后用protobuf工具生成接口代码:
protoc –cpp_out=. addressbook.proto
运行后生成了两个文件:addressbook.pb.cc 和addressbook.pb.h
包含了操作参数,序列化,反序列化的接口函数.(add_person(), add_phone(), set_number(), set_email(),SerializeToOstream(),ParseFromIstream()等)