Utils: Add PersistentCacheStore

Change-Id: I952e0271afcc0fd4b03ef75fa5acb219be153290
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-09-05 10:12:33 +02:00
parent 7adeaafd93
commit 1c5aa22257
8 changed files with 172 additions and 0 deletions

View File

@@ -6,6 +6,9 @@
#include "algorithm.h"
#include "qtcassert.h"
#include <QJsonDocument>
#include <QJsonParseError>
namespace Utils {
KeyList keysFromStrings(const QStringList &list)
@@ -111,4 +114,23 @@ Key numberedKey(const Key &key, int number)
return key + Key::number(number);
}
expected_str<Store> storeFromJson(const QByteArray &json)
{
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(json, &error);
if (error.error != QJsonParseError::NoError)
return make_unexpected(error.errorString());
if (!doc.isObject())
return make_unexpected(QString("Not a valid JSON object."));
return storeFromMap(doc.toVariant().toMap());
}
QByteArray jsonFromStore(const Store &store)
{
QJsonDocument doc = QJsonDocument::fromVariant(mapFromStore(store));
return doc.toJson();
}
} // Utils