diff options
Diffstat (limited to 'src/corelib/serialization/qjsoncbor.cpp')
-rw-r--r-- | src/corelib/serialization/qjsoncbor.cpp | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index 3d79388b1d..da07eca8a7 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qcborvalue.h" #include "qcborvalue_p.h" @@ -48,6 +12,9 @@ #include "qjsondocument.h" #include "qjson_p.h" +#include <qmap.h> +#include <qhash.h> + #include <private/qnumeric_p.h> #include <quuid.h> @@ -98,7 +65,6 @@ static QString maybeEncodeTag(const QCborContainerPrivate *d) { qint64 tag = d->elements.at(0).value; const Element &e = d->elements.at(1); - const ByteData *b = d->byteData(e); switch (tag) { case qint64(QCborKnownTags::DateTimeString): @@ -115,8 +81,12 @@ static QString maybeEncodeTag(const QCborContainerPrivate *d) break; case qint64(QCborKnownTags::Uuid): - if (e.type == QCborValue::ByteArray && b->len == sizeof(QUuid)) +#ifndef QT_BOOTSTRAPPED + if (const ByteData *b = d->byteData(e); e.type == QCborValue::ByteArray && b + && b->len == sizeof(QUuid)) return QUuid::fromRfc4122(b->asByteArrayView()).toString(QUuid::WithoutBraces); +#endif + break; } // don't know what to do, bail out @@ -205,10 +175,14 @@ static QJsonValue convertExtendedTypeToJson(QCborContainerPrivate *d) switch (tag) { case qint64(QCborKnownTags::Url): - // use the fullly-encoded URL form +#ifdef QT_BOOTSTRAPPED + break; +#else + // use the fully-encoded URL form if (d->elements.at(1).type == QCborValue::String) return QUrl::fromEncoded(d->byteData(1)->asByteArrayView()).toString(QUrl::FullyEncoded); Q_FALLTHROUGH(); +#endif case qint64(QCborKnownTags::DateTimeString): case qint64(QCborKnownTags::ExpectedBase64url): @@ -424,10 +398,12 @@ QJsonValue QCborValue::toJsonValue() const return QJsonPrivate::Value::fromTrustedCbor(simpleTypeString(type())); } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED) QJsonValue QCborValueRef::toJsonValue() const { return qt_convertToJson(d, i); } +#endif /*! Recursively converts every \l QCborValue element in this array to JSON @@ -445,11 +421,13 @@ QJsonArray QCborArray::toJsonArray() const return convertToJsonArray(d.data()); } +#ifndef QT_NO_VARIANT QJsonArray QJsonPrivate::Variant::toJsonArray(const QVariantList &list) { const auto cborArray = QCborArray::fromVariantList(list); return convertToJsonArray(cborArray.d.data(), ConversionMode::FromVariantToJson); } +#endif // !QT_NO_VARIANT /*! Recursively converts every \l QCborValue value in this map to JSON using @@ -493,6 +471,7 @@ QJsonObject QCborMap::toJsonObject() const return convertToJsonObject(d.data()); } +#ifndef QT_NO_VARIANT QJsonObject QJsonPrivate::Variant::toJsonObject(const QVariantMap &map) { const auto cborMap = QCborMap::fromVariantMap(map); @@ -580,15 +559,15 @@ QVariant QCborValue::toVariant() const #ifndef QT_BOOTSTRAPPED case Url: return toUrl(); -#endif -#if QT_CONFIG(regularexpression) +# if QT_CONFIG(regularexpression) case RegularExpression: return toRegularExpression(); -#endif +# endif case Uuid: return toUuid(); +#endif case Invalid: return QVariant(); @@ -600,9 +579,9 @@ QVariant QCborValue::toVariant() const if (isSimpleType()) return QVariant::fromValue(toSimpleType()); - Q_UNREACHABLE(); - return QVariant(); + Q_UNREACHABLE_RETURN(QVariant()); } +#endif // !QT_NO_VARIANT /*! Converts the JSON value contained in \a v into its corresponding CBOR value @@ -656,6 +635,7 @@ QCborValue QCborValue::fromJsonValue(const QJsonValue &v) return QCborValue(); } +#ifndef QT_NO_VARIANT static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) { // Handle strings and byte arrays directly, to avoid creating a temporary @@ -757,9 +737,9 @@ QCborValue QCborValue::fromVariant(const QVariant &variant) #ifndef QT_BOOTSTRAPPED case QMetaType::QUrl: return QCborValue(variant.toUrl()); -#endif case QMetaType::QUuid: return QCborValue(variant.toUuid()); +#endif case QMetaType::QVariantList: return QCborArray::fromVariantList(variant.toList()); case QMetaType::QVariantMap: @@ -856,6 +836,7 @@ QCborArray QCborArray::fromVariantList(const QVariantList &list) appendVariant(a.d.data(), v); return a; } +#endif // !QT_NO_VARIANT /*! Converts all JSON items found in the \a array array to CBOR using @@ -887,6 +868,7 @@ QCborArray QCborArray::fromJsonArray(QJsonArray &&array) noexcept } +#ifndef QT_NO_VARIANT /*! Converts the CBOR values to QVariant using QCborValue::toVariant() and "stringifies" all the CBOR keys in this map, returning the QVariantMap that @@ -983,6 +965,7 @@ QCborMap QCborMap::fromVariantHash(const QVariantHash &hash) } return m; } +#endif // !QT_NO_VARIANT /*! Converts all JSON items found in the \a obj object to CBOR using |