OctreeDataUtils - use new json from DS also; allow upload of large domains

This commit is contained in:
Simon Walton 2018-11-12 15:43:09 -08:00
parent 8c347fae70
commit 6ee837d47c
3 changed files with 25 additions and 54 deletions

View file

@ -3411,20 +3411,11 @@ void DomainServer::maybeHandleReplacementEntityFile() {
}
void DomainServer::handleOctreeFileReplacement(QByteArray octreeFile) {
//Assume we have compressed data
auto compressedOctree = octreeFile;
QByteArray jsonOctree;
bool wasCompressed = gunzip(compressedOctree, jsonOctree);
if (!wasCompressed) {
// the source was not compressed, assume we were sent regular JSON data
jsonOctree = compressedOctree;
}
OctreeUtils::RawEntityData data;
if (data.readOctreeDataInfoFromData(jsonOctree)) {
if (data.readOctreeDataInfoFromData(octreeFile)) {
data.resetIdAndVersion();
QByteArray compressedOctree;
gzip(data.toByteArray(), compressedOctree);
// write the compressed octree data to a special file

View file

@ -47,16 +47,6 @@ namespace {
} // Anon namespace.
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromJSON(QJsonObject root) {
if (root.contains("Id") && root.contains("DataVersion") && root.contains("Version")) {
id = root["Id"].toVariant().toUuid();
dataVersion = root["DataVersion"].toInt();
version = root["Version"].toInt();
}
readSubclassData(root);
return true;
}
bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromMap(const QVariantMap& map) {
if (map.contains("Id") && map.contains("DataVersion") && map.contains("Version")) {
id = map["Id"].toUuid();
@ -94,28 +84,25 @@ bool OctreeUtils::RawOctreeData::readOctreeDataInfoFromFile(QString path) {
}
QByteArray data = file.readAll();
QByteArray jsonData;
if (!gunzip(data, jsonData)) {
jsonData = data;
}
return readOctreeDataInfoFromData(jsonData);
return readOctreeDataInfoFromData(data);
}
QByteArray OctreeUtils::RawOctreeData::toByteArray() {
QJsonObject obj {
{ "DataVersion", QJsonValue((qint64)dataVersion) },
{ "Id", QJsonValue(id.toString()) },
{ "Version", QJsonValue((qint64)version) },
};
QByteArray jsonString;
writeSubclassData(obj);
jsonString += QString(R"({
"DataVersion": %1,
)").arg(dataVersion);
QJsonDocument doc;
doc.setObject(obj);
writeSubclassData(jsonString);
return doc.toJson();
jsonString += QString(R"(,
"Id": "%1",
"Version": %2
})").arg(id.toString()).arg(version);
return jsonString;
}
QByteArray OctreeUtils::RawOctreeData::toGzippedByteArray() {
@ -142,24 +129,21 @@ void OctreeUtils::RawOctreeData::resetIdAndVersion() {
qDebug() << "Reset octree data to: " << id << dataVersion;
}
void OctreeUtils::RawEntityData::readSubclassData(const QJsonObject& root) {
if (root.contains("Entities")) {
entityData = root["Entities"].toArray();
}
}
void OctreeUtils::RawEntityData::readSubclassData(const QVariantMap& root) {
variantEntityData = root["Entities"].toList();
}
void OctreeUtils::RawEntityData::writeSubclassData(QJsonObject& root) const {
//root["Entities"] = entityData;
QJsonArray entitiesJsonArray;
void OctreeUtils::RawEntityData::writeSubclassData(QByteArray& root) const {
root += " \"Entities\": [";
for (auto entityIter = variantEntityData.begin(); entityIter != variantEntityData.end(); ++entityIter) {
entitiesJsonArray += entityIter->toJsonObject();
if (entityIter != variantEntityData.begin()) {
root += ",";
}
root += "\n ";
// Convert to string and remove trailing LF.
root += QJsonDocument(entityIter->toJsonObject()).toJson().chopped(1);
}
root["Entities"] = entitiesJsonArray;
root += "]";
}
PacketType OctreeUtils::RawEntityData::dataPacketType() const { return PacketType::EntityData; }

View file

@ -33,9 +33,8 @@ public:
virtual PacketType dataPacketType() const;
virtual void readSubclassData(const QJsonObject& root) { }
virtual void readSubclassData(const QVariantMap& root) { }
virtual void writeSubclassData(QJsonObject& root) const { }
virtual void writeSubclassData(QByteArray& root) const { }
void resetIdAndVersion();
QByteArray toByteArray();
@ -43,18 +42,15 @@ public:
bool readOctreeDataInfoFromData(QByteArray data);
bool readOctreeDataInfoFromFile(QString path);
bool readOctreeDataInfoFromJSON(QJsonObject root);
bool readOctreeDataInfoFromMap(const QVariantMap& map);
};
class RawEntityData : public RawOctreeData {
public:
PacketType dataPacketType() const override;
void readSubclassData(const QJsonObject& root) override;
void readSubclassData(const QVariantMap& root) override;
void writeSubclassData(QJsonObject& root) const override;
void writeSubclassData(QByteArray& root) const override;
QJsonArray entityData;
QVariantList variantEntityData;
};