From c17a934197a0ca27c15abebbbdfddc6b70a393f0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 13 Feb 2025 08:12:45 -0800 Subject: [PATCH] QCborStreamWriter: add append(QByteArrayView) This required demoting the QByteArray overload to Q_WEAK_OVERLOAD to avoid introducing ambiguities. [ChangeLog][QtCore][QCborStreamWriter] Added a QByteArrayView overload of append(). Change-Id: I3004bd691aca990cb67dfffde63b58bb378e3311 Reviewed-by: Ahmad Samir --- src/corelib/compat/removed_api.cpp | 2 ++ src/corelib/serialization/qcborstreamwriter.cpp | 4 ++++ src/corelib/serialization/qcborstreamwriter.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index b80af92a549..d315aed8e6b 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -1380,6 +1380,8 @@ QUuid::Version QUuid::version() const noexcept #if QT_CORE_REMOVED_SINCE(6, 10) +#include "qcborstreamwriter.h" // Q_WEAK_OVERLOAD added + #include "qcoreapplication.h" #if QT_CONFIG(permissions) diff --git a/src/corelib/serialization/qcborstreamwriter.cpp b/src/corelib/serialization/qcborstreamwriter.cpp index 4b1ef64313d..950c08270d4 100644 --- a/src/corelib/serialization/qcborstreamwriter.cpp +++ b/src/corelib/serialization/qcborstreamwriter.cpp @@ -397,6 +397,7 @@ void QCborStreamWriter::append(QCborNegativeInteger n) /*! \fn void QCborStreamWriter::append(const QByteArray &ba) + \fn void QCborStreamWriter::append(QByteArrayView ba) \overload Appends the byte array \a ba to the stream, creating a CBOR Byte String @@ -411,6 +412,9 @@ void QCborStreamWriter::append(QCborNegativeInteger n) As the example shows, unlike JSON, CBOR requires no escaping for binary content. + \note The overload taking a \l QByteArrayView has been present since Qt + 6.10. + \sa appendByteString(), QCborStreamReader::isByteArray(), QCborStreamReader::readByteArray() */ diff --git a/src/corelib/serialization/qcborstreamwriter.h b/src/corelib/serialization/qcborstreamwriter.h index 976a0cb34a4..dbc340e0b35 100644 --- a/src/corelib/serialization/qcborstreamwriter.h +++ b/src/corelib/serialization/qcborstreamwriter.h @@ -42,7 +42,11 @@ public: void append(quint64 u); void append(qint64 i); void append(QCborNegativeInteger n); +#if !QT_CORE_REMOVED_SINCE(6, 10) // wasn't a template until 6.10 + Q_WEAK_OVERLOAD +#endif void append(const QByteArray &ba) { appendByteString(ba.constData(), ba.size()); } + void append(QByteArrayView ba) { appendByteString(ba.data(), ba.size()); } void append(QLatin1StringView str); void append(QStringView str); void append(QCborTag tag);