summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/corelib/serialization/convert/jsonconverter.cpp60
-rw-r--r--examples/corelib/serialization/convert/jsonconverter.h13
-rw-r--r--examples/corelib/serialization/savegame/doc/src/savegame.qdoc8
-rw-r--r--examples/corelib/serialization/savegame/game.cpp11
-rw-r--r--src/corelib/serialization/qjsondocument.cpp7
-rw-r--r--src/corelib/serialization/qjsondocument.h10
-rw-r--r--src/gui/rhi/qshaderdescription.cpp10
7 files changed, 31 insertions, 88 deletions
diff --git a/examples/corelib/serialization/convert/jsonconverter.cpp b/examples/corelib/serialization/convert/jsonconverter.cpp
index 80d1cc6827..ec24af703d 100644
--- a/examples/corelib/serialization/convert/jsonconverter.cpp
+++ b/examples/corelib/serialization/convert/jsonconverter.cpp
@@ -57,7 +57,6 @@
#include <QJsonValue>
static JsonConverter jsonConverter;
-static BinaryJsonConverter BinaryJsonConverter;
static const char optionHelp[] =
"compact=no|yes Use compact JSON form.\n";
@@ -151,62 +150,3 @@ void JsonConverter::saveFile(QIODevice *f, const QVariant &contents, const QStri
f->write(convertFromVariant(contents).toJson(format));
}
-
-QString BinaryJsonConverter::name()
-{
- return "binary-json";
-}
-
-Converter::Direction BinaryJsonConverter::directions()
-{
- return InOut;
-}
-
-Converter::Options BinaryJsonConverter::outputOptions()
-{
- return {};
-}
-
-const char *BinaryJsonConverter::optionsHelp()
-{
- return nullptr;
-}
-
-bool BinaryJsonConverter::probeFile(QIODevice *f)
-{
- return f->isReadable() && f->peek(4) == "qbjs";
-}
-
-QVariant BinaryJsonConverter::loadFile(QIODevice *f, Converter *&outputConverter)
-{
- if (!outputConverter)
- outputConverter = &jsonConverter;
-
- QJsonDocument doc;
- if (auto file = qobject_cast<QFile *>(f)) {
- uchar *ptr = file->map(0, file->size());
- if (ptr)
- doc = QJsonDocument::fromRawData(reinterpret_cast<char *>(ptr), file->size());
- }
-
- if (doc.isNull())
- doc = QJsonDocument::fromBinaryData(f->readAll());
-
- if (!doc.isObject() && !doc.isArray()) {
- fprintf(stderr, "Failed to load Binary JSON.\n");
- exit(EXIT_FAILURE);
- }
- if (outputConverter == null)
- return QVariant();
- return doc.toVariant();
-}
-
-void BinaryJsonConverter::saveFile(QIODevice *f, const QVariant &contents, const QStringList &options)
-{
- if (!options.isEmpty()) {
- fprintf(stderr, "Unknown option '%s' to JSON output. This format has no options.\n", qPrintable(options.first()));
- exit(EXIT_FAILURE);
- }
-
- f->write(convertFromVariant(contents).toBinaryData());
-}
diff --git a/examples/corelib/serialization/convert/jsonconverter.h b/examples/corelib/serialization/convert/jsonconverter.h
index 17170603c7..445a0e6695 100644
--- a/examples/corelib/serialization/convert/jsonconverter.h
+++ b/examples/corelib/serialization/convert/jsonconverter.h
@@ -69,17 +69,4 @@ public:
void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
};
-class BinaryJsonConverter : public Converter
-{
- // Converter interface
-public:
- QString name() override;
- Direction directions() override;
- Options outputOptions() override;
- const char *optionsHelp() override;
- bool probeFile(QIODevice *f) override;
- QVariant loadFile(QIODevice *f, Converter *&outputConverter) override;
- void saveFile(QIODevice *f, const QVariant &contents, const QStringList &options) override;
-};
-
#endif // JSONCONVERTER_H
diff --git a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
index a35f763430..e20cb6bc6c 100644
--- a/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
+++ b/examples/corelib/serialization/savegame/doc/src/savegame.qdoc
@@ -37,8 +37,8 @@
game generally involves serializing each game object's member variables
to a file. Many formats can be used for this purpose, one of which is JSON.
With QJsonDocument, you also have the ability to serialize a document in a
- binary format, which is great if you don't want the save file to be
- readable, or if you need to keep the file size down.
+ \l {https://tools.ietf.org/html/rfc7049} {CBOR} format, which is great if you
+ don't want the save file to be readable, or if you need to keep the file size down.
In this example, we'll demonstrate how to save and load a simple game to
and from JSON and binary formats.
@@ -133,7 +133,7 @@
When loading a saved game in loadGame(), the first thing we do is open the
save file based on which format it was saved to; \c "save.json" for JSON,
- and \c "save.dat" for binary. We print a warning and return \c false if the
+ and \c "save.dat" for CBOR. We print a warning and return \c false if the
file couldn't be opened.
Since QJsonDocument's \l{QJsonDocument::fromJson()}{fromJson()} and
@@ -172,7 +172,7 @@
\snippet serialization/savegame/main.cpp 1
When the player has finished, we save their game. For demonstration
- purposes, we can serialize to either JSON or binary. You can examine the
+ purposes, we can serialize to either JSON or CBOR. You can examine the
contents of the files in the same directory as the executable (or re-run
the example, making sure to also specify the "load" option), although the
binary save file will contain some garbage characters (which is normal).
diff --git a/examples/corelib/serialization/savegame/game.cpp b/examples/corelib/serialization/savegame/game.cpp
index c39362bc68..58fc087b1f 100644
--- a/examples/corelib/serialization/savegame/game.cpp
+++ b/examples/corelib/serialization/savegame/game.cpp
@@ -50,6 +50,8 @@
#include "game.h"
+#include <QCborMap>
+#include <QCborValue>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
@@ -122,14 +124,14 @@ bool Game::loadGame(Game::SaveFormat saveFormat)
QJsonDocument loadDoc(saveFormat == Json
? QJsonDocument::fromJson(saveData)
- : QJsonDocument::fromBinaryData(saveData));
+ : QJsonDocument(QCborValue::fromCbor(saveData).toMap().toJsonObject()));
read(loadDoc.object());
QTextStream(stdout) << "Loaded save for "
<< loadDoc["player"]["name"].toString()
<< " using "
- << (saveFormat != Json ? "binary " : "") << "JSON...\n";
+ << (saveFormat != Json ? "CBOR" : "JSON") << "...\n";
return true;
}
//! [3]
@@ -148,10 +150,9 @@ bool Game::saveGame(Game::SaveFormat saveFormat) const
QJsonObject gameObject;
write(gameObject);
- QJsonDocument saveDoc(gameObject);
saveFile.write(saveFormat == Json
- ? saveDoc.toJson()
- : saveDoc.toBinaryData());
+ ? QJsonDocument(gameObject).toJson()
+ : QCborValue::fromJsonValue(gameObject).toCbor());
return true;
}
diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp
index b9b1902f34..fe0500bdef 100644
--- a/src/corelib/serialization/qjsondocument.cpp
+++ b/src/corelib/serialization/qjsondocument.cpp
@@ -237,7 +237,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other)
the application.
*/
-#if QT_CONFIG(binaryjson)
+#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
/*!
Creates a QJsonDocument that uses the first \a size bytes from
\a data. It assumes \a data contains a binary encoded JSON document.
@@ -385,10 +385,13 @@ QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidati
QByteArray QJsonDocument::toBinaryData() const
{
int size = 0;
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
const char *raw = rawData(&size);
+QT_WARNING_POP
return QByteArray(raw, size);
}
-#endif // QT_CONFIG(binaryjson)
+#endif // QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
/*!
Creates a QJsonDocument from the QVariant \a variant.
diff --git a/src/corelib/serialization/qjsondocument.h b/src/corelib/serialization/qjsondocument.h
index 325e47b531..758bbfd9dd 100644
--- a/src/corelib/serialization/qjsondocument.h
+++ b/src/corelib/serialization/qjsondocument.h
@@ -111,13 +111,19 @@ public:
BypassValidation
};
-#if QT_CONFIG(binaryjson)
+#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
+ QT_DEPRECATED_X("Use CBOR format instead")
static QJsonDocument fromRawData(const char *data, int size, DataValidation validation = Validate);
+
+ QT_DEPRECATED_X("Use CBOR format instead")
const char *rawData(int *size) const;
+ QT_DEPRECATED_X("Use CBOR format instead")
static QJsonDocument fromBinaryData(const QByteArray &data, DataValidation validation = Validate);
+
+ QT_DEPRECATED_X("Use CBOR format instead")
QByteArray toBinaryData() const;
-#endif // QT_CONFIG(binaryjson)
+#endif // QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
static QJsonDocument fromVariant(const QVariant &variant);
QVariant toVariant() const;
diff --git a/src/gui/rhi/qshaderdescription.cpp b/src/gui/rhi/qshaderdescription.cpp
index d0f73f6aa7..7e9b7d7b8e 100644
--- a/src/gui/rhi/qshaderdescription.cpp
+++ b/src/gui/rhi/qshaderdescription.cpp
@@ -342,8 +342,11 @@ bool QShaderDescription::isValid() const
*/
QByteArray QShaderDescription::toBinaryJson() const
{
-#if QT_CONFIG(binaryjson)
+#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
return d->makeDoc().toBinaryData();
+QT_WARNING_POP
#else
qWarning("Cannot generate binary JSON from QShaderDescription due to disabled binaryjson feature");
return QByteArray();
@@ -382,8 +385,11 @@ QByteArray QShaderDescription::toJson() const
QShaderDescription QShaderDescription::fromBinaryJson(const QByteArray &data)
{
QShaderDescription desc;
-#if QT_CONFIG(binaryjson)
+#if QT_CONFIG(binaryjson) && QT_DEPRECATED_SINCE(5, 15)
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_DEPRECATED
QShaderDescriptionPrivate::get(&desc)->loadDoc(QJsonDocument::fromBinaryData(data));
+QT_WARNING_POP
#else
Q_UNUSED(data);
qWarning("Cannot load QShaderDescription from binary JSON due to disabled binaryjson feature");