Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
Created July 16, 2011 04:48
Show Gist options
  • Save laclefyoshi/1086013 to your computer and use it in GitHub Desktop.
Save laclefyoshi/1086013 to your computer and use it in GitHub Desktop.
cpp code for Protocol Buffers
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2011/07/16
**/
#include <iostream>
#include <fstream>
#include <string>
#include "person.pb.h"
using namespace std;
int main(int argc, char* argv[]) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
Person p;
fstream input("PersonBook", ios::in | ios::binary);
if (!p.ParseFromIstream(&input)) {
cerr << "Failed to parse address book." << endl;
return -1;
}
cout << "Person ID: " << p.id() << endl;
cout << "\tName: " << p.name() << endl;
cout << "\tEmail: " << p.email() << endl;
google::protobuf::ShutdownProtobufLibrary();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment