protocol buffer 常用API
来源:互联网 发布:男士衣服搭配 知乎 编辑:程序博客网 时间:2024/05/29 11:28
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();
- }
阅读全文
0 0
- protocol buffer 常用API
- Google Protocol buffer 系列二: 常用api
- Google Protocol Buffer(2)—API
- protocol buffer
- protocol buffer
- Protocol Buffer
- protocol Buffer
- protocol buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- Protocol Buffer
- 汉字与 Unicode 转换 //转换 function Str_Gb2UniCode(text: string): String; var i,len: Integer; cur: Integer;
- mysql集群 之 [ERROR] InnoDB: Unable to lock ./ibdata1, error: 11
- linux下java环境的搭建
- Jquery单引号和双引号的使用注意
- eclipse的异常断点和条件断点设置方式
- protocol buffer 常用API
- system类
- 从零开始学习音视频编程技术(30) Linux篇之系统安装
- 获取某段时间内的小时、日期、月份,存储过程中使用的较多。
- 图像分割—基于图像数据的自动选择阈值(基本全局阈值处理方法)
- #spring注入为空null,普通类中引用springIOC类
- Navicat 导入数据报错 --- 1153
- 安装Ubuntu 出现 SQUASFS error / sd 8:0:0:0 :[sdb] assuming drive cache:write through
- JNI笔记 JNI引用,异常处理,初始化成员变量