QCborValue Class▲
-
Header: QCborValue
-
Since: Qt 5.12
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Group: QCborValue is part of cbor
Detailed Description▲
This class can be used to hold one of the many types available in CBOR. CBOR is the Concise Binary Object Representation, a very compact form of binary data encoding that is a superset of JSON. It was created by the IETF Constrained RESTful Environments (CoRE) WG, which has used it in many new RFCs. It is meant to be used alongside the https://.
CBOR has three groups of built-in types:
-
Basic types: integers, floating point (double), boolean, null, etc.
-
String-like types: strings and byte arrays
-
Containers: arrays and maps
Additionally, CBOR supports a form of type extensibility by associating a "tag" to one of the above types to convey more information. For example, a UUID is represented by a tag and a byte array containing the 16 bytes of the UUID content. https:// supports creating and decoding several of those extended types directly with Qt classes (like https://).
For the complete list, see https://. The type of a https:// can be queried using https://() or one of the "isXxxx" functions.
Extended types and tagged values▲
A tagged value is a normal https:// that is paired with a number that is its tag. See https:// for more information on what tags are in the API as well as the full, official list. Such combinations form extended types.
https:// has support for certain extended types in the API, like URL (with https://) and UUID (with https://). Other extended types not supported in the API are represented by a https:// of https:// type. The tag can later be retrieved by https://() and the tagged value using https://().
In order to support future compatibility, QCborValues containing extended Qt types compare equal to the tag type of the same contents. In other words, the following expression is true:
QCborValue(uuid) == QCborValue(QCborKnownTags::Uuid, uuid.toRfc4122());Undefined and null values▲
https:// can contain a value of "null", which is not of any specific type. It resembles the C++ std::nullptr_t type, whose only possible value is nullptr. https:// has a constructor taking such a type and creates a null https://.
Null values are used to indicate that an optional value is not present. In that aspect, it is similar to the C++ Standard Library type std::optional when that is disengaged. Unlike the C++ type, CBOR nulls are simply of type "Null" and it is not possible to determine what concrete type it is replacing.
https:// can also be of the undefined type, which represents a value of "undefined". In fact, that is what the https:// default constructor creates.
Undefined values are different from null values. While nulls are used to indicate an optional value that is not provided, Undefined is usually used to indicate that an expected value could not be provided, usually due to an error or a precondition that could not be satisfied.
Such values are completely valid and may appear in CBOR streams, unlike JSON content and https://'s undefined bit. But like https://'s Undefined, it is returned by a CBOR container's value() or read-only operator[] for invalid look-ups (index out of range for https://, or key not found for https://). It is not possible to tell such a case apart from the value of Undefined, so if that is required, check the https:// size and use the https:// iterator API.
Simple types▲
CBOR supports additional simple types that, like Null and Undefined, carry no other value. They are called interchangeably "Simple Types" and "Simple Values". CBOR encodes booleans as two distinct types (one for true and one for false), but https:// has a convenience API for them.
There are currently no other defined CBOR simple types. https:// supports them simply by their number with API like https://() and https://(), available for compatibility with future specifications before the Qt API can be updated. Their use before such a specification is discouraged, as other CBOR implementations may not support them fully.
CBOR support▲
https:// supports all CBOR features required to create canonical and strict streams. It implements almost all of the features specified in https://.
The following table lists the CBOR features that https:// supports.
|
Feature |
Support |
|---|---|
|
Unsigned numbers |
Yes (https:// range) |
|
Negative numbers |
Yes (https:// range) |
|
Byte strings |
Yes |
|
Text strings |
Yes |
|
Chunked strings |
See below |
|
Tags |
Yes (arbitrary) |
|
Booleans |
Yes |
|
Null |
Yes |
|
Undefined |
Yes |
|
Arbitrary simple values |
Yes |
|
Half-precision float (16-bit) |
Yes |
|
Single-precision float (32-bit) |
Yes |
|
Double-precision float (64-bit) |
Yes |
|
Infinities and NaN floating point |
Yes |
|
Determinate-length arrays and maps |
Yes |
|
Indeterminate-length arrays and maps |
Yes |
|
Map key types other than strings and integers |
Yes (arbitrary) |
Integers in https:// are limited to the range of the https:// type. That is, from -9,223,372,036,854,775,808 (-263) to 9,223,372,036,854,775,807 (263 - 1). CBOR itself can represent integer values outside of this range, which https:// does not support. When decoding a stream using https://() containing one of those values, https:// will convert automatically to https://, but that may lose up to 11 bits of precision.
https://() is able to decode chunked strings, but will always merge the chunks together into a single https://. For that reason, it always writes non-chunked strings when using https://() (which is required by the Canonical format anyway).
https:// will always convert half- and single-precision floating point values in the CBOR stream to double-precision. The https://() function can take a parameter indicating to recreate them.
QCborValueRef▲
QCborValueRef is a helper class for https:// and https://. It is the type you get when using one of the mutating APIs in those classes. Unlike https://, new values can be assigned to that class. When that is done, the array or map it refers to will be modified with the new value. In all other aspects, its API is identical to https://.
https://, https://
See Also▲
See also https://, https://, https://, https://
Member Type Documentation▲
enum QCborValue::DiagnosticNotationOption▲
flags QCborValue::DiagnosticNotationOptions
This enum is used in the option argument to https://(), to modify the output format.
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Compact |
0x00 |
Does not use any line-breaks, producing a compact representation. |
|
https://::LineWrapped |
0x01 |
Uses line-breaks, one https:// per line. |
|
https://::ExtendedFormat |
0x02 |
Uses some different options to represent values, not found in RFC 7049. Those options are subject to change. |
Currently, ExtendedFormat will change how byte arrays are represented. Without it, they are always hex-encoded and without spaces. With it, https://() will either use hex with spaces, base64 or base64url encoding, depending on the context.
The DiagnosticNotationOptions type is a typedef for https://<DiagnosticNotationOption>. It stores an OR combination of DiagnosticNotationOption values.
See Also▲
See also https://()
enum QCborValue::EncodingOption▲
flags QCborValue::EncodingOptions
This enum is used in the options argument to https://(), modifying the behavior of the encoder.
|
Constant |
Value |
Description |
|---|---|---|
|
https://::NoTransformation |
0 |
(Default) Performs no transformations. |
|
https://::UseFloat |
0x02 |
Tells the encoder to use IEEE 754 single-precision floating point (that is, float) whenever possible. |
|
https://::UseFloat16 |
UseFloat | 0x04 |
Tells the encoder to use IEEE 754 half-precision floating point (that is, qfloat16), whenever possible. Implies UseFloat. |
|
https://::UseIntegers |
0x08 |
Tells the encoder to use integers whenever a value of type https:// contains an integer. |
The use of UseFloat16 is required to encode the stream in Canonical Format, but is not otherwise necessary.
The EncodingOptions type is a typedef for https://<EncodingOption>. It stores an OR combination of EncodingOption values.
See Also▲
See also https://()
enum QCborValue::Type▲
This enum represents the https:// type. It is returned by the https://() function.
The CBOR built-in types are:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Integer |
0x00 |
qint64: An integer value |
|
https://::ByteArray |
0x40 |
https://: a byte array ("byte string") |
|
https://::String |
0x60 |
https://: a Unicode string ("text string") |
|
https://::Array |
0x80 |
https://: an array of QCborValues |
|
https://::Map |
0xa0 |
https://: an associative container of QCborValues |
|
https://::SimpleType |
0x100 |
https://: one of several simple types/values |
|
https://::False |
SimpleType + int(QCborSimpleType::False) |
bool: the simple type for value false |
|
https://::True |
SimpleType + int(QCborSimpleType::True) |
bool: the simple type for value true |
|
https://::Null |
SimpleType + int(QCborSimpleType::Null) |
std::nullptr_t: the simple type for the null value |
|
https://::Undefined |
SimpleType + int(QCborSimpleType::Undefined) |
(no type) the simple type for the undefined value |
|
https://::Double |
0x202 |
double: a double-precision floating point |
|
https://::Invalid |
-1 |
Not a valid value, this usually indicates a CBOR decoding error |
Additionally, https:// can represent extended types:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Tag |
0xc0 |
An unknown or unrecognized extended type, represented by its tag (a https://) and the tagged value (a https://) |
|
https://::DateTime |
0x10000 |
https://: a date and time stamp |
|
https://::Url |
0x10020 |
https://: a URL or URI |
|
https://::RegularExpression |
0x10023 |
https://: the pattern of a regular expression |
|
https://::Uuid |
0x10025 |
https://: a UUID |
See Also▲
See also https://()
Member Function Documentation▲
QCborValue::QCborValue(QCborArray &&a)▲
QCborValue::QCborValue(const QCborArray &a)
Creates a https:// with the array a. The array can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QCborMap &&m)▲
QCborValue::QCborValue(const QCborMap &m)
Creates a https:// with the map m. The map can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QCborKnownTags tag, const QCborValue &tv = QCborValue())▲
QCborValue::QCborValue(QCborTag tag, const QCborValue &tv = QCborValue())
Creates a https:// for the extended type represented by the tag value tag, tagging value tv. The tag can later be retrieved using https://() and the tagged value using https://().
See Also▲
See also https://(), https://(), https://(), https://
QCborArray QCborValue::toArray() const▲
QCborArray QCborValue::toArray(const QCborArray &defaultValue) const
Returns the array value stored in this https://, if it is of the array type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
QCborMap QCborValue::toMap() const▲
QCborMap QCborValue::toMap(const QCborMap &defaultValue) const
Returns the map value stored in this https://, if it is of the map type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://(), https://()
[static] QCborValue QCborValue::fromCbor(const char *data, qsizetype len, QCborParserError *error = nullptr)▲
[static] QCborValue QCborValue::fromCbor(const quint8 *data, qsizetype len, QCborParserError *error = nullptr)
This is an overloaded function.
Converts len bytes of data to a https:// and then calls the overload of this function that accepts a https://, also passing error, if provided.
QCborValue::QCborValue()▲
Creates a https:// of the https:// type.
CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the https:// and https:// API to indicate the searched item was not found.
Undefined values are represented by the https://. Because of that, QCborValues with undefined values will also return true for https://() and isSimpleType(QCborSimpleType::Undefined).
Undefined values are different from null values.
https:// objects with undefined values are also different from invalid https:// objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QCborValue::Type t_)▲
Creates a https:// of type t_. The value associated with such a type (if any) will be default constructed.
See Also▲
See also https://()
QCborValue::QCborValue(std::nullptr_t)▲
Creates a https:// of the https:// type.
CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(bool b)▲
Creates a https:// with boolean value b. The value can later be retrieved using https://().
Internally, CBOR booleans are represented by a pair of types, one for true and one for false. For that reason, boolean QCborValues will return true for https://() and one of isSimpleType(QCborSimpleType::False) or isSimpleType(QCborSimpleType::True).
See Also▲
See also https://(), https://(), https://(), https://(), https://()
QCborValue::QCborValue(qint64 i)▲
Creates a https:// with integer value i. The value can later be retrieved using https://().
CBOR integer values are distinct from floating point values. Therefore, https:// objects with integers will compare differently to https:// objects containing floating-point, even if the values contained in the objects are equivalent.
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(double d)▲
Creates a https:// with floating point value d. The value can later be retrieved using https://().
CBOR floating point values are distinct from integer values. Therefore, https:// objects with integers will compare differently to https:// objects containing floating-point, even if the values contained in the objects are equivalent.
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QCborSimpleType st)▲
Creates a https:// of simple type st. The type can later later be retrieved using https://() as well as https://(st).
CBOR simple types are types that do not have any associated value, like C++'s std::nullptr_t type, whose only possible value is nullptr.
If st is QCborSimpleType::Null, the resulting https:// will be of the https:// type and similarly for QCborSimpleType::Undefined. If st is QCborSimpleType::False or QCborSimpleType::True, the created https:// will be a boolean containing a value of false or true, respectively.
This function can be used with simple types not defined in the API. For example, to create a https:// with simple type 12, one could write:
QCborValue value(QCborSimpleType(12));Simple types should not be used until a specification for them has been published, since other implementations may not support them properly. Simple type values 24 to 31 are reserved and must not be used.
https://(), https://(), https://(), https://(), https://()
QCborValue::QCborValue(const QByteArray &ba)▲
Creates a https:// with byte array value ba. The value can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(const QString &s)▲
Creates a https:// with string value s. The value can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QStringView s)▲
Creates a https:// with string value s. The value can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(QLatin1String s)▲
This is an overloaded function.
Creates a https:// with string value s. The value can later be retrieved using https://().
See Also▲
See also https://(), https://(), https://()
[explicit] QCborValue::QCborValue(const QDateTime &dt)▲
Creates a https:// object of the date/time extended type and containing the value represented by dt. The value can later be retrieved using https://().
The CBOR date/time types are extension types using tags: either a string (in ISO date format) tagged as a https:// or a number (of seconds since the start of 1970, UTC) tagged as a https://. When parsing CBOR streams, https:// will convert https:// to the string-based type.
See Also▲
See also https://(), https://(), https://()
[explicit] QCborValue::QCborValue(const QUrl &url)▲
Creates a https:// object of the URL extended type and containing the value represented by url. The value can later be retrieved using https://().
The CBOR URL type is an extended type represented by a string tagged as an https://.
See Also▲
See also https://(), https://(), https://()
[explicit] QCborValue::QCborValue(const QRegularExpression &rx)▲
Creates a https:// object of the regular expression pattern extended type and containing the value represented by rx. The value can later be retrieved using https://().
The CBOR regular expression type is an extended type represented by a string tagged as an https://. Note that CBOR regular expressions only store the patterns, so any flags that the https:// object may carry will be lost.
See Also▲
See also https://(), https://(), https://()
[explicit] QCborValue::QCborValue(const QUuid &uuid)▲
Creates a https:// object of the UUID extended type and containing the value represented by uuid. The value can later be retrieved using https://().
The CBOR UUID type is an extended type represented by a byte array tagged as an https://.
See Also▲
See also https://(), https://(), https://()
QCborValue::QCborValue(const QCborValue &other)▲
Copies the contents of other into this object.
QCborValue::QCborValue(QCborValue &&other)▲
This is an overloaded function.
Moves the contents of the other https:// object into this one and frees the resources of this one.
QCborValue::~QCborValue()▲
Disposes of the current https:// object and frees any associated resources.
int QCborValue::compare(const QCborValue &other) const▲
Compares this value and other, and returns an integer that indicates whether this value should be sorted prior to (if the result is negative) or after other (if the result is positive). If this function returns 0, the two values are equal and hold the same contents.
If each https:// contains an array or map, the comparison is recursive to elements contained in them.
Extended types▲
https:// compares equal a https:// containing an extended type, like https:// and https:// and its equivalent tagged representation. So, for example, the following expression is true:
QCborValue(QUrl("https://example.com")) == QCborValue(QCborKnownTags::Url, "https://example.com");Do note that Qt types like https:// and https:// will normalize and otherwise modify their arguments. The expression above is true only because the string on the right side is the normalized value that the https:// on the left would take. If, for example, the "https" part were uppercase in both sides, the comparison would fail. For information on normalizations performed by https://, please consult the documentation of the constructor taking the Qt type in question.
Sorting order▲
Sorting order in CBOR is defined in RFC 7049 {https://tools.ietf.org/html/rfc7049#section-3.9}{section 3.9}, which discusses the sorting of keys in a map when following the Canonical encoding. According to the specification, "sorting is performed on the bytes of the representation of the key data items" and lists as consequences that:
-
"If two keys have different lengths, the shorter one sorts earlier;"
-
"If two keys have the same length, the one with the lower value in (byte-wise) lexical order sorts earlier."
This results in surprising sorting of QCborValues, where the result of this function is different from that which would later be retrieved by comparing the contained elements. For example, the https:// containing string "zzz" sorts before the https:// with string "foobar", even though when comparing as https:// or https:// the "zzz" sorts after "foobar" (dictionary order).
The specification does not clearly indicate what sorting order should be done for values of different types (it says sorting should not pay "attention to the 3/5 bit splitting for major types"). https:// makes the assumption that types should be sorted too. The numeric values of the https:// enumeration are in that order, with the exception of the extended types, which compare as their tagged equivalents.
Sorting order is preliminary and is subject to change. Applications should not depend on the order returned by this function for the time being.
Notes▲
See Also▲
See also https://(), https://(), https://()
[static] QCborValue QCborValue::fromCbor(QCborStreamReader &reader)▲
Decodes one item from the CBOR stream found in reader and returns the equivalent representation. This function is recursive: if the item is a map or array, it will decode all items found in that map or array, until the outermost object is finished.
This function need not be used on the root element of a https://. For example, the following code illustrates how to skip the CBOR signature tag from the beginning of a file:
if (reader.isTag() && reader.toTag() == QCborKnownTags::Signature)
reader.next();
QCborValue contents = QCborValue::fromCbor(reader);The returned value may be partially complete and indistinguishable from a valid https:// even if the decoding failed. To determine if there was an error, check if https://() is indicating an error condition. This function stops decoding immediately after the first error.
See Also▲
See also https://(), https://(), https://(), https://()
[static] QCborValue QCborValue::fromCbor(const QByteArray &ba, QCborParserError *error = nullptr)▲
This is an overloaded function.
Decodes one item from the CBOR stream found in the byte array ba and returns the equivalent representation. This function is recursive: if the item is a map or array, it will decode all items found in that map or array, until the outermost object is finished.
This function stores the error state, if any, in the object pointed to by error, along with the offset of where the error occurred. If no error happened, it stores https:// in the error state and the number of bytes that it consumed (that is, it stores the offset for the first unused byte). Using that information makes it possible to parse further data that may exist in the same byte array.
The returned value may be partially complete and indistinguishable from a valid https:// even if the decoding failed. To determine if there was an error, check if there was an error stored in error. This function stops decoding immediately after the first error.
See Also▲
See also https://(), https://(), https://(), https://()
[static] QCborValue QCborValue::fromJsonValue(const QJsonValue &v)▲
Converts the JSON value contained in v into its corresponding CBOR value and returns it. There is no data loss in converting from JSON to CBOR, as the CBOR type set is richer than JSON's. Additionally, values converted to CBOR using this function can be converted back to JSON using https://() with no data loss.
The following table lists the mapping of JSON types to CBOR types:
|
JSON Type |
CBOR Type |
|---|---|
|
Bool |
Bool |
|
Number |
Integer (if the number has no fraction and is in the https:// range) or Double |
|
String |
String |
|
Array |
Array |
|
Object |
Map |
|
Null |
Null |
https:// can also be undefined, indicating a previous operation that failed to complete (for example, searching for a key not present in an object). Undefined values are not JSON types and may not appear in JSON arrays and objects, but this function does return the https:// undefined value if the corresponding https:// is undefined.
See Also▲
See also https://(), https://(), https://(), https://()
[static] QCborValue QCborValue::fromVariant(const QVariant &variant)▲
Converts the https:// variant into https:// and returns it.
QVariants may contain a large list of different meta types, many of which have no corresponding representation in CBOR. That includes all user-defined meta types. When preparing transmission using CBOR, it is suggested to encode carefully each value to prevent loss of representation.
The following table lists the conversion this function will apply:
|
Qt (C++) type |
CBOR type |
|---|---|
|
invalid (QVariant()) |
Undefined |
|
bool |
Bool |
|
std::nullptr_t |
Null |
|
short, ushort, int, uint, https:// |
Integer |
|
https:// |
Integer, or Double if outside the range of qint64 |
|
float, double |
Double |
|
https:// |
https:// |
|
https:// |
https:// |
|
https:// |
Simple type |
|
https:// |
Array, converted using QCborArray::formJsonArray() |
|
https:// |
Array or Map |
|
https:// |
Map, converted using https://() |
|
https:// |
converted using https://() |
|
https:// |
https:// |
|
https:// |
String |
|
https:// |
Array |
|
https:// |
Map |
|
https:// |
Array |
|
https:// |
Map |
|
https:// |
Url |
|
https:// |
Uuid |
If https://() returns true, a null https:// is returned or inserted into the list or object, regardless of the type carried by https://. Note the behavior change in Qt 6.0 affecting https://() also affects this function.
For other types not listed above, a conversion to string will be attempted, usually but not always by calling https://(). If the conversion fails the value is replaced by an Undefined CBOR value. Note that https://() is also lossy for the majority of types.
Please note that the conversions via https://() are subject to change at any time. Both https:// and https:// may be extended in the future to support more types, which will result in a change in how this function performs conversions.
See Also▲
See also https://(), https://(), https://(), https://(), https://()
bool QCborValue::isArray() const▲
Returns true if this https:// is of the array type. The array value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isBool() const▲
Returns true if this https:// is a boolean. The value can be retrieved using https://().
See Also▲
See also https://(), https://(), https://(), https://()
bool QCborValue::isByteArray() const▲
Returns true if this https:// is of the byte array type. The byte array value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isContainer() const▲
This convenience function returns true if the https:// is either an array or a map.
See Also▲
See also https://(), https://()
bool QCborValue::isDateTime() const▲
Returns true if this https:// is of the date/time type. The value can be retrieved using https://(). Date/times are extended types that use the tag https://.
Additionally, when decoding from a CBOR stream, https:// will interpret tags of value https:// and convert them to the equivalent date/time.
See Also▲
See also https://(), https://()
bool QCborValue::isDouble() const▲
Returns true if this https:// is of the floating-point type. The value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isFalse() const▲
Returns true if this https:// is a boolean with false value. This function exists because, internally, CBOR booleans are stored as two separate types, one for true and one for false.
See Also▲
See also https://(), https://(), https://(), https://()
bool QCborValue::isInteger() const▲
Returns true if this https:// is of the integer type. The integer value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isInvalid() const▲
Returns true if this https:// is not of any valid type. Invalid QCborValues are distinct from those with undefined values and they usually represent a decoding error.
See Also▲
See also https://(), https://()
bool QCborValue::isMap() const▲
Returns true if this https:// is of the map type. The map value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isNull() const▲
Returns true if this https:// is of the null type.
CBOR null values are used to indicate optional values that were not provided. They are distinct from undefined values, in that null values are usually not the result of an earlier error or problem.
Null values are distinct from undefined values and from invalid https:// objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
See Also▲
See also https://(), https://(), https://()
bool QCborValue::isRegularExpression() const▲
Returns true if this https:// contains a regular expression's pattern. The pattern can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isSimpleType() const▲
Returns true if this https:// is of one of the CBOR simple types. The type itself can later be retrieved using https://(), even for types that don't have an enumeration in the API. They can also be checked with the https://(QCborSimpleType) overload.
See Also▲
See also https://, https://(QCborSimpleType), https://()
bool QCborValue::isSimpleType(QCborSimpleType st) const▲
This is an overloaded function.
Returns true if this https:// is of a simple type and https://() would return st, false otherwise. This function can be used to check for any CBOR simple type, even those for which there is no enumeration in the API. For example, for the simple type of value 12, you could write:
value.isSimpleType(QCborSimpleType(12));See Also▲
See also https://(QCborSimpleType), https://(), https://(), https://(), https://, https://(), https://()
bool QCborValue::isString() const▲
Returns true if this https:// is of the string type. The string value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isTag() const▲
Returns true if this https:// is of the tag type. The tag value can be retrieved using https://() and the tagged value using https://().
This function also returns true for extended types that the API recognizes. For code that handles extended types directly before the Qt API is updated to support them, it is possible to recreate the tag + tagged value pair by using https://().
See Also▲
See also https://(), https://(), https://(), https://()
bool QCborValue::isTrue() const▲
Returns true if this https:// is a boolean with true value. This function exists because, internally, CBOR booleans are stored as two separate types, one for false and one for true.
See Also▲
See also https://(), https://(), https://(), https://()
bool QCborValue::isUndefined() const▲
Returns true if this https:// is of the undefined type.
CBOR undefined values are used to indicate missing information, usually as a result of a previous operation that did not complete as expected. They are also used by the https:// and https:// API to indicate the searched item was not found.
Undefined values are distinct from null values.
https:// objects with undefined values are also different from invalid https:// objects. The API will not create invalid QCborValues, but they may exist as a result of a parsing error.
See Also▲
See also https://(), https://(), https://()
bool QCborValue::isUrl() const▲
Returns true if this https:// is of the URL type. The URL value can be retrieved using https://().
See Also▲
See also https://(), https://()
bool QCborValue::isUuid() const▲
Returns true if this https:// contains a UUID. The value can be retrieved using https://().
See Also▲
See also https://(), https://()
void QCborValue::swap(QCborValue &other)▲
Swaps the contents of this https:// object and other.
QCborTag QCborValue::tag(QCborTag defaultValue = QCborTag(-1)) const▲
Returns the tag of this extended https:// object, if it is of the tag type, defaultValue otherwise.
CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that number. To retrieve the representation, use https://().
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://()
QCborValue QCborValue::taggedValue(const QCborValue &defaultValue = QCborValue()) const▲
Returns the tagged value of this extended https:// object, if it is of the tag type, defaultValue otherwise.
CBOR represents extended types by associating a number (the tag) with a stored representation. This function returns that representation. To retrieve the tag, use https://().
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://()
bool QCborValue::toBool(bool defaultValue = false) const▲
Returns the boolean value stored in this https://, if it is of a boolean type. Otherwise, it returns defaultValue.
See Also▲
See also https://(), https://(), https://()
QByteArray QCborValue::toByteArray(const QByteArray &defaultValue = {}) const▲
Returns the byte array value stored in this https://, if it is of the byte array type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QByteArray QCborValue::toCbor(QCborValue::EncodingOptions opt = NoTransformation) const▲
Encodes this https:// object to its CBOR representation, using the options specified in opt, and return the byte array containing that representation.
This function will not fail, except if this https:// or any of the contained items, if this is a map or array, are invalid. Invalid types are not produced normally by the API, but can result from decoding errors.
By default, this function performs no transformation on the values in the https://, writing all floating point directly as double-precision (double) types. If the https:// option is specified, it will use single precision (float) for any floating point value for which there's no loss of precision in using that representation. That includes infinities and NaN values.
Similarly, if https:// is specified, this function will try to use half-precision (qfloat16) floating point if the conversion to that results in no loss of precision. This is always true for infinities and NaN.
If https:// is specified, it will use integers for any floating point value that contains an actual integer.
See Also▲
See also https://(), https://(), https://()
void QCborValue::toCbor(QCborStreamWriter &writer, QCborValue::EncodingOptions opt = NoTransformation) const▲
This is an overloaded function.
Encodes this https:// object to its CBOR representation, using the options specified in opt, to the writer specified by writer. The same writer can be used by multiple QCborValues, for example, in order to encode different elements in a larger array.
This function will not fail, except if this https:// or any of the contained items, if this is a map or array, are invalid. Invalid types are not produced normally by the API, but can result from decoding errors.
By default, this function performs no transformation on the values in the https://, writing all floating point directly as double-precision (binary64) types. If the https:// option is specified, it will use single precision (binary32) for any floating point value for which there's no loss of precision in using that representation. That includes infinities and NaN values.
Similarly, if https:// is specified, this function will try to use half-precision (binary16) floating point if the conversion to that results in no loss of precision. This is always true for infinities and NaN.
If https:// is specified, it will use integers for any floating point value that contains an actual integer.
See Also▲
See also https://(), https://(), https://()
QDateTime QCborValue::toDateTime(const QDateTime &defaultValue = {}) const▲
Returns the date/time value stored in this https://, if it is of the date/time extended type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QString QCborValue::toDiagnosticNotation(QCborValue::DiagnosticNotationOptions opts = Compact) const▲
Creates the diagnostic notation equivalent of this CBOR object and returns it. The opts parameter controls the dialect of the notation. Diagnostic notation is useful in debugging, to aid the developer in understanding what value is stored in the https:// or in a CBOR stream. For that reason, the Qt API provides no support for parsing the diagnostic back into the in-memory format or CBOR stream, though the representation is unique and it would be possible.
CBOR diagnostic notation is specified by https:// of RFC 7049. It is a text representation of the CBOR stream and it is very similar to JSON, but it supports the CBOR types not found in JSON. The extended format enabled by the https:// flag is currently in some IETF drafts and its format is subject to change.
This function produces the equivalent representation of the stream that https://() would produce, without any transformation option provided there. This also implies this function may not produce a representation of the stream that was used to create the object, if it was created using https://(), as that function may have applied transformations. For a high-fidelity notation of a stream, without transformation, see the cbordump example.
See Also▲
See also https://(), https://()
double QCborValue::toDouble(double defaultValue = 0) const▲
Returns the floating point value stored in this https://, if it is of the Double type. If it is of the Integer type, this function returns the integer value converted to double. In any other case, it returns defaultValue.
See Also▲
See also https://(), https://(), https://()
qint64 QCborValue::toInteger(qint64 defaultValue = 0) const▲
Returns the integer value stored in this https://, if it is of the integer type. If it is of the Double type, this function returns the floating point value converted to integer. In any other case, it returns defaultValue.
See Also▲
See also https://(), https://(), https://()
QJsonValue QCborValue::toJsonValue() const▲
Converts this https:// object to an equivalent representation in JSON and returns it as a https://.
Please note that CBOR contains a richer and wider type set than JSON, so some information may be lost in this conversion. The following table compares CBOR types to JSON types and indicates whether information may be lost or not.
|
CBOR Type |
JSON Type |
Comments |
|---|---|---|
|
Bool |
Bool |
No data loss possible |
|
Double |
Number |
Infinities and NaN will be converted to Null; no data loss for other values |
|
Integer |
Number |
Data loss possible in the conversion if the integer is larger than 253 or smaller than -253. |
|
Null |
Null |
No data loss possible |
|
Undefined |
Null |
Type information lost |
|
String |
String |
No data loss possible |
|
Byte Array |
String |
Converted to a lossless encoding like Base64url, but the distinction between strings and byte arrays is lost |
|
Other simple types |
String |
Type information lost |
|
Array |
Array |
Conversion applies to each contained value |
|
Map |
Object |
Keys are converted to string; values converted according to this table |
|
Tags and extended types |
Special |
The tag number itself is lost and the tagged value is converted to JSON |
For information on the conversion of CBOR map keys to string, see https://().
If this https:// contains the undefined value, this function will return an undefined https:// too. Note that JSON does not support undefined values and undefined QJsonValues are an extension to the specification. They cannot be held in a https:// or https://, but can be returned from functions to indicate a failure. For all other intents and purposes, they are the same as null.
Special handling of tags and extended types▲
|
Tag |
CBOR type |
Transformation |
|---|---|---|
|
https:// |
Byte array |
Encodes the byte array as Base64url |
|
https:// |
Byte array |
Encodes the byte array as Base64 |
|
https:// |
Byte array |
Encodes the byte array as hex |
|
Url |
Url and String |
Uses https://() to normalize the encoding to the URL's fully encoded format |
|
Uuid |
Uuid and Byte array |
Uses https://() to create the string representation |
Notes▲
See Also▲
See also https://(), https://(), https://(), https://()
QRegularExpression QCborValue::toRegularExpression(const QRegularExpression &defaultValue = {}) const▲
Returns the regular expression value stored in this https://, if it is of the regular expression pattern extended type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QCborSimpleType QCborValue::toSimpleType(QCborSimpleType defaultValue = QCborSimpleType::Undefined) const▲
Returns the simple type this https:// is of, if it is a simple type. If it is not a simple type, it returns defaultValue.
The following types are simple types and this function will return the listed values:
|
https:// |
https:// |
|
https:// |
https:// |
|
https:// |
https:// |
|
https:// |
https:// |
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://(), https://(), https://()
QString QCborValue::toString(const QString &defaultValue = {}) const▲
Returns the string value stored in this https://, if it is of the string type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QUrl QCborValue::toUrl(const QUrl &defaultValue = {}) const▲
Returns the URL value stored in this https://, if it is of the URL extended type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QUuid QCborValue::toUuid(const QUuid &defaultValue = {}) const▲
Returns the UUID value stored in this https://, if it is of the UUID extended type. Otherwise, it returns defaultValue.
Note that this function performs no conversion from other types to https://.
See Also▲
See also https://(), https://(), https://()
QVariant QCborValue::toVariant() const▲
Converts this value to a native Qt type and returns the corresponding https://.
The following table lists the mapping performed between https:// and https://.
|
CBOR Type |
Qt or C++ type |
Notes |
|---|---|---|
|
Integer |
https:// |
|
|
Double |
double |
|
|
Bool |
bool |
|
|
Null |
std::nullptr_t |
|
|
Undefined |
no type (QVariant()) |
|
|
Byte array |
https:// |
|
|
String |
https:// |
|
|
Array |
https:// |
Recursively converts all values |
|
Map |
https:// |
Key types are "stringified" |
|
Other simple types |
https:// |
|
|
https:// |
https:// |
|
|
Url |
https:// |
|
|
https:// |
https:// |
|
|
Uuid |
https:// |
|
|
Other tags |
Special |
The tag is ignored and the tagged value is converted using this function |
Note that values in both CBOR Maps and Arrays are converted recursively using this function too and placed in https:// and https:// instead. You will not find https:// and https:// stored inside the QVariants.
QVariantMaps have string keys, unlike CBOR, so the conversion of a https:// to https:// will imply a step of "stringification" of the key values. See https://() for details.
See Also▲
See also https://(), https://(), https://(), https://()
QCborValue::Type QCborValue::type() const▲
Returns the type of this https://. The type can also later be retrieved by one of the "isXxx" functions.
See Also▲
See also https://(), https://(), https://(), https://(), https://(), https://(), https://(), https://(), https://(), https://(), https://, https://(), https://(), https://(), https://(), https://()
bool QCborValue::operator!=(const QCborValue &other) const▲
Compares this value and other, and returns true if contents differ, false otherwise. If each https:// contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR equality in Qt, see, https://().
See Also▲
See also https://(), https://(), https://(), https://(), https://()
bool QCborValue::operator<(const QCborValue &other) const▲
Compares this value and other, and returns true if this value should be sorted before other, false otherwise. If each https:// contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR sorting order, see https://().
See Also▲
See also https://(), https://(), https://(), https://(), https://()
QCborValue &QCborValue::operator=(const QCborValue &other)▲
Replaces the contents of this QCborObject with a copy of other.
QCborValue &QCborValue::operator=(QCborValue &&other)▲
This is an overloaded function.
Moves the contents of the other https:// object into this one and frees the resources of this one. Returns a reference to this object.
bool QCborValue::operator==(const QCborValue &other) const▲
Compares this value and other, and returns true if they hold the same contents, false otherwise. If each https:// contains an array or map, the comparison is recursive to elements contained in them.
For more information on CBOR equality in Qt, see, https://().
See Also▲
See also https://(), QCborValue::operator==(), https://(), https://(), https://()
const QCborValue QCborValue::operator[](const QString &key) const▲
If this https:// is a https://, searches elements for the value whose key matches key. If there's no key matching key in the map or if this https:// object is not a map, returns the undefined value.
This function is equivalent to:
value.toMap().value(key);See Also▲
See also https://(qint64), https://, https://(), https://()
const QCborValue QCborValue::operator[](QLatin1String key) const▲
This is an overloaded function.
If this https:// is a https://, searches elements for the value whose key matches key. If there's no key matching key in the map or if this https:// object is not a map, returns the undefined value.
This function is equivalent to:
value.toMap().value(key);See Also▲
See also https://(qint64), https://, https://(), https://()
const QCborValue QCborValue::operator[](qint64 key) const▲
This is an overloaded function.
If this https:// is a https://, searches elements for the value whose key matches key. If this is a https://, returns the element whose index is key. If there's no matching value in the array or map, or if this https:// object is not an array or map, returns the undefined value.
See Also▲
See also https://, https://, https://(), https://(), https://, https://()
QCborValueRef QCborValue::operator[](qint64 key)▲
This is an overloaded function.
Returns a QCborValueRef that can be used to read or modify the entry in this, as a map or array, with the given key. When this https:// is a https:// or, for 0 <= key < 0x10000, a https://, this function is equivalent to the matching operator[] on that map or array.
Before returning the reference: if this https:// was an array but the key is out of range, the array is first converted to a map (so that map[i] is array[i] for each index, i, with valid array[i]); otherwise, if it was not a map it will be over-written with an empty map.
See Also▲
See also https://, https://, https://(), https://(), https://, https://()
QCborValueRef QCborValue::operator[](QLatin1String key)▲
This is an overloaded function.
Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key. When this https:// is a https://, this function is equivalent to the matching operator[] on that map.
Before returning the reference: if this https:// was an array, it is first converted to a map (so that map[i] is array[i] for each index, i, with valid array[i]); otherwise, if it was not a map it will be over-written with an empty map.
See Also▲
See also https://(qint64), https://, https://(), https://()
QCborValueRef QCborValue::operator[](const QString &key)▲
Returns a QCborValueRef that can be used to read or modify the entry in this, as a map, with the given key. When this https:// is a https://, this function is equivalent to the matching operator[] on that map.
Before returning the reference: if this https:// was an array, it is first converted to a map (so that map[i] is array[i] for each index, i, with valid array[i]); otherwise, if it was not a map it will be over-written with an empty map.
See Also▲
See also https://(qint64), https://, https://(), https://()


