ProtoBuf 常用序列化/反序列化API
来源:互联网 发布:计算睡眠网络断开 编辑:程序博客网 时间:2024/06/05 07:41
各位亲 有时间可以去看看我的 “金骏家居淘宝店” http://jinjun1688.taobao.com/shop/view_shop.htm?tracelog=twddp 买时说明在我的博客看到有优惠哦 还有意外礼品赠送 真正的程序员淘宝店
1、C数组的序列化和反序列化API
- //C数组的序列化和序列化API
- bool ParseFromArray(const void* data, int size);
- bool SerializeToArray(void* data, int size) const;
- //使用
- void set_people()
- {
- wp.set_name("sealyao");
- wp.set_id(123456);
- wp.set_email("sealyaog@gmail.com");
- wp.SerializeToArray(parray,256);
- }
- void get_people()
- {
- rap.ParseFromArray(parray,256);
- cout << "Get People from Array:" << endl;
- cout << "\t Name : " <<rap.name() << endl;
- cout << "\t Id : " << rap.id() << endl;
- cout << "\t email : " << rap.email() << endl;
- }
2、C++ String的序列化和反序列化API
- //C++string序列化和序列化API
- bool SerializeToString(string* output) const;
- bool ParseFromString(const string& data);
- //使用:
- void set_people()
- {
- wp.set_name("sealyao");
- wp.set_id(123456);
- wp.set_email("sealyaog@gmail.com");
- wp.SerializeToString(&pstring);
- }
- void get_people()
- {
- rsp.ParseFromString(pstring);
- cout << "Get People from String:" << endl;
- cout << "\t Name : " <<rsp.name() << endl;
- cout << "\t Id : " << rsp.id() << endl;
- cout << "\t email : " << rsp.email() << endl;
- }
3、文件描述符序列化和反序列化API
- //文件描述符的序列化和序列化API
- bool SerializeToFileDescriptor(int file_descriptor) const;
- bool ParseFromFileDescriptor(int file_descriptor);
- //使用:
- void set_people()
- {
- fd = open(path,O_CREAT|O_TRUNC|O_RDWR,0644);
- if(fd <= 0){
- perror("open");
- exit(0);
- }
- wp.set_name("sealyaog");
- wp.set_id(123456);
- wp.set_email("sealyaog@gmail.com");
- wp.SerializeToFileDescriptor(fd);
- close(fd);
- }
- void get_people()
- {
- fd = open(path,O_RDONLY);
- if(fd <= 0){
- perror("open");
- exit(0);
- }
- rp.ParseFromFileDescriptor(fd);
- std::cout << "Get People from FD:" << endl;
- std::cout << "\t Name : " <<rp.name() << endl;
- std::cout << "\t Id : " << rp.id() << endl;
- std::cout << "\t email : " << rp.email() << endl;
- close(fd);
- }
4、C++ stream 序列化和反序列化API
- //C++ stream 序列化/反序列化API
- bool SerializeToOstream(ostream* output) const;
- bool ParseFromIstream(istream* input);
- //使用:
- void set_people()
- {
- fstream fs(path,ios::out|ios::trunc|ios::binary);
- wp.set_name("sealyaog");
- wp.set_id(123456);
- wp.set_email("sealyaog@gmail.com");
- wp.SerializeToOstream(&fs);
- fs.close();
- fs.clear();
- }
- void get_people()
- {
- fstream fs(path,ios::in|ios::binary);
- rp.ParseFromIstream(&fs);
- std::cout << "\t Name : " <<rp.name() << endl;
- std::cout << "\t Id : " << rp.id() << endl;
- std::cout << "\t email : " << rp.email() << endl;
- fs.close();
- fs.clear();
- }
- ProtoBuf 常用序列化/反序列化API
- ProtoBuf 常用序列化/反序列化API
- ProtoBuf 常用序列化/反序列化API
- ProtoBuf 常用序列化/反序列化API
- protobuf 常用序列化/反序列化 api
- ProtoBuf 常用序列化/反序列化API
- ProtoBuf 常用序列化/反序列化API
- ProtoBuf 常用序列化/反序列化API
- protobuf入门教程(三):常用序列化/反序列化接口
- protobuf入门教程(三):常用序列化/反序列化接口
- protobuf 序列化 反序列接口
- java中使用protobuf序列化(反序列化)
- java中使用protobuf序列化(反序列化)
- protobuf 的序列化与反序列化
- google protobuf入门(序列化和反序列化)
- Lua 中实现 protobuf 序列化,反序列化
- protobuf的序列化与反序列化
- 使用protoBuf进行序列化和反序列化
- 安装CentOS的建议
- android binder机制之--(我是Server Porxy)
- TableView详细解释
- 查看字符串在不同编码(ASCII、Unicode、UTF7、UTF8、Default、BigEndianUnicode)下的 Hex
- SAP客户合作伙伴关系使用说明
- ProtoBuf 常用序列化/反序列化API
- poj3892 高精度
- Ready购商城-网上购物新选择
- 异常分析:There is no Action mapped for action name null. - [unknown location]
- android binder机制之——(我是binder实例)
- Piotr's ants UVA 10881
- php 操作数组 (合并,拆分,追加,查找,删除等)
- System.Threading.ThreadAbortException: 正在中止线程
- http请求状态码(code)