Here is an introduction to paste http://blog.csdn.net/hailong0715/article/details/52016682
Here on how to install the installation of the Caffe installed together, here to introduce how to use this library, Caffe use him as a data transmission means he soon
A new proto defines the structure of the data transfer, which is similar to the data transmission on ROS.
Syntax = "Proto2";
Package Caffe; Domain Name message person
{
Required String name = 1;
Required Int32 age = 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];
}
Optional PhoneNumber phone = 4;
}
Package refers to the domain name, which is Std.
Write.cpp
#include <iostream>
#include <fstream>
#include "caffe.pb.h"
using namespace std;
using namespace Caffe;
int main () {person by person
;
Person.set_name ("Flamingo");
Person.set_age ();
Person.set_email ("majianfei1023@gmail.com");
Person.mutable_phone ()->set_number ("135525");
Write
fstream output ("./log", Ios::out | ios::trunc | ios::binary);
if (!person. Serializetoostream (&output)) {
cerr << "Failed to write Msg." << Endl;
return-1;
}
System ("pause");
return 0;
}
In fact, I was looking at the functions defined in the caffe.pb.h he produced, and found that these functions can be used directly
Read.cpp
#include <iostream>
#include <fstream>
#include "caffe.pb.h"
using namespace std;
using namespace Caffe;
void Printinfo (const person & person) {
cout << person.name () << Endl;
cout << person.age () << Endl;
cout << person.email () << Endl;
cout << Person.phone (). Number () << Endl;
cout << Person.phone (). Type () << Endl;
int main () {person by person
;
FStream input ("./log", Ios::in | ios::binary);
if (!person. Parsefromistream (&input)) {
cerr << "Failed to parse Address Book." << Endl;
return-1;
}
Printinfo (person);
return 0;
}
Then compile and join the library.
Protoc--cpp_out=./Caffe.proto #在当前目录生成. h and. CC
g++ write.cpp caffe.pb.cc-o write-lprotobuf
g++ Read.cpp Caffe.pb.cc-o Read-lprotobuf
This digest from: http://blog.csdn.net/cai13160674275/article/details/71214552