QCborMap Class

The QCborMap class is used to hold an associative container representable in CBOR. More...

Header: #include <QCborMap>
qmake: QT += core
Since: Qt 5.12

This class was introduced in Qt 5.12.

Note: All functions in this class are reentrant.

Public Types

class ConstIterator
class Iterator
typedef const_iterator
typedef iterator
typedef key_type
typedef mapped_type
typedef size_type
typedef value_type

Detailed Description

This class can be used to hold an associative container in CBOR, a map between a key and a value type. 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 CoAP protocol.

Unlike JSON and QVariantMap, CBOR map keys can be of any type, not just strings. For that reason, QCborMap is effectively a map between QCborValue keys to QCborValue value elements.

However, for all member functions that take a key parameter, QCborMap provides overloads that will work efficiently with integers and strings. In fact, the use of integer keys is encouraged, since they occupy fewer bytes to transmit and are simpler to encode and decode. Newer protocols designed by the IETF CoRE WG to work specifically with CBOR are known to use them.

QCborMap is not sorted, because of that, searching for keys has linear complexity (O(n)). QCborMap actually keeps the elements in the order that they were inserted, which means that it is possible to make sorted QCborMaps by carefully inserting elements in sorted order. CBOR does not require sorting, but recommends it.

QCborMap can also be converted to and from QVariantMap and QJsonObject. However, when performing the conversion, any non-string keys will be stringified using a one-way method that the conversion back to QCborMap will not undo.

See also QCborArray, QCborValue, QJsonDocument, and QVariantMap.

Member Type Documentation

typedef QCborMap::const_iterator

A synonym for QCborMap::ConstIterator

typedef QCborMap::iterator

A synonym for QCborMap::Iterator.

typedef QCborMap::key_type

The key type for this map. Since QCborMap keys can be any CBOR type, this is a QCborValue.

typedef QCborMap::mapped_type

The type that is mapped to (the value), that is, a QCborValue.

typedef QCborMap::size_type

The type that QCborMap uses for sizes.

typedef QCborMap::value_type

The value that is stored in this container: a pair of QCborValues