std::vector<Register*> SPSegment::toRegisterVector(const char* data) { Schema::Relation relation = this->relation(); unsigned nextVarLength = 0; unsigned offset = 0; vector<Register*> result = vector<Register*>(); for (auto attr = relation.attributes.begin(); attr != relation.attributes.end(); attr++) { switch ((*attr).type) { case Types::Tag::Integer: nextVarLength += sizeof(int); break; case Types::Tag::Char: nextVarLength += sizeof(unsigned); break; } } for (auto attr = relation.attributes.begin(); attr != relation.attributes.end(); attr++) { Register* reg = new Register(); switch ((*attr).type) { case Types::Tag::Integer: reg->setInteger(*(reinterpret_cast<const int*>(data + offset))); offset += sizeof(int); break; case Types::Tag::Char: const char* str = data + nextVarLength; const unsigned endOffset = *(reinterpret_cast<const unsigned*>(data + offset)); reg->setString(string(str, offset + endOffset - nextVarLength)); offset += sizeof(unsigned); break; } result.push_back(reg); } return result; }