int LeafNode::deserialize(const char* buffer) { level = LEVEL_MASK & buffer[0]; numElements = buffer[1]; elements.resize(numElements); int bytes = 2; for (unsigned i = 0; i < numElements; ++i) { Record* aux = new Record(); bytes += aux->deserialize(buffer + bytes); elements[i] = aux; } occupiedSpace = bytes; return bytes; }
bool TimeLogger::deserialize(string file_name, Record& record) { fstream logfile; logfile.open(file_name.c_str(), ios_base::binary | ios_base::in); if (!logfile.is_open()) { cerr << "Could not open and deserialize file '" << file_name << "'!" << endl; return false; } logfile.seekp(0, ios_base::end); size_t file_size = logfile.tellp(); logfile.seekp(0, ios_base::beg); if (!file_size) { cerr << "Cuold not deserialize empty file!" << endl; return false; } // Header unsigned int magic_sig; logfile.read((char*)&magic_sig, sizeof(MAGIC_SIG)); if (magic_sig != MAGIC_SIG) { cerr << "This file is not in the TimeLogger format!" << endl; return false; } unsigned int version; logfile.read((char*)&version, sizeof(VERSION)); if (version != VERSION) { cerr << "Version missmatch!" << endl; return false; } record.deserialize(logfile); return true; }