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
4#ifndef QCBORSTREAMWRITER_H
5#define QCBORSTREAMWRITER_H
6
7#include <QtCore/qbytearray.h>
8#include <QtCore/qcborcommon.h>
9#include <QtCore/qscopedpointer.h>
10#include <QtCore/qstring.h>
11#include <QtCore/qstringview.h>
12#ifndef QT_BOOTSTRAPPED
13#include <QtCore/qfloat16.h>
14#endif
15
16QT_REQUIRE_CONFIG(cborstreamwriter);
17
18/* X11 headers use these values too, but as defines */
19#if defined(False) && defined(True)
20# undef True
21# undef False
22#endif
23
24QT_BEGIN_NAMESPACE
25
26class QIODevice;
27
28class QCborStreamWriterPrivate;
29class Q_CORE_EXPORT QCborStreamWriter
30{
31public:
32 explicit QCborStreamWriter(QIODevice *device);
33 explicit QCborStreamWriter(QByteArray *data);
34 ~QCborStreamWriter();
35 Q_DISABLE_COPY(QCborStreamWriter)
36
37 void setDevice(QIODevice *device);
38 QIODevice *device() const;
39
40 void append(quint64 u);
41 void append(qint64 i);
42 void append(QCborNegativeInteger n);
43 void append(const QByteArray &ba) { appendByteString(data: ba.constData(), len: ba.size()); }
44 void append(QLatin1StringView str);
45 void append(QStringView str);
46 void append(QCborTag tag);
47 void append(QCborKnownTags tag) { append(tag: QCborTag(tag)); }
48 void append(QCborSimpleType st);
49 void append(std::nullptr_t) { append(st: QCborSimpleType::Null); }
50#ifndef QT_BOOTSTRAPPED
51 void append(qfloat16 f);
52#endif
53 void append(float f);
54 void append(double d);
55
56 void appendByteString(const char *data, qsizetype len);
57 void appendTextString(const char *utf8, qsizetype len);
58
59 // convenience
60 void append(bool b) { append(st: b ? QCborSimpleType::True : QCborSimpleType::False); }
61 void appendNull() { append(st: QCborSimpleType::Null); }
62 void appendUndefined() { append(st: QCborSimpleType::Undefined); }
63
64#ifndef Q_QDOC
65 // overloads to make normal code not complain
66 void append(int i) { append(i: qint64(i)); }
67 void append(uint u) { append(u: quint64(u)); }
68#endif
69#ifndef QT_NO_CAST_FROM_ASCII
70 void append(const char *str, qsizetype size = -1)
71 { appendTextString(utf8: str, len: (str && size == -1) ? int(strlen(s: str)) : size); }
72#endif
73
74 void startArray();
75 void startArray(quint64 count);
76 bool endArray();
77 void startMap();
78 void startMap(quint64 count);
79 bool endMap();
80
81 // no API for encoding chunked strings
82
83private:
84 QScopedPointer<QCborStreamWriterPrivate> d;
85};
86
87QT_END_NAMESPACE
88
89#if defined(QT_X11_DEFINES_FOUND)
90# define True 1
91# define False 0
92#endif
93
94#endif // QCBORSTREAMWRITER_H
95

source code of qtbase/src/corelib/serialization/qcborstreamwriter.h