diff options
Diffstat (limited to 'src/corelib/serialization/qcborvalue_p.h')
-rw-r--r-- | src/corelib/serialization/qcborvalue_p.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/corelib/serialization/qcborvalue_p.h b/src/corelib/serialization/qcborvalue_p.h index c80abd68f5..eb6fe09147 100644 --- a/src/corelib/serialization/qcborvalue_p.h +++ b/src/corelib/serialization/qcborvalue_p.h @@ -124,6 +124,8 @@ class QCborContainerPrivate : public QSharedData ~QCborContainerPrivate(); public: + enum ContainerDisposition { CopyContainer, MoveContainer }; + QByteArray::size_type usedData = 0; QByteArray data; QVector<QtCbor::Element> elements; @@ -275,12 +277,13 @@ public: return data->toUtf8String(); } - static QCborValue makeValue(QCborValue::Type type, qint64 n, QCborContainerPrivate *d = nullptr) + static QCborValue makeValue(QCborValue::Type type, qint64 n, QCborContainerPrivate *d = nullptr, + ContainerDisposition disp = CopyContainer) { QCborValue result(type); result.n = n; result.container = d; - if (d) + if (d && disp == CopyContainer) d->ref.ref(); return result; } @@ -300,6 +303,24 @@ public: } return makeValue(e.type, e.value); } + QCborValue extractAt_complex(QtCbor::Element e); + QCborValue extractAt(qsizetype idx) + { + QtCbor::Element e; + qSwap(e, elements[idx]); + + if (e.flags & QtCbor::Element::IsContainer) { + if (e.type == QCborValue::Tag && e.container->elements.size() != 2) { + // invalid tags can be created due to incomplete parsing + e.container->deref(); + return makeValue(QCborValue::Invalid, 0, nullptr); + } + return makeValue(e.type, -1, e.container, MoveContainer); + } else if (e.flags & QtCbor::Element::HasByteData) { + return extractAt_complex(e); + } + return makeValue(e.type, e.value); + } static QtCbor::Element elementFromValue(const QCborValue &value) { |