1// qcborstream.sip generated by MetaSIP
2//
3// This file is part of the QtCore Python extension module.
4//
5// Copyright (c) 2021 Riverbank Computing Limited <info@riverbankcomputing.com>
6//
7// This file is part of PyQt5.
8//
9// This file may be used under the terms of the GNU General Public License
10// version 3.0 as published by the Free Software Foundation and appearing in
11// the file LICENSE included in the packaging of this file.  Please review the
12// following information to ensure the GNU General Public License version 3.0
13// requirements will be met: http://www.gnu.org/copyleft/gpl.html.
14//
15// If you do not wish to use this file under the terms of the GPL version 3.0
16// then you may purchase a commercial license.  For more information contact
17// info@riverbankcomputing.com.
18//
19// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21
22
23%If (Qt_5_12_0 -)
24
25class QCborStreamWriter
26{
27%TypeHeaderCode
28#include <qcborstream.h>
29%End
30
31public:
32    explicit QCborStreamWriter(QIODevice *device);
33    explicit QCborStreamWriter(QByteArray *data);
34    ~QCborStreamWriter();
35    void setDevice(QIODevice *device);
36    QIODevice *device() const;
37    void append(QCborSimpleType st);
38    void append(QCborKnownTags tag);
39    void append(const QString &str) [void (QStringView str)];
40    void append(const QByteArray &ba);
41    void append(bool b /Constrained/);
42    void append(double d /Constrained/);
43%MethodCode
44        // Use the smallest type without losing precision.
45
46        qfloat16 a0_16 = a0;
47
48        if (qIsNaN(a0) || a0_16 == a0)
49        {
50            sipCpp->append(a0_16);
51        }
52        else
53        {
54            float a0_float = a0;
55
56            if (a0_float == a0)
57                sipCpp->append(a0_float);
58            else
59                sipCpp->append(a0);
60        }
61%End
62
63    void append(SIP_PYOBJECT /TypeHint="int"/);
64%MethodCode
65        #if PY_MAJOR_VERSION < 3
66        if (PyLong_Check(a0))
67        #endif
68        {
69            static PyObject *zero = 0;
70
71            if (!zero)
72                zero = PyLong_FromLong(0);
73
74            if (PyObject_RichCompareBool(a0, zero, Py_LT) > 0)
75            {
76                PyErr_Clear();
77                qint64 val = sipLong_AsLongLong(a0);
78
79                if (PyErr_Occurred())
80                    sipError = sipErrorFail;
81                else
82                    sipCpp->append(val);
83            }
84            else
85            {
86                PyErr_Clear();
87                quint64 val = sipLong_AsUnsignedLongLong(a0);
88
89                if (PyErr_Occurred())
90                    sipError = sipErrorFail;
91                else
92                    sipCpp->append(val);
93            }
94        }
95        #if PY_MAJOR_VERSION < 3
96        else if (PyInt_Check(a0))
97        {
98            PyErr_Clear();
99            long val = PyInt_AsLong(a0);
100
101            if (PyErr_Occurred())
102                sipError = sipErrorFail;
103            else if (val < 0)
104                sipCpp->append((qint64)val);
105            else
106                sipCpp->append((quint64)val);
107        }
108        #endif
109%End
110
111    void appendNull();
112    void appendUndefined();
113    void startArray();
114    void startArray(quint64 count);
115    bool endArray();
116    void startMap();
117    void startMap(quint64 count);
118    bool endMap();
119
120private:
121    QCborStreamWriter(const QCborStreamWriter &);
122};
123
124%End
125%If (Qt_5_12_0 -)
126
127class QCborStreamReader
128{
129%TypeHeaderCode
130#include <qcborstream.h>
131%End
132
133public:
134    enum Type
135    {
136        UnsignedInteger,
137        NegativeInteger,
138        ByteString,
139        ByteArray,
140        TextString,
141        String,
142        Array,
143        Map,
144        Tag,
145        SimpleType,
146        HalfFloat,
147        Float16,
148        Float,
149        Double,
150        Invalid,
151    };
152
153    enum StringResultCode
154    {
155        EndOfString,
156        Ok,
157        Error,
158    };
159
160    QCborStreamReader();
161    explicit QCborStreamReader(const QByteArray &data);
162    explicit QCborStreamReader(QIODevice *device);
163    ~QCborStreamReader();
164    void setDevice(QIODevice *device);
165    QIODevice *device() const;
166    void addData(const QByteArray &data);
167    void reparse();
168    void clear();
169    void reset();
170    QCborError lastError();
171    qint64 currentOffset() const;
172    bool isValid() const;
173    int containerDepth() const;
174    QCborStreamReader::Type parentContainerType() const;
175    bool hasNext() const;
176    bool next(int maxRecursion = 10000);
177    QCborStreamReader::Type type() const;
178    bool isUnsignedInteger() const;
179    bool isNegativeInteger() const;
180    bool isInteger() const;
181    bool isByteArray() const;
182    bool isString() const;
183    bool isArray() const;
184    bool isMap() const;
185    bool isTag() const;
186    bool isSimpleType() const;
187    bool isFloat16() const;
188    bool isFloat() const;
189    bool isDouble() const;
190    bool isInvalid() const;
191    bool isSimpleType(QCborSimpleType st) const;
192    bool isFalse() const;
193    bool isTrue() const;
194    bool isBool() const;
195    bool isNull() const;
196    bool isUndefined() const;
197    bool isLengthKnown() const;
198    quint64 length() const /__len__/;
199    bool isContainer() const;
200    bool enterContainer();
201    bool leaveContainer();
202    SIP_PYTUPLE readString() /TypeHint="Tuple[str, QCborStreamReader.StringResultCode]"/;
203%MethodCode
204        QCborStreamReader::StringResult<QString> res = sipCpp->readString();
205
206        QString *qs = new QString;
207        if (res.status != QCborStreamReader::Error)
208            *qs = res.data;
209
210        sipRes = sipBuildResult(NULL, "NF", qs, sipType_QString, NULL, res.status, sipType_QCborStreamReader_StringResultCode);
211%End
212
213    SIP_PYTUPLE readByteArray() /TypeHint="Tuple[QByteArray, QCborStreamReader.StringResultCode]"/;
214%MethodCode
215        QCborStreamReader::StringResult<QByteArray> res = sipCpp->readByteArray();
216
217        QByteArray *qba = new QByteArray;
218        if (res.status != QCborStreamReader::Error)
219            *qba = res.data;
220
221        sipRes = sipBuildResult(NULL, "NF", qba, sipType_QByteArray, NULL, res.status, sipType_QCborStreamReader_StringResultCode);
222%End
223
224    bool toBool() const;
225    quint64 toUnsignedInteger() const;
226    QCborSimpleType toSimpleType() const;
227    double toDouble() const;
228    qint64 toInteger() const;
229
230private:
231    QCborStreamReader(const QCborStreamReader &);
232};
233
234%End
235