Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcborstreamwriter.h
Go to the documentation of this file.
1// Copyright (C) 2018 Intel Corporation.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
5#ifndef QCBORSTREAMWRITER_H
6#define QCBORSTREAMWRITER_H
7
8#include <QtCore/qbytearray.h>
9#include <QtCore/qcborcommon.h>
10#include <QtCore/qscopedpointer.h>
11#include <QtCore/qstring.h>
12#include <QtCore/qstringview.h>
13#ifndef QT_BOOTSTRAPPED
14#include <QtCore/qfloat16.h>
15#endif
16
17#include <memory>
18
20
21/* X11 headers use these values too, but as defines */
22#if defined(False) && defined(True)
23# undef True
24# undef False
25#endif
26
27QT_BEGIN_NAMESPACE
28
29class QIODevice;
30
32class Q_CORE_EXPORT QCborStreamWriter
33{
34public:
35 explicit QCborStreamWriter(QIODevice *device);
36 explicit QCborStreamWriter(QByteArray *data);
37 ~QCborStreamWriter();
38 Q_DISABLE_COPY(QCborStreamWriter)
39
40 void setDevice(QIODevice *device);
41 QIODevice *device() const;
42
43 void append(quint64 u);
44 void append(qint64 i);
45 void append(QCborNegativeInteger n);
46#if !QT_CORE_REMOVED_SINCE(6, 10) // wasn't a template until 6.10
47 Q_WEAK_OVERLOAD
48#endif
49 void append(const QByteArray &ba) { appendByteString(ba.constData(), ba.size()); }
50 void append(QByteArrayView ba) { appendByteString(ba.data(), ba.size()); }
51 void append(QLatin1StringView str);
52 void append(QStringView str);
53 void append(QUtf8StringView str) { appendTextString(str.data(), str.size()); }
54 void append(QCborTag tag);
55 void append(QCborKnownTags tag) { append(QCborTag(tag)); }
56 void append(QCborSimpleType st);
57 void append(std::nullptr_t) { append(QCborSimpleType::Null); }
58#ifndef QT_BOOTSTRAPPED
59 void append(qfloat16 f);
60#endif
61 void append(float f);
62 void append(double d);
63
64 void appendByteString(const char *data, qsizetype len);
65 void appendTextString(const char *utf8, qsizetype len);
66
67 // convenience
68 void append(bool b) { append(b ? QCborSimpleType::True : QCborSimpleType::False); }
69 void appendNull() { append(QCborSimpleType::Null); }
70 void appendUndefined() { append(QCborSimpleType::Undefined); }
71
72#ifndef Q_QDOC
73 // overloads to make normal code not complain
74 void append(int i) { append(qint64(i)); }
75 void append(uint u) { append(quint64(u)); }
76#endif
77#ifndef QT_NO_CAST_FROM_ASCII
78 void append(const char *str, qsizetype size = -1)
79 { appendTextString(str, (str && size == -1) ? int(strlen(str)) : size); }
80#endif
81
82 void startArray();
83 void startArray(quint64 count);
84 bool endArray();
85 void startMap();
86 void startMap(quint64 count);
87 bool endMap();
88
89 // no API for encoding chunked strings
90
91private:
92 std::unique_ptr<QCborStreamWriterPrivate> d;
93};
94
95QT_END_NAMESPACE
96
97#endif // QCBORSTREAMWRITER_H
static constexpr quint64 IndefiniteLength
QStack< CborEncoder > containerStack
void executeAppend(CborError(*f)(CborEncoder *, Args...), Args... args)
QCborStreamWriterPrivate(QIODevice *device)
void createContainer(CborError(*f)(CborEncoder *, CborEncoder *, size_t), quint64 len=IndefiniteLength)
\inmodule QtCore\reentrant
static QT_BEGIN_NAMESPACE CborError qt_cbor_encoder_write_callback(void *token, const void *data, size_t len, CborEncoderAppendType)
static CborError cbor_encode_float_as_half_float(CborEncoder *, float)
QT_REQUIRE_CONFIG(cborstreamwriter)
Q_DECLARE_TYPEINFO(QObjectPrivate::ConnectionList, Q_RELOCATABLE_TYPE)