Advertisement
theultraman20

Untitled

Oct 9th, 2024
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. std::vector<uint8_t> deserializePdb(std::string filename) {
  2.     std::ifstream is(filename, std::ios::binary);
  3.     if (!is.good()) { throw std::runtime_error("Cannot open file for reading"); }
  4.  
  5.     uint32_t size;
  6.     is.read(reinterpret_cast<char*>(&size), sizeof(size));
  7.     if (!is.good()) { throw std::runtime_error("Error reading size"); }
  8.  
  9.     std::cout << size << std::endl;
  10.  
  11.     std::vector<uint8_t> bytes(size);
  12.     is.read(reinterpret_cast<char*>(bytes.data()), size);
  13.     if (!is.good()) { throw std::runtime_error("Error reading bytes"); }
  14.  
  15.     return bytes;
  16. }
  17.  
  18. void serializePdb(std::vector<uint8_t> const& data, std::string filename) {
  19.     std::ofstream os(filename, std::ios::binary);
  20.     if (!os.good()) { throw std::runtime_error("Cannot open file for writing"); }
  21.  
  22.     uint32_t size = data.size();
  23.     os.write(reinterpret_cast<const char*>(&size), sizeof(size));
  24.     if (!os.good()) { throw std::runtime_error("Error writing size"); }
  25.  
  26.     os.write(reinterpret_cast<const char*>(data.data()), size);
  27.     if (!os.good()) { throw std::runtime_error("Error writing bytes"); }
  28.  
  29.     os.close();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement