- Qt 6.8
- Qt Core
- <QtCborCommon>
- Qt 6.8.3 Reference Documentation

# <QtCborCommon>

The <QtCborCommon> header contains definitions common to both the streaming classes (QCborStreamReader and QCborStreamWriter) and to QCborValue. More...

Header: | `#include <QtCborCommon>`

## Types

enum class | QCborKnownTags { DateTimeString, UnixTime_t, PositiveBignum, NegativeBignum, Decimal, …, Signature }
enum class | QCborSimpleType { False, True, Null, Undefined }
enum class | QCborTag { }

## Detailed Description

See also QCborError.

## Type Documentation

### enum class QCborKnownTags

This enum contains a list of CBOR tags, known at the time of the Qt implementation. This list is not meant to be complete and contains only tags that are either backed by an RFC or specifically used by the Qt implementation.

The authoritative list is maintained by IANA in the CBOR tag registry.

Constant | Value | Description
--- | --- | ---
`QCborKnownTags::DateTimeString` | `0` | A date and time string, formatted according to RFC 3339, as refined by RFC 4287. It is the same format as Qt::ISODate and Qt::ISODateWithMs.
`QCborKnownTags::UnixTime_t` | `1` | A numerical representation of seconds elapsed since 1970-01-01T00:00Z.
`QCborKnownTags::PositiveBignum` | `2` | A positive number of arbitrary length, encoded as a byte array in network byte order. For example, the number 264 is represented by a byte array containing the byte value 0x01 followed by 8 zero bytes.
`QCborKnownTags::NegativeBignum` | `3` | A negative number of arbitrary length, encoded as the absolute value of that number, minus one. For example, a byte array containing byte value 0x02 followed by 8 zero bytes represents the number -265 - 1.
`QCborKnownTags::Decimal` | `4` | A decimal fraction, encoded as an array of two integers: the first is the exponent of the power of 10, the second the integral mantissa. The value 273.15 would be encoded as array `[-2, 27315]`.
`QCborKnownTags::Bigfloat` | `5` | Similar to Decimal, but the exponent is a power of 2 instead.
`QCborKnownTags::COSE_Encrypt0` | `16` | An `Encrypt0` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::COSE_Mac0` | `17` | A `Mac0` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::COSE_Sign1` | `18` | A `Sign1` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::ExpectedBase64url` | `21` | Indicates that the byte array should be encoded using Base64url if the stream is converted to JSON.
`QCborKnownTags::ExpectedBase64` | `22` | Indicates that the byte array should be encoded using Base64 if the stream is converted to JSON.
`QCborKnownTags::ExpectedBase16` | `23` | Indicates that the byte array should be encoded using Base16 (hex) if the stream is converted to JSON.
`QCborKnownTags::EncodedCbor` | `24` | Indicates that the byte array contains a CBOR stream.
`QCborKnownTags::Url` | `32` | Indicates that the string contains a URL.
`QCborKnownTags::Base64url` | `33` | Indicates that the string contains data encoded using Base64url.
`QCborKnownTags::Base64` | `34` | Indicates that the string contains data encoded using Base64.
`QCborKnownTags::RegularExpression` | `35` | Indicates that the string contains a Perl-Compatible Regular Expression pattern.
`QCborKnownTags::MimeMessage` | `36` | Indicates that the string contains a MIME message (according to RFC 2045).
`QCborKnownTags::Uuid` | `37` | Indicates that the byte array contains a UUID.
`QCborKnownTags::COSE_Encrypt` | `96` | An `Encrypt` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::COSE_Mac` | `97` | A `Mac` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::COSE_Sign` | `98` | A `Sign` map as specified by RFC 8152 (CBOR Object Signing and Encryption).
`QCborKnownTags::Signature` | `55799` | No change in interpretation; this tag can be used as the outermost tag in a CBOR stream as the file header.

The following tags are interpreted by QCborValue during decoding and will produce objects with extended Qt types, and it will use those tags when encoding the same extended types.

Constant | Value | Description
--- | --- | ---
`QCborKnownTags::DateTimeString` | `0` | QDateTime
`QCborKnownTags::UnixTime_t` | `1` | QDateTime (only in decoding)
`QCborKnownTags::Url` | `32` | QUrl
`QCborKnownTags::Uuid` | `37` | QUuid

Additionally, if a QCborValue containing a QByteArray is tagged using one of `ExpectedBase64url`, `ExpectedBase64` or `ExpectedBase16`, QCborValue will use the expected encoding when converting to JSON (see QCborValue::toJsonValue).

See also QCborTag, QCborStreamWriter::append(QCborTag), QCborStreamReader::isTag(), QCborStreamReader::toTag(), QCborValue::isTag(), and QCborValue::tag().

### enum class QCborSimpleType

This enum contains the possible "Simple Types" for CBOR. Simple Types range from 0 to 255 and are types that carry no further value.

The following values are currently known:

Constant | Value | Description
--- | --- | ---
`QCborSimpleType::False` | `20` | A "false" boolean.
`QCborSimpleType::True` | `21` | A "true" boolean.
`QCborSimpleType::Null` | `22` | Absence of value (null).
`QCborSimpleType::Undefined` | `23` | Missing or deleted value, usually an error.

Qt CBOR API supports encoding and decoding any Simple Type, whether one of those above or any other value.

Applications should only use further values if a corresponding specification has been published, otherwise interpretation and validation by the remote may fail. Values 24 to 31 are reserved and must not be used.

The current authoritative list is maintained by IANA in the Simple Values registry.

See also QCborStreamWriter::append(QCborSimpleType), QCborStreamReader::isSimpleType(), QCborStreamReader::toSimpleType(), QCborValue::isSimpleType(), and QCborValue::toSimpleType().

### enum class QCborTag

This enum contains no enumeration and is used only to provide type-safe access to a CBOR tag.

CBOR tags are 64-bit numbers that are attached to generic CBOR types to provide further semantic meaning. QCborTag may be constructed from an enumeration found in QCborKnownTags or directly by providing the numeric representation.

For example, the following creates a QCborValue containing a byte array tagged with a tag 2.

        QCborValue(QCborTag(2), QByteArray("\x01\0\0\0\0\0\0\0\0", 9));

See also QCborKnownTags, QCborStreamWriter::append(QCborTag), QCborStreamReader::isTag(), QCborStreamReader::toTag(), QCborValue::isTag(), and QCborValue::tag().