Protobuf在C/C++中的应用
来源:互联网 发布:energy star软件 编辑:程序博客网 时间:2024/04/30 07:43
2014-08-11 wcdj
https://github.com/gerryyang/mac-utils/tree/master/tools/protobuf/examples
官网:https://code.google.com/p/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.
0 0
- Protobuf在C/C++中的应用
- Protobuf-c在项目中的应用
- protobuf-c应用样例
- Protobuf在Unity中的应用
- SQlite在c#中的应用
- protobuf-c
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- protobuf在网络编程中的应用思考
- [protobuf] 在网络编程中的应用思考
- POJ 3667 Hotel. (线段树 区间合并)
- java的字符串
- 适当放松放松的非
- easyui datagrid 键盘上下控制选中行示例
- [poj3356]字符串dp
- Protobuf在C/C++中的应用
- 传说中的数据结构
- 并查集(初始化为-1)
- 黑马程序员_注解
- OC属性总结
- 【POJ 3128】Leonardo's Notebook
- VIM配置大全
- 哈哈,第一个Java的大数HDU1002
- 空间花开缓缓打开放松放松