// // ScriptMessage.h // libraries/script-engine/src/v8/FastScriptValueUtils.cpp // // Created by dr Karol Suprynowicz on 2023/09/24. // Copyright 2023 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // #include "ScriptMessage.h" #include QJsonObject ScriptMessage::toJson() { QJsonObject object; object["message"] = _messageContent; object["lineNumber"] = _lineNumber; object["fileName"] = _fileName; object["entityID"] = _entityID.toString(); object["type"] = static_cast(_scriptType); object["severity"] = static_cast(_severity); return object; } bool ScriptMessage::fromJson(const QJsonObject &object) { if (object.isEmpty()) { qDebug() << "ScriptMessage::fromJson object is empty"; return false; } if (!object["message"].isString() || !object["lineNumber"].isDouble() || !object["fileName"].isString() || !object["entityID"].isString() || !object["type"].isDouble() || !object["severity"].isDouble()) { qDebug() << "ScriptMessage::fromJson failed to find required fields in JSON file"; return false; } _messageContent = object["message"].toString(); _lineNumber = object["lineNumber"].toInt(); _fileName = object["fileName"].toInt(); _entityID = QUuid::fromString(object["entityID"].toString()); _scriptType = static_cast(object["type"].toInt()); _severity = static_cast(object["severity"].toInt()); return true; }