google protobuf 源码

时间:2013-11-17 11:34:29
【文件属性】:

文件名称:google protobuf 源码

文件大小:2.21MB

文件格式:ZIP

更新时间:2013-11-17 11:34:29

code google protobuf

Protocol Buffers What is it? Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. Latest Updates http://protobuf.googlecode.com/svn/trunk/CHANGES.txt Documentation Read the documentation. Discussion Visit the discussion group. Quick Example You write a .proto file like this: message Person { required int32 id = 1; required string name = 2; optional string email = 3; } Then you compile it with protoc, the protocol buffer compiler, to produce code in C++, Java, or Python. Then, if you are using C++, you use that code like this: Person person; person.set_id(123); person.set_name("Bob"); person.set_email("bob@example.com"); fstream out("person.pb", ios::out | ios::binary | ios::trunc); person.SerializeToOstream(&out); out.close(); Or like this: Person person; fstream in("person.pb", ios::in | ios::binary); if (!person.ParseFromIstream(&in)) { cerr << "Failed to parse person.pb." << endl; exit(1); } cout << "ID: " << person.id() << endl; cout << "name: " << person.name() << endl; if (person.has_email()) { cout << "e-mail: " << person.email() << endl; } For a more complete example, see the tutorials. v2.3.0 http://code.google.com/p/protobuf/ sample command: protoc.exe -I=.\ --cpp_out=.\ unittest.proto


网友评论

  • 非常好,谢谢分享。
  • 很好的开源代码
  • 表示找不到ProtoBuf.Meta.TypeModel
  • 很好的开源代码
  • 可以使用,附上编译 Windows:http://blog.csdn.net/kandyer/article/details/10042715 Linux:http://wuquan-1230.blog.163.com/blog/static/298111532013615112359407/ windows编译用的是vs2008
  • 谢谢分享 ,可以使用
  • 可以,我刚用上