QtBase  v6.3.1
qcborcommon.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 Intel Corporation.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QCBORCOMMON_H
41 #define QCBORCOMMON_H
42 
43 #include <QtCore/qobjectdefs.h>
44 #include <QtCore/qmetatype.h>
45 #include <QtCore/qdebug.h>
46 
47 #if 0
48 #pragma qt_class(QtCborCommon)
49 #endif
50 
51 /* X11 headers use these values too, but as defines */
52 #if defined(False) && defined(True)
53 # undef True
54 # undef False
55 #endif
56 
58 
59 enum class QCborSimpleType : quint8 {
60  False = 20,
61  True = 21,
62  Null = 22,
63  Undefined = 23
64 };
65 
66 enum class QCborTag : quint64 {};
67 enum class QCborKnownTags {
68  DateTimeString = 0,
69  UnixTime_t = 1,
70  PositiveBignum = 2,
71  NegativeBignum = 3,
72  Decimal = 4,
73  Bigfloat = 5,
74  COSE_Encrypt0 = 16,
75  COSE_Mac0 = 17,
76  COSE_Sign1 = 18,
77  ExpectedBase64url = 21,
78  ExpectedBase64 = 22,
79  ExpectedBase16 = 23,
80  EncodedCbor = 24,
81  Url = 32,
82  Base64url = 33,
83  Base64 = 34,
84  RegularExpression = 35,
85  MimeMessage = 36,
86  Uuid = 37,
87  COSE_Encrypt = 96,
88  COSE_Mac = 97,
89  COSE_Sign = 98,
90  Signature = 55799
91 };
92 
93 inline bool operator==(QCborTag t, QCborKnownTags kt) { return quint64(t) == quint64(kt); }
94 inline bool operator==(QCborKnownTags kt, QCborTag t) { return quint64(t) == quint64(kt); }
95 inline bool operator!=(QCborTag t, QCborKnownTags kt) { return quint64(t) != quint64(kt); }
96 inline bool operator!=(QCborKnownTags kt, QCborTag t) { return quint64(t) != quint64(kt); }
97 
98 struct Q_CORE_EXPORT QCborError
99 {
100  Q_GADGET
101 public:
102  enum Code : int {
103  UnknownError = 1,
104  AdvancePastEnd = 3,
105  InputOutputError = 4,
106  GarbageAtEnd = 256,
113 
114  InvalidUtf8String = 516,
115 
116  DataTooLarge = 1024,
119 
120  NoError = 0
121  };
122  Q_ENUM(Code)
123 
125  operator Code() const { return c; }
126  QString toString() const;
127 };
128 
129 #if !defined(QT_NO_DEBUG_STREAM)
130 Q_CORE_EXPORT QDebug operator<<(QDebug, QCborSimpleType st);
131 Q_CORE_EXPORT QDebug operator<<(QDebug, QCborKnownTags tg);
132 Q_CORE_EXPORT QDebug operator<<(QDebug, QCborTag tg);
133 #endif
134 
135 #if !defined(QT_NO_DATASTREAM)
136 Q_CORE_EXPORT QDataStream &operator<<(QDataStream &ds, QCborSimpleType st);
137 Q_CORE_EXPORT QDataStream &operator>>(QDataStream &ds, QCborSimpleType &st);
138 #endif
139 
140 inline size_t qHash(QCborSimpleType tag, size_t seed = 0)
141 {
142  return qHash(quint8(tag), seed);
143 }
144 
145 inline size_t qHash(QCborTag tag, size_t seed = 0)
146 {
147  return qHash(quint64(tag), seed);
148 }
149 
151 
153 
154 QT_DECL_METATYPE_EXTERN(QCborTag, Q_CORE_EXPORT)
155 
156 // To avoid changing namespace we need to reinstate defines, even though our .cpp
157 // will then have to remove them again.
158 #if defined(QT_X11_DEFINES_FOUND)
159 # define True 1
160 # define False 0
161 #endif
162 
163 #endif // QCBORSTREAM_H
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
template< typename Enum > bool operator!=(Enum lhs, QFlags< Enum > rhs)
template< typename Enum > size_t qHash(QFlags< Enum > flags, size_t seed=0) noexcept
template< typename Enum > bool operator==(Enum lhs, QFlags< Enum > rhs)
The QString class provides a Unicode character string.
Definition: qstring.h:388
#define Code
Definition: deflate.h:80
QCborKnownTags
Definition: qcborcommon.h:67
QCborTag
Definition: qcborcommon.h:66
QCborSimpleType
Definition: qcborcommon.h:59
QCborNegativeInteger
Definition: qcborcommon.h:150
unsigned long long quint64
Definition: qglobal.h:299
unsigned char quint8
Definition: qglobal.h:284
#define QT_DECL_METATYPE_EXTERN(TYPE, EXPORT)
Definition: qmetatype.h:1285
const GLubyte * c
Definition: qopenglext.h:12701
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_GADGET
Definition: qtmetamacros.h:193
Definition: hb-null.hh:93
The QCborError class holds the error condition found while parsing or validating a CBOR stream.
Definition: qcborcommon.h:99
@ IllegalSimpleType
Definition: qcborcommon.h:112
XmlOutput::xml_output tag(const QString &name)
Definition: xmloutput.h:154