Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-11 09:21:51

0001 // Copyright (C) 2018 Intel Corporation.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:critical reason:data-parser
0004 
0005 #ifndef QCBORSTREAMWRITER_H
0006 #define QCBORSTREAMWRITER_H
0007 
0008 #include <QtCore/qbytearray.h>
0009 #include <QtCore/qcborcommon.h>
0010 #include <QtCore/qscopedpointer.h>
0011 #include <QtCore/qstring.h>
0012 #include <QtCore/qstringview.h>
0013 #ifndef QT_BOOTSTRAPPED
0014 #include <QtCore/qfloat16.h>
0015 #endif
0016 
0017 #include <memory>
0018 
0019 QT_REQUIRE_CONFIG(cborstreamwriter);
0020 
0021 /* X11 headers use these values too, but as defines */
0022 #if defined(False) && defined(True)
0023 #  undef True
0024 #  undef False
0025 #endif
0026 
0027 QT_BEGIN_NAMESPACE
0028 
0029 class QIODevice;
0030 
0031 class QCborStreamWriterPrivate;
0032 class Q_CORE_EXPORT QCborStreamWriter
0033 {
0034 public:
0035     explicit QCborStreamWriter(QIODevice *device);
0036     explicit QCborStreamWriter(QByteArray *data);
0037     ~QCborStreamWriter();
0038     Q_DISABLE_COPY(QCborStreamWriter)
0039 
0040     void setDevice(QIODevice *device);
0041     QIODevice *device() const;
0042 
0043     void append(quint64 u);
0044     void append(qint64 i);
0045     void append(QCborNegativeInteger n);
0046 #if !QT_CORE_REMOVED_SINCE(6, 10)   // wasn't a template until 6.10
0047     Q_WEAK_OVERLOAD
0048 #endif
0049     void append(const QByteArray &ba)       { appendByteString(ba.constData(), ba.size()); }
0050     void append(QByteArrayView ba)          { appendByteString(ba.data(), ba.size()); }
0051     void append(QLatin1StringView str);
0052     void append(QStringView str);
0053     void append(QUtf8StringView str)        { appendTextString(str.data(), str.size()); }
0054     void append(QCborTag tag);
0055     void append(QCborKnownTags tag)         { append(QCborTag(tag)); }
0056     void append(QCborSimpleType st);
0057     void append(std::nullptr_t)             { append(QCborSimpleType::Null); }
0058 #ifndef QT_BOOTSTRAPPED
0059     void append(qfloat16 f);
0060 #endif
0061     void append(float f);
0062     void append(double d);
0063 
0064     void appendByteString(const char *data, qsizetype len);
0065     void appendTextString(const char *utf8, qsizetype len);
0066 
0067     // convenience
0068     void append(bool b)     { append(b ? QCborSimpleType::True : QCborSimpleType::False); }
0069     void appendNull()       { append(QCborSimpleType::Null); }
0070     void appendUndefined()  { append(QCborSimpleType::Undefined); }
0071 
0072 #ifndef Q_QDOC
0073     // overloads to make normal code not complain
0074     void append(int i)      { append(qint64(i)); }
0075     void append(uint u)     { append(quint64(u)); }
0076 #endif
0077 #ifndef QT_NO_CAST_FROM_ASCII
0078     void append(const char *str, qsizetype size = -1)
0079     { appendTextString(str, (str && size == -1)  ? int(strlen(str)) : size); }
0080 #endif
0081 
0082     void startArray();
0083     void startArray(quint64 count);
0084     bool endArray();
0085     void startMap();
0086     void startMap(quint64 count);
0087     bool endMap();
0088 
0089     // no API for encoding chunked strings
0090 
0091 private:
0092     std::unique_ptr<QCborStreamWriterPrivate> d;
0093 };
0094 
0095 QT_END_NAMESPACE
0096 
0097 #endif // QCBORSTREAMWRITER_H