Advertisement
mnguyen

protobuf crash

Aug 29th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1.  
  2. int ScoreWrite(string output_pbuf, OverallScores overall, MetaInfo minfo)
  3. {
  4.     DLOG("SCOR: start ScoreWrite()");
  5.   hlcam::communication::scores::ScoreBook score_book;
  6.  
  7.   /*{ fstream input(output_pbuf.c_str(), ios::in | ios::binary);
  8.     if(!input)
  9.     { cout << " File not found, creating new one." << endl;  
  10.     }
  11.     else if(!score_book.ParseFromIstream(&input))
  12.     { cerr << "Failed to parse score book." << endl;
  13.       return -1;
  14.     }
  15.   }*/
  16.     DLOG("pushing data into protobuf");
  17.     GetDataToPbuf(&score_book, overall, minfo);
  18.  
  19.  
  20.     fstream output(output_pbuf.c_str(), ios::out | ios::trunc | ios::binary);
  21.     if(!output)
  22.     {
  23.         DLOG("SCOR: Failed to open output file: %s.", output_pbuf.c_str());
  24.         cerr << "SCOR: Failed to open output file: "<<output_pbuf.c_str() <<" ."<<endl;
  25.       return -1;
  26.     }
  27.  
  28.     DLOG("File opened for writing");
  29.     if(!score_book.SerializeToOstream(&output))
  30.     {
  31.         DLOG("Failed to serialize data to stream");
  32.      cerr << "Failed to write score book." << endl;
  33.       return -1;
  34.     }
  35.         DLOG("shutting down protobuf");
  36.  
  37.     google::protobuf::ShutdownProtobufLibrary();
  38.         DLOG("shutdown of protobuf successul");
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement