http://blog.csdn.net/sealyao/article/details/69402451、C數(shù)組的序列化和反序列化API
成都創(chuàng)新互聯(lián)長(zhǎng)期為超過(guò)千家客戶(hù)提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為淅川企業(yè)提供專(zhuān)業(yè)的
成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作,
淅川網(wǎng)站改版等技術(shù)服務(wù)。擁有十年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。
[cpp] view plaincopy
- //C數(shù)組的序列化和序列化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 << " Name : " <<rap.name() << endl;
- cout << " Id : " << rap.id() << endl;
- cout << " email : " << rap.email() << endl;
- }
2、C++ String的序列化和反序列化API
[cpp] view plaincopy
- //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 << " Name : " <<rsp.name() << endl;
- cout << " Id : " << rsp.id() << endl;
- cout << " email : " << rsp.email() << endl;
- }
3、文件描述符序列化和反序列化API
[cpp] view plaincopy
- //文件描述符的序列化和序列化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 << " Name : " <<rp.name() << endl;
- std::cout << " Id : " << rp.id() << endl;
- std::cout << " email : " << rp.email() << endl;
- close(fd);
- }
4、C++ stream 序列化和反序列化API
[cpp] view plaincopy
- //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 << " Name : " <<rp.name() << endl;
- std::cout << " Id : " << rp.id() << endl;
- std::cout << " email : " << rp.email() << endl;
- fs.close();
- fs.clear();
- }
網(wǎng)站題目:ProtoBuf常用序列化/反序列化API轉(zhuǎn)-創(chuàng)新互聯(lián)
URL地址:http://www.rwnh.cn/article48/dcddep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供域名注冊(cè)、軟件開(kāi)發(fā)、網(wǎng)站收錄、服務(wù)器托管、網(wǎng)站導(dǎo)航、ChatGPT
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源:
創(chuàng)新互聯(lián)