Provide a feature for CBOR stream I/O

We need to turn it off in bootstrap code.

Change-Id: I826e49fbc5f6128e56f84b58d29358dd7b0b9dc5
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
Ulf Hermann 2019-10-14 15:12:02 +02:00
parent 821c2eb131
commit 85ed676dff
6 changed files with 32 additions and 2 deletions

View File

@ -1086,6 +1086,14 @@ Mozilla License) is included. The data is then also used in QNetworkCookieJar::v
"win32_system_libs": { "win32_system_libs": {
"label": "Windows System Libraries", "label": "Windows System Libraries",
"condition": "config.win32 && libs.advapi32 && libs.gdi32 && libs.kernel32 && libs.netapi32 && libs.ole32 && libs.shell32 && libs.uuid && libs.user32 && libs.winmm && libs.ws2_32" "condition": "config.win32 && libs.advapi32 && libs.gdi32 && libs.kernel32 && libs.netapi32 && libs.ole32 && libs.shell32 && libs.uuid && libs.user32 && libs.winmm && libs.ws2_32"
},
"cborstream": {
"label": "CBOR stream I/O",
"purpose": "Provides support for reading and writing the CBOR binary format.
Note that this is required for plugin loading. Qt GUI needs QPA plugins for basic operation.",
"section": "Utilities",
"output": [ "publicFeature" ]
} }
}, },

View File

@ -74,6 +74,7 @@
#else #else
# define QT_FEATURE_alloca_malloc_h -1 # define QT_FEATURE_alloca_malloc_h -1
#endif #endif
#define QT_FEATURE_cborstream -1
#define QT_CRYPTOGRAPHICHASH_ONLY_SHA1 #define QT_CRYPTOGRAPHICHASH_ONLY_SHA1
#define QT_FEATURE_cxx11_random (QT_HAS_INCLUDE(<random>) ? 1 : -1) #define QT_FEATURE_cxx11_random (QT_HAS_INCLUDE(<random>) ? 1 : -1)
#define QT_NO_DATASTREAM #define QT_NO_DATASTREAM

View File

@ -47,6 +47,8 @@
#include <QtCore/qstring.h> #include <QtCore/qstring.h>
#include <QtCore/qstringview.h> #include <QtCore/qstringview.h>
QT_REQUIRE_CONFIG(cborstream);
// See qcborcommon.h for why we check // See qcborcommon.h for why we check
#if defined(QT_X11_DEFINES_FOUND) #if defined(QT_X11_DEFINES_FOUND)
# undef True # undef True

View File

@ -42,7 +42,10 @@
#include "qdatastream.h" #include "qdatastream.h"
#include "qcborarray.h" #include "qcborarray.h"
#include "qcbormap.h" #include "qcbormap.h"
#if QT_CONFIG(cborstream)
#include "qcborstream.h" #include "qcborstream.h"
#endif
#include <qendian.h> #include <qendian.h>
#include <qlocale.h> #include <qlocale.h>
@ -758,6 +761,7 @@ QT_BEGIN_NAMESPACE
using namespace QtCbor; using namespace QtCbor;
#if QT_CONFIG(cborstream)
// in qcborstream.cpp // in qcborstream.cpp
extern void qt_cbor_stream_set_error(QCborStreamReaderPrivate *d, QCborError error); extern void qt_cbor_stream_set_error(QCborStreamReaderPrivate *d, QCborError error);
@ -799,6 +803,7 @@ static void writeDoubleToCbor(QCborStreamWriter &writer, double d, QCborValue::E
writer.append(d); writer.append(d);
} }
#endif // QT_CONFIG(cborstream)
static inline int typeOrder(Element e1, Element e2) static inline int typeOrder(Element e1, Element e2)
{ {
@ -1221,6 +1226,7 @@ int QCborMap::compare(const QCborMap &other) const noexcept
return compareContainer(d.data(), other.d.data()); return compareContainer(d.data(), other.d.data());
} }
#if QT_CONFIG(cborstream)
static void encodeToCbor(QCborStreamWriter &writer, const QCborContainerPrivate *d, qsizetype idx, static void encodeToCbor(QCborStreamWriter &writer, const QCborContainerPrivate *d, qsizetype idx,
QCborValue::EncodingOptions opt) QCborValue::EncodingOptions opt)
{ {
@ -1632,6 +1638,7 @@ void QCborContainerPrivate::decodeFromCbor(QCborStreamReader &reader)
if (reader.lastError() == QCborError::NoError) if (reader.lastError() == QCborError::NoError)
reader.leaveContainer(); reader.leaveContainer();
} }
#endif // QT_CONFIG(cborstream)
/*! /*!
Creates a QCborValue with byte array value \a ba. The value can later be Creates a QCborValue with byte array value \a ba. The value can later be
@ -2330,6 +2337,7 @@ QCborValueRef QCborValue::operator[](qint64 key)
return { container, index }; return { container, index };
} }
#if QT_CONFIG(cborstream)
/*! /*!
Decodes one item from the CBOR stream found in \a reader and returns the Decodes one item from the CBOR stream found in \a reader and returns the
equivalent representation. This function is recursive: if the item is a map equivalent representation. This function is recursive: if the item is a map
@ -2567,6 +2575,7 @@ void QCborValueRef::toCbor(QCborStreamWriter &writer, QCborValue::EncodingOption
{ {
concrete().toCbor(writer, opt); concrete().toCbor(writer, opt);
} }
#endif // QT_CONFIG(cborstream)
void QCborValueRef::assign(QCborValueRef that, const QCborValue &other) void QCborValueRef::assign(QCborValueRef that, const QCborValue &other)
{ {

View File

@ -285,6 +285,7 @@ public:
static QCborValue fromJsonValue(const QJsonValue &v); static QCborValue fromJsonValue(const QJsonValue &v);
QJsonValue toJsonValue() const; QJsonValue toJsonValue() const;
#if QT_CONFIG(cborstream)
static QCborValue fromCbor(QCborStreamReader &reader); static QCborValue fromCbor(QCborStreamReader &reader);
static QCborValue fromCbor(const QByteArray &ba, QCborParserError *error = nullptr); static QCborValue fromCbor(const QByteArray &ba, QCborParserError *error = nullptr);
static QCborValue fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr) static QCborValue fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr)
@ -293,6 +294,7 @@ public:
{ return fromCbor(QByteArray(reinterpret_cast<const char *>(data), int(len)), error); } { return fromCbor(QByteArray(reinterpret_cast<const char *>(data), int(len)), error); }
QByteArray toCbor(EncodingOptions opt = NoTransformation); QByteArray toCbor(EncodingOptions opt = NoTransformation);
void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation); void toCbor(QCborStreamWriter &writer, EncodingOptions opt = NoTransformation);
#endif
QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const; QString toDiagnosticNotation(DiagnosticNotationOptions opts = Compact) const;
@ -435,9 +437,11 @@ public:
QVariant toVariant() const { return concrete().toVariant(); } QVariant toVariant() const { return concrete().toVariant(); }
QJsonValue toJsonValue() const; QJsonValue toJsonValue() const;
#if QT_CONFIG(cborstream)
QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation) QByteArray toCbor(QCborValue::EncodingOptions opt = QCborValue::NoTransformation)
{ return concrete().toCbor(opt); } { return concrete().toCbor(opt); }
void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation); void toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = QCborValue::NoTransformation);
#endif
QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact) QString toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opt = QCborValue::Compact)
{ return concrete().toDiagnosticNotation(opt); } { return concrete().toDiagnosticNotation(opt); }

View File

@ -6,7 +6,6 @@ HEADERS += \
serialization/qcbormap.h \ serialization/qcbormap.h \
serialization/qcborvalue.h \ serialization/qcborvalue.h \
serialization/qcborvalue_p.h \ serialization/qcborvalue_p.h \
serialization/qcborstream.h \
serialization/qdatastream.h \ serialization/qdatastream.h \
serialization/qdatastream_p.h \ serialization/qdatastream_p.h \
serialization/qjson_p.h \ serialization/qjson_p.h \
@ -23,7 +22,6 @@ HEADERS += \
serialization/qxmlutils_p.h serialization/qxmlutils_p.h
SOURCES += \ SOURCES += \
serialization/qcborstream.cpp \
serialization/qcbordiagnostic.cpp \ serialization/qcbordiagnostic.cpp \
serialization/qcborvalue.cpp \ serialization/qcborvalue.cpp \
serialization/qdatastream.cpp \ serialization/qdatastream.cpp \
@ -39,6 +37,14 @@ SOURCES += \
serialization/qxmlstream.cpp \ serialization/qxmlstream.cpp \
serialization/qxmlutils.cpp serialization/qxmlutils.cpp
qtConfig(cborstream): {
SOURCES += \
serialization/qcborstream.cpp
HEADERS += \
serialization/qcborstream.h
}
false: SOURCES += \ false: SOURCES += \
serialization/qcborarray.cpp \ serialization/qcborarray.cpp \
serialization/qcbormap.cpp serialization/qcbormap.cpp