#[repr(C)]
pub struct QCborStreamReader { /* private fields */ }
Expand description

The QCborStreamReader class is a simple CBOR stream decoder, operating on either a QByteArray or QIODevice.

C++ class: QCborStreamReader.

C++ documentation:

The QCborStreamReader class is a simple CBOR stream decoder, operating on either a QByteArray or QIODevice.

This class can be used to decode a stream of CBOR content directly from either a QByteArray or a QIODevice. CBOR is the Concise Binary Object Representation, a very compact form of binary data encoding that is compatible with 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.

QCborStreamReader provides a StAX-like API, similar to that of QXmlStreamReader. Using it requires a bit of knowledge of CBOR encoding. For a simpler API, see QCborValue and especially the decoding function QCborValue::fromCbor().

Typically, one creates a QCborStreamReader by passing the source QByteArray or QIODevice as a parameter to the constructor, then pop elements off the stream if there were no errors in decoding. There are three kinds of CBOR types:

KindTypesBehavior
Fixed-widthIntegers, Tags, Simple types, Floating pointValue is pre-parsed by QCborStreamReader, so accessor functions are const. Must call next() to advance.
StringsByte arrays, Text stringsLength (if known) is pre-parsed, but the string itself is not. The accessor functions are not const and may allocate memory. Once called, the accessor functions automatically advance to the next element.
ContainersArrays, MapsLength (if known) is pre-parsed. To access the elements, you must call enterContainer(), read all elements, then call leaveContainer(). That function advances to the next element.

So a processor function typically looks like this:

void handleStream(QCborStreamReader &reader) { switch (reader.type()) case QCborStreamReader::UnsignedInteger: case QCborStreamReader::NegativeInteger: case QCborStreamReader::SimpleType: case QCborStreamReader::Float16: case QCborStreamReader::Float: case QCborStreamReader::Double: handleFixedWidth(reader); reader.next(); break; case QCborStreamReader::ByteArray: case QCborStreamReader::String: handleString(reader); break; case QCborStreamReader::Array: case QCborStreamReader::Map: reader.enterContainer(); while (reader.lastError() == QCborError::NoError) handleStream(reader); if (reader.lastError() == QCborError::NoError) reader.leaveContainer(); } }

Implementations§

source§

impl QCborStreamReader

source

pub unsafe fn add_data_q_byte_array(&self, data: impl CastInto<Ref<QByteArray>>)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Adds data to the CBOR stream and reparses the current element. This function is useful if the end of the data was previously reached while processing the stream, but now more data is available.

Calls C++ function: void QCborStreamReader::addData(const QByteArray& data).

C++ documentation:

Adds data to the CBOR stream and reparses the current element. This function is useful if the end of the data was previously reached while processing the stream, but now more data is available.

source

pub unsafe fn add_data_char_longlong( &self, data: *const c_char, len: c_longlong )

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: void QCborStreamReader::addData(const char* data, long long len).

C++ documentation:

This is an overloaded function.

Adds len bytes of data starting at data to the CBOR stream and reparses the current element. This function is useful if the end of the data was previously reached while processing the stream, but now more data is available.

source

pub unsafe fn add_data_u8_longlong(&self, data: *const u8, len: c_longlong)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: void QCborStreamReader::addData(const quint8* data, long long len).

C++ documentation:

This is an overloaded function.

Adds len bytes of data starting at data to the CBOR stream and reparses the current element. This function is useful if the end of the data was previously reached while processing the stream, but now more data is available.

source

pub unsafe fn clear(&self)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Clears the decoder state and resets the input source data to an empty byte array. After this function is called, QCborStreamReader will be indicating an error parsing.

Calls C++ function: void QCborStreamReader::clear().

C++ documentation:

Clears the decoder state and resets the input source data to an empty byte array. After this function is called, QCborStreamReader will be indicating an error parsing.

Call addData() to add more data to be parsed.

See also reset() and setDevice().

source

pub unsafe fn container_depth(&self) -> c_int

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the number of containers that this stream has entered with enterContainer() but not yet left.

Calls C++ function: int QCborStreamReader::containerDepth() const.

C++ documentation:

Returns the number of containers that this stream has entered with enterContainer() but not yet left.

See also enterContainer() and leaveContainer().

source

pub unsafe fn current_offset(&self) -> i64

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the offset in the input stream of the item currently being decoded. The current offset is the number of decoded bytes so far only if the source data is a QByteArray or it is a QIODevice that was positioned at its beginning when decoding started.

Calls C++ function: qint64 QCborStreamReader::currentOffset() const.

C++ documentation:

Returns the offset in the input stream of the item currently being decoded. The current offset is the number of decoded bytes so far only if the source data is a QByteArray or it is a QIODevice that was positioned at its beginning when decoding started.

See also reset(), clear(), and device().

source

pub unsafe fn current_string_chunk_size(&self) -> c_longlong

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the size of the current text or byte string chunk. If the CBOR stream contains a non-chunked string (that is, if isLengthKnown() returns true), this function returns the size of the entire string, the same as length().

Calls C++ function: long long QCborStreamReader::currentStringChunkSize() const.

C++ documentation:

Returns the size of the current text or byte string chunk. If the CBOR stream contains a non-chunked string (that is, if isLengthKnown() returns true), this function returns the size of the entire string, the same as length().

This function is useful to pre-allocate the buffer whose pointer can be passed to readStringChunk() later.

See also readString(), readByteArray(), and readStringChunk().

source

pub unsafe fn device(&self) -> QPtr<QIODevice>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the QIODevice that was set with either setDevice() or the QCborStreamReader constructor. If this object was reading from a QByteArray, this function returns nullptr instead.

Calls C++ function: QIODevice* QCborStreamReader::device() const.

C++ documentation:

Returns the QIODevice that was set with either setDevice() or the QCborStreamReader constructor. If this object was reading from a QByteArray, this function returns nullptr instead.

See also setDevice().

source

pub unsafe fn enter_container(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Enters the array or map that is the current item and prepares for iterating the elements contained in the container. Returns true if entering the container succeeded, false otherwise (usually, a parsing error). Each call to enterContainer() must be paired with a call to leaveContainer().

Calls C++ function: bool QCborStreamReader::enterContainer().

C++ documentation:

Enters the array or map that is the current item and prepares for iterating the elements contained in the container. Returns true if entering the container succeeded, false otherwise (usually, a parsing error). Each call to enterContainer() must be paired with a call to leaveContainer().

This function may only be called if the current item is an array or a map (that is, if isArray(), isMap() or isContainer() is true). Calling it in any other condition is an error.

See also leaveContainer(), isContainer(), isArray(), and isMap().

source

pub unsafe fn has_next(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if there are more items to be decoded in the current container or false of we've reached its end. If we're parsing the root element, hasNext() returning false indicates the parsing is complete; otherwise, if the container depth is non-zero, then the outer code needs to call leaveContainer().

Calls C++ function: bool QCborStreamReader::hasNext() const.

C++ documentation:

Returns true if there are more items to be decoded in the current container or false of we’ve reached its end. If we’re parsing the root element, hasNext() returning false indicates the parsing is complete; otherwise, if the container depth is non-zero, then the outer code needs to call leaveContainer().

See also parentContainerType(), containerDepth(), and leaveContainer().

source

pub unsafe fn is_array(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is an array (that is, if type() returns QCborStreamReader::Array). If this function returns true, you may call enterContainer() to begin parsing that container.

Calls C++ function: bool QCborStreamReader::isArray() const.

C++ documentation:

Returns true if the type of the current element is an array (that is, if type() returns QCborStreamReader::Array). If this function returns true, you may call enterContainer() to begin parsing that container.

When the current element is an array, you may also call isLengthKnown() to find out if the array's size is explicit in the CBOR stream. If it is, that size can be obtained by calling length().

The following example pre-allocates a QVariantList given the array's size for more efficient decoding:

QVariantList populateFromCbor(QCborStreamReader &reader) { QVariantList list; if (reader.isLengthKnown()) list.reserve(reader.length());

reader.enterContainer(); while (reader.lastError() == QCborError::NoError && reader.hasNext()) list.append(readOneElement(reader)); if (reader.lastError() == QCborError::NoError) reader.leaveContainer(); }

Note: The code above does not validate that the length is a sensible value. If the input stream reports that the length is 1 billion elements, the above function will try to allocate some 16 GB or more of RAM, which can lead to a crash.

See also type(), isMap(), isLengthKnown(), length(), enterContainer(), and leaveContainer().

source

pub unsafe fn is_bool(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is a boolean value (true or false), false if it is anything else. If this function returns true, you may call toBool() to retrieve the value of the boolean. You may also call toSimpleType() and compare to either QCborSimpleValue::True or QCborSimpleValue::False.

Calls C++ function: bool QCborStreamReader::isBool() const.

C++ documentation:

Returns true if the current element is a boolean value (true or false), false if it is anything else. If this function returns true, you may call toBool() to retrieve the value of the boolean. You may also call toSimpleType() and compare to either QCborSimpleValue::True or QCborSimpleValue::False.

See also type(), isFalse(), isTrue(), toBool(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_byte_array(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is a byte array (that is, if type() returns QCborStreamReader::ByteArray). If this function returns true, you may call readByteArray() to read that data.

Calls C++ function: bool QCborStreamReader::isByteArray() const.

C++ documentation:

Returns true if the type of the current element is a byte array (that is, if type() returns QCborStreamReader::ByteArray). If this function returns true, you may call readByteArray() to read that data.

See also type(), readByteArray(), and isString().

source

pub unsafe fn is_container(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is a container (that is, an array or a map), false if it is anything else. If the current element is a container, the isLengthKnown() function may be used to find out if the container's size is explicit in the stream and, if so, length() can be used to get that size.

Calls C++ function: bool QCborStreamReader::isContainer() const.

C++ documentation:

Returns true if the current element is a container (that is, an array or a map), false if it is anything else. If the current element is a container, the isLengthKnown() function may be used to find out if the container’s size is explicit in the stream and, if so, length() can be used to get that size.

More importantly, for a container, the enterContainer() function is available to begin iterating through the elements contained therein.

See also type(), isArray(), isMap(), isLengthKnown(), length(), enterContainer(), leaveContainer(), and containerDepth().

source

pub unsafe fn is_double(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is an IEEE 754 double-precision floating point (that is, if type() returns QCborStreamReader::Double). If this function returns true, you may call toDouble() to read that data.

Calls C++ function: bool QCborStreamReader::isDouble() const.

C++ documentation:

Returns true if the type of the current element is an IEEE 754 double-precision floating point (that is, if type() returns QCborStreamReader::Double). If this function returns true, you may call toDouble() to read that data.

See also type(), toDouble(), isFloat16(), and isFloat().

source

pub unsafe fn is_false(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is the false value, false if it is anything else.

Calls C++ function: bool QCborStreamReader::isFalse() const.

C++ documentation:

Returns true if the current element is the false value, false if it is anything else.

See also type(), isTrue(), isBool(), toBool(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_float(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is an IEEE 754 single-precision floating point (that is, if type() returns QCborStreamReader::Float). If this function returns true, you may call toFloat() to read that data.

Calls C++ function: bool QCborStreamReader::isFloat() const.

C++ documentation:

Returns true if the type of the current element is an IEEE 754 single-precision floating point (that is, if type() returns QCborStreamReader::Float). If this function returns true, you may call toFloat() to read that data.

See also type(), toFloat(), isFloat16(), and isDouble().

source

pub unsafe fn is_float16(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is an IEEE 754 half-precision floating point (that is, if type() returns QCborStreamReader::Float16). If this function returns true, you may call toFloat16() to read that data.

Calls C++ function: bool QCborStreamReader::isFloat16() const.

C++ documentation:

Returns true if the type of the current element is an IEEE 754 half-precision floating point (that is, if type() returns QCborStreamReader::Float16). If this function returns true, you may call toFloat16() to read that data.

See also type(), toFloat16(), isFloat(), and isDouble().

source

pub unsafe fn is_integer(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is either an unsigned integer or a negative one (that is, if type() returns QCborStreamReader::UnsignedInteger or QCborStreamReader::NegativeInteger). If this function returns true, you may call toInteger() to read that value.

Calls C++ function: bool QCborStreamReader::isInteger() const.

C++ documentation:

Returns true if the type of the current element is either an unsigned integer or a negative one (that is, if type() returns QCborStreamReader::UnsignedInteger or QCborStreamReader::NegativeInteger). If this function returns true, you may call toInteger() to read that value.

See also type(), toInteger(), toUnsignedInteger(), toNegativeInteger(), isUnsignedInteger(), and isNegativeInteger().

source

pub unsafe fn is_invalid(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is invalid, false otherwise. The current element may be invalid if there was a decoding error or we've just parsed the last element in an array or map.

Calls C++ function: bool QCborStreamReader::isInvalid() const.

C++ documentation:

Returns true if the current element is invalid, false otherwise. The current element may be invalid if there was a decoding error or we’ve just parsed the last element in an array or map.

Note: This function is not to be confused with isNull(). Null is a normal CBOR type that must be handled by the application.

See also type() and isValid().

source

pub unsafe fn is_length_known(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the length of the current array, map, byte array or string is known (explicit in the CBOR stream), false otherwise. This function should only be called if the element is one of those.

Calls C++ function: bool QCborStreamReader::isLengthKnown() const.

C++ documentation:

Returns true if the length of the current array, map, byte array or string is known (explicit in the CBOR stream), false otherwise. This function should only be called if the element is one of those.

If the length is known, it may be obtained by calling length().

If the length of a map or an array is not known, it is implied by the number of elements present in the stream. QCborStreamReader has no API to calculate the length in that condition.

Strings and byte arrays may also have indeterminate length (that is, they may be transmitted in multiple chunks). Those cannot currently be created with QCborStreamWriter, but they could be with other encoders, so QCborStreamReader supports them.

See also length(), QCborStreamWriter::startArray(), and QCborStreamWriter::startMap().

source

pub unsafe fn is_map(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is a map (that is, if type() returns QCborStreamReader::Map). If this function returns true, you may call enterContainer() to begin parsing that container.

Calls C++ function: bool QCborStreamReader::isMap() const.

C++ documentation:

Returns true if the type of the current element is a map (that is, if type() returns QCborStreamReader::Map). If this function returns true, you may call enterContainer() to begin parsing that container.

When the current element is a map, you may also call isLengthKnown() to find out if the map's size is explicit in the CBOR stream. If it is, that size can be obtained by calling length().

The following example pre-allocates a QVariantMap given the map's size for more efficient decoding:

QVariantMap populateFromCbor(QCborStreamReader &reader) { QVariantMap map; if (reader.isLengthKnown()) map.reserve(reader.length());

reader.enterContainer(); while (reader.lastError() == QCborError::NoError && reader.hasNext()) { QString key = readElementAsString(reader); map.insert(key, readOneElement(reader)); } if (reader.lastError() == QCborError::NoError) reader.leaveContainer(); }

The example above uses a function called readElementAsString to read the map's keys and obtain a string. That is because CBOR maps may contain any type as keys, not just strings. User code needs to either perform this conversion, reject non-string keys, or instead use a different container besides QVariantMap and QVariantHash. For example, if the map is expected to contain integer keys, which is recommended as it reduces stream size and parsing, the correct container would be \l{QMap}<int, QVariant> or \l{QHash}<int, QVariant>.

Note: The code above does not validate that the length is a sensible value. If the input stream reports that the length is 1 billion elements, the above function will try to allocate some 24 GB or more of RAM, which can lead to a crash.

See also type(), isArray(), isLengthKnown(), length(), enterContainer(), and leaveContainer().

source

pub unsafe fn is_negative_integer(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is a negative integer (that is if type() returns QCborStreamReader::NegativeInteger). If this function returns true, you may call toNegativeInteger() or toInteger() to read that value.

Calls C++ function: bool QCborStreamReader::isNegativeInteger() const.

C++ documentation:

Returns true if the type of the current element is a negative integer (that is if type() returns QCborStreamReader::NegativeInteger). If this function returns true, you may call toNegativeInteger() or toInteger() to read that value.

See also type(), toNegativeInteger(), toInteger(), isInteger(), and isUnsignedInteger().

source

pub unsafe fn is_null(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is the null value, false if it is anything else. Null values may be used to indicate the absence of some optional data.

Calls C++ function: bool QCborStreamReader::isNull() const.

C++ documentation:

Returns true if the current element is the null value, false if it is anything else. Null values may be used to indicate the absence of some optional data.

Note: This function is not the opposite of isValid(). A Null value is a valid CBOR value.

See also type(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_simple_type_0a(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is any CBOR simple type, including a boolean value (true and false) as well as null and undefined. To find out which simple type this is, call toSimpleType(). Alternatively, to test for one specific simple type, call the overload that takes a QCborSimpleType parameter.

Calls C++ function: bool QCborStreamReader::isSimpleType() const.

C++ documentation:

Returns true if the type of the current element is any CBOR simple type, including a boolean value (true and false) as well as null and undefined. To find out which simple type this is, call toSimpleType(). Alternatively, to test for one specific simple type, call the overload that takes a QCborSimpleType parameter.

CBOR simple types are types that do not carry extra value. There are 255 possibilities, but there are currently only four values that have defined meaning. Code is not expected to cope with unknown simple types and may simply discard the stream as invalid if it finds an unknown one.

See also QCborSimpleType, type(), isSimpleType(QCborSimpleType), and toSimpleType().

source

pub unsafe fn is_simple_type_1a(&self, st: QCborSimpleType) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is the simple type st, false otherwise. If this function returns true, then toSimpleType() will return st.

Calls C++ function: bool QCborStreamReader::isSimpleType(QCborSimpleType st) const.

C++ documentation:

Returns true if the type of the current element is the simple type st, false otherwise. If this function returns true, then toSimpleType() will return st.

CBOR simple types are types that do not carry extra value. There are 255 possibilities, but there are currently only four values that have defined meaning. Code is not expected to cope with unknown simple types and may simply discard the stream as invalid if it finds an unknown one.

See also QCborSimpleType, type(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_string(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is a text string (that is, if type() returns QCborStreamReader::String). If this function returns true, you may call readString() to read that data.

Calls C++ function: bool QCborStreamReader::isString() const.

C++ documentation:

Returns true if the type of the current element is a text string (that is, if type() returns QCborStreamReader::String). If this function returns true, you may call readString() to read that data.

See also type(), readString(), and isByteArray().

source

pub unsafe fn is_tag(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is a CBOR tag (that is, if type() returns QCborStreamReader::Tag). If this function returns true, you may call toTag() to read that data.

Calls C++ function: bool QCborStreamReader::isTag() const.

C++ documentation:

Returns true if the type of the current element is a CBOR tag (that is, if type() returns QCborStreamReader::Tag). If this function returns true, you may call toTag() to read that data.

See also type() and toTag().

source

pub unsafe fn is_true(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is the true value, false if it is anything else.

Calls C++ function: bool QCborStreamReader::isTrue() const.

C++ documentation:

Returns true if the current element is the true value, false if it is anything else.

See also type(), isFalse(), isBool(), toBool(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_undefined(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is the undefined value, false if it is anything else. Undefined values may be encoded to indicate that some conversion failed or was not possible when creating the stream. QCborStreamReader never performs any replacement and this function will only return true if the stream contains an explicit undefined value.

Calls C++ function: bool QCborStreamReader::isUndefined() const.

C++ documentation:

Returns true if the current element is the undefined value, false if it is anything else. Undefined values may be encoded to indicate that some conversion failed or was not possible when creating the stream. QCborStreamReader never performs any replacement and this function will only return true if the stream contains an explicit undefined value.

See also type(), isSimpleType(), and toSimpleType().

source

pub unsafe fn is_unsigned_integer(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the type of the current element is an unsigned integer (that is if type() returns QCborStreamReader::UnsignedInteger). If this function returns true, you may call toUnsignedInteger() or toInteger() to read that value.

Calls C++ function: bool QCborStreamReader::isUnsignedInteger() const.

C++ documentation:

Returns true if the type of the current element is an unsigned integer (that is if type() returns QCborStreamReader::UnsignedInteger). If this function returns true, you may call toUnsignedInteger() or toInteger() to read that value.

See also type(), toUnsignedInteger(), toInteger(), isInteger(), and isNegativeInteger().

source

pub unsafe fn is_valid(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns true if the current element is valid, false otherwise. The current element may be invalid if there was a decoding error or we've just parsed the last element in an array or map.

Calls C++ function: bool QCborStreamReader::isValid() const.

C++ documentation:

Returns true if the current element is valid, false otherwise. The current element may be invalid if there was a decoding error or we’ve just parsed the last element in an array or map.

Note: This function is not the opposite of isNull(). Null is a normal CBOR type that must be handled by the application.

See also type() and isInvalid().

source

pub unsafe fn last_error(&self) -> CppBox<QCborError>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the last error in decoding the stream, if any. If no error was encountered, this returns an QCborError::NoError.

Calls C++ function: QCborError QCborStreamReader::lastError().

C++ documentation:

Returns the last error in decoding the stream, if any. If no error was encountered, this returns an QCborError::NoError.

See also isValid().

source

pub unsafe fn leave_container(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Leaves the array or map whose items were being processed and positions the decoder at the next item after the end of the container. Returns true if leaving the container succeeded, false otherwise (usually, a parsing error). Each call to enterContainer() must be paired with a call to leaveContainer().

Calls C++ function: bool QCborStreamReader::leaveContainer().

C++ documentation:

Leaves the array or map whose items were being processed and positions the decoder at the next item after the end of the container. Returns true if leaving the container succeeded, false otherwise (usually, a parsing error). Each call to enterContainer() must be paired with a call to leaveContainer().

This function may only be called if hasNext() has returned false and containerDepth() is not zero. Calling it in any other condition is an error.

See also enterContainer(), parentContainerType(), and containerDepth().

source

pub unsafe fn length(&self) -> u64

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the length of the string or byte array, or the number of items in an array or the number, of item pairs in a map, if known. This function must not be called if the length is unknown (that is, if isLengthKnown() returned false). It is an error to do that and it will cause QCborStreamReader to stop parsing the input stream.

Calls C++ function: quint64 QCborStreamReader::length() const.

C++ documentation:

Returns the length of the string or byte array, or the number of items in an array or the number, of item pairs in a map, if known. This function must not be called if the length is unknown (that is, if isLengthKnown() returned false). It is an error to do that and it will cause QCborStreamReader to stop parsing the input stream.

See also isLengthKnown(), QCborStreamWriter::startArray(), and QCborStreamWriter::startMap().

source

pub unsafe fn new() -> CppBox<QCborStreamReader>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Creates a QCborStreamReader object with no source data. After construction, QCborStreamReader will report an error parsing.

Calls C++ function: [constructor] void QCborStreamReader::QCborStreamReader().

C++ documentation:

Creates a QCborStreamReader object with no source data. After construction, QCborStreamReader will report an error parsing.

You can add more data by calling addData() or by setting a different source device using setDevice().

See also addData() and isValid().

source

pub unsafe fn from_char_longlong( data: *const c_char, len: c_longlong ) -> CppBox<QCborStreamReader>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: [constructor] void QCborStreamReader::QCborStreamReader(const char* data, long long len).

C++ documentation:

This is an overloaded function.

Creates a QCborStreamReader object with len bytes of data starting at data. The pointer must remain valid until QCborStreamReader is destroyed.

source

pub unsafe fn from_u8_longlong( data: *const u8, len: c_longlong ) -> CppBox<QCborStreamReader>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: [constructor] void QCborStreamReader::QCborStreamReader(const quint8* data, long long len).

C++ documentation:

This is an overloaded function.

Creates a QCborStreamReader object with len bytes of data starting at data. The pointer must remain valid until QCborStreamReader is destroyed.

source

pub unsafe fn from_q_byte_array( data: impl CastInto<Ref<QByteArray>> ) -> CppBox<QCborStreamReader>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: [constructor] void QCborStreamReader::QCborStreamReader(const QByteArray& data).

C++ documentation:

This is an overloaded function.

Creates a QCborStreamReader object that will parse the CBOR stream found in data.

source

pub unsafe fn from_q_io_device( device: impl CastInto<Ptr<QIODevice>> ) -> CppBox<QCborStreamReader>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

This is an overloaded function.

Calls C++ function: [constructor] void QCborStreamReader::QCborStreamReader(QIODevice* device).

C++ documentation:

This is an overloaded function.

Creates a QCborStreamReader object that will parse the CBOR stream found by reading from device. QCborStreamReader does not take ownership of device, so it must remain valid until this oject is destroyed.

source

pub unsafe fn next_1a(&self, max_recursion: c_int) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Advance the CBOR stream decoding one element. You should usually call this function when parsing fixed-width basic elements (that is, integers, simple values, tags and floating point values). But this function can be called when the current item is a string, array or map too and it will skip over that entire element, including all contained elements.

Calls C++ function: bool QCborStreamReader::next(int maxRecursion = …).

C++ documentation:

Advance the CBOR stream decoding one element. You should usually call this function when parsing fixed-width basic elements (that is, integers, simple values, tags and floating point values). But this function can be called when the current item is a string, array or map too and it will skip over that entire element, including all contained elements.

This function returns true if advancing was successful, false otherwise. It may fail if the stream is corrupt, incomplete or if the nesting level of arrays and maps exceeds maxRecursion. Calling this function when hasNext() has returned false is also an error. If this function returns false, lastError() will return the error code detailing what the failure was.

See also lastError(), isValid(), and hasNext().

source

pub unsafe fn next_0a(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Advance the CBOR stream decoding one element. You should usually call this function when parsing fixed-width basic elements (that is, integers, simple values, tags and floating point values). But this function can be called when the current item is a string, array or map too and it will skip over that entire element, including all contained elements.

Calls C++ function: bool QCborStreamReader::next().

C++ documentation:

Advance the CBOR stream decoding one element. You should usually call this function when parsing fixed-width basic elements (that is, integers, simple values, tags and floating point values). But this function can be called when the current item is a string, array or map too and it will skip over that entire element, including all contained elements.

This function returns true if advancing was successful, false otherwise. It may fail if the stream is corrupt, incomplete or if the nesting level of arrays and maps exceeds maxRecursion. Calling this function when hasNext() has returned false is also an error. If this function returns false, lastError() will return the error code detailing what the failure was.

See also lastError(), isValid(), and hasNext().

source

pub unsafe fn parent_container_type(&self) -> Type

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns either QCborStreamReader::Array or QCborStreamReader::Map, indicating whether the container that contains the current item was an array or map, respectively. If we're currently parsing the root element, this function returns QCborStreamReader::Invalid.

Calls C++ function: QCborStreamReader::Type QCborStreamReader::parentContainerType() const.

C++ documentation:

Returns either QCborStreamReader::Array or QCborStreamReader::Map, indicating whether the container that contains the current item was an array or map, respectively. If we’re currently parsing the root element, this function returns QCborStreamReader::Invalid.

See also containerDepth() and enterContainer().

source

pub unsafe fn read_byte_array(&self) -> CppBox<StringResultOfQByteArray>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Decodes one byte array chunk from the CBOR string and returns it. This function is used for both regular and chunked contents, so the caller must always loop around calling this function, even if isLengthKnown() has is true. The typical use of this function is as follows:

Calls C++ function: QCborStreamReader::StringResult<QByteArray> QCborStreamReader::readByteArray().

C++ documentation:

Decodes one byte array chunk from the CBOR string and returns it. This function is used for both regular and chunked contents, so the caller must always loop around calling this function, even if isLengthKnown() has is true. The typical use of this function is as follows:


     QBytearray decodeBytearray(QCborStreamReader &reader)
     {
         QBytearray result;
         auto r = reader.readBytearray();
         while (r.code == QCborStreamReader::Ok) {
             result += r.data;
             r = reader.readByteArray();
         }

         if (r.code == QCborStreamReader::Error) {
             // handle error condition
             result.clear();
         }
         return result;
     }

This function does not perform any type conversions, including from integers or from strings. Therefore, it may only be called if isByteArray() is true; calling it in any other condition is an error.

See also readString(), isByteArray(), and readStringChunk().

source

pub unsafe fn read_string(&self) -> CppBox<StringResultOfQString>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Decodes one string chunk from the CBOR string and returns it. This function is used for both regular and chunked string contents, so the caller must always loop around calling this function, even if isLengthKnown() has is true. The typical use of this function is as follows:

Calls C++ function: QCborStreamReader::StringResult<QString> QCborStreamReader::readString().

C++ documentation:

Decodes one string chunk from the CBOR string and returns it. This function is used for both regular and chunked string contents, so the caller must always loop around calling this function, even if isLengthKnown() has is true. The typical use of this function is as follows:


     QString decodeString(QCborStreamReader &reader)
     {
         QString result;
         auto r = reader.readString();
         while (r.code == QCborStreamReader::Ok) {
             result += r.data;
             r = reader.readString();
         }

         if (r.code == QCborStreamReader::Error) {
             // handle error condition
             result.clear();
         }
         return result;
     }

This function does not perform any type conversions, including from integers or from byte arrays. Therefore, it may only be called if isString() returned true; calling it in any other condition is an error.

See also readByteArray(), isString(), and readStringChunk().

source

pub unsafe fn read_string_chunk( &self, ptr: *mut c_char, maxlen: c_longlong ) -> CppBox<StringResultOfLonglong>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Reads the current string chunk into the buffer pointed to by ptr, whose size is maxlen. This function returns a StringResult object, with the number of bytes copied into ptr saved in the \l StringResult::data member. The \l StringResult::status member indicates whether there was an error reading the string, whether data was copied or whether this was the last chunk.

Calls C++ function: QCborStreamReader::StringResult<long long> QCborStreamReader::readStringChunk(char* ptr, long long maxlen).

C++ documentation:

Reads the current string chunk into the buffer pointed to by ptr, whose size is maxlen. This function returns a StringResult object, with the number of bytes copied into ptr saved in the \l StringResult::data member. The \l StringResult::status member indicates whether there was an error reading the string, whether data was copied or whether this was the last chunk.

This function can be called for both String and ByteArray types. For the latter, this function will read the same data that readByteArray() would have returned. For strings, it returns the UTF-8 equivalent of the QString that would have been returned.

This function is usually used alongside currentStringChunkSize() in a loop. For example:

QCborStreamReader<qsizetype> result; do { qsizetype size = reader.currentStringChunkSize(); qsizetype oldsize = buffer.size(); buffer.resize(oldsize + size); result = reader.readStringChunk(buffer.data() + oldsize, size); } while (result.status() == QCborStreamReader::Ok);

Unlike readByteArray() and readString(), this function is not limited by implementation limits of QByteArray and QString.

Note: This function does not perform verification that the UTF-8 contents are properly formatted. That means this function does not produce the QCborError::InvalidUtf8String error, even when readString() does.

See also currentStringChunkSize(), readString(), readByteArray(), isString(), and isByteArray().

source

pub unsafe fn reparse(&self)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Reparses the current element. This function must be called when more data becomes available in the source QIODevice after parsing failed due to reaching the end of the input data before the end of the CBOR stream.

Calls C++ function: void QCborStreamReader::reparse().

C++ documentation:

Reparses the current element. This function must be called when more data becomes available in the source QIODevice after parsing failed due to reaching the end of the input data before the end of the CBOR stream.

When reading from QByteArray(), the addData() function automatically calls this function. Calling it when the reading had not failed is a no-op.

source

pub unsafe fn reset(&self)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Resets the source back to the beginning and clears the decoder state. If the source data was a QByteArray, QCborStreamReader will restart from the beginning of the array.

Calls C++ function: void QCborStreamReader::reset().

C++ documentation:

Resets the source back to the beginning and clears the decoder state. If the source data was a QByteArray, QCborStreamReader will restart from the beginning of the array.

If the source data is a QIODevice, this function will call QIODevice::reset(), which will seek to byte position 0. If the CBOR stream is not found at the beginning of the device (e.g., beginning of a file), then this function will likely do the wrong thing. Instead, position the QIODevice to the right offset and call setDevice().

See also clear() and setDevice().

source

pub unsafe fn set_device(&self, device: impl CastInto<Ptr<QIODevice>>)

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Sets the source of data to device, resetting the decoder to its initial state.

Calls C++ function: void QCborStreamReader::setDevice(QIODevice* device).

C++ documentation:

Sets the source of data to device, resetting the decoder to its initial state.

See also device().

source

pub unsafe fn static_meta_object() -> Ref<QMetaObject>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns a reference to the staticMetaObject field.

source

pub unsafe fn to_bool(&self) -> bool

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the boolean value of the current element.

Calls C++ function: bool QCborStreamReader::toBool() const.

C++ documentation:

Returns the boolean value of the current element.

This function does not perform any type conversions, including from integer. Therefore, it may only be called if isTrue(), isFalse() or isBool() returned true; calling it in any other condition is an error.

See also isBool(), isTrue(), isFalse(), and toInteger().

source

pub unsafe fn to_double(&self) -> c_double

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the 64-bit double-precision floating point value of the current element.

Calls C++ function: double QCborStreamReader::toDouble() const.

C++ documentation:

Returns the 64-bit double-precision floating point value of the current element.

This function does not perform any type conversions, including from other floating point types or from integer values. Therefore, it may only be called if isDouble() is true; calling it in any other condition is an error.

See also isDouble(), toFloat16(), and toFloat().

source

pub unsafe fn to_float(&self) -> c_float

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the 32-bit single-precision floating point value of the current element.

Calls C++ function: float QCborStreamReader::toFloat() const.

C++ documentation:

Returns the 32-bit single-precision floating point value of the current element.

This function does not perform any type conversions, including from other floating point types or from integer values. Therefore, it may only be called if isFloat() is true; calling it in any other condition is an error.

See also isFloat(), toFloat16(), and toDouble().

source

pub unsafe fn to_float16(&self) -> CppBox<Qfloat16>

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the 16-bit half-precision floating point value of the current element.

Calls C++ function: qfloat16 QCborStreamReader::toFloat16() const.

C++ documentation:

Returns the 16-bit half-precision floating point value of the current element.

This function does not perform any type conversions, including from other floating point types or from integer values. Therefore, it may only be called if isFloat16() is true; calling it in any other condition is an error.

See also isFloat16(), toFloat(), and toDouble().

source

pub unsafe fn to_integer(&self) -> i64

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the integer value of the current element, be it negative, positive or zero. If the value is larger than 263 - 1 or smaller than -263, the returned value will overflow and will have an incorrect sign. If handling those values is required, use toUnsignedInteger() or toNegativeInteger() instead.

Calls C++ function: qint64 QCborStreamReader::toInteger() const.

C++ documentation:

Returns the integer value of the current element, be it negative, positive or zero. If the value is larger than 263 - 1 or smaller than -263, the returned value will overflow and will have an incorrect sign. If handling those values is required, use toUnsignedInteger() or toNegativeInteger() instead.

This function does not perform any type conversions, including from boolean or CBOR tag. Therefore, it may only be called if isInteger() is true; calling it in any other condition is an error.

See also isInteger(), toUnsignedInteger(), and toNegativeInteger().

source

pub unsafe fn to_negative_integer(&self) -> QCborNegativeInteger

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the negative integer value of the current element. QCborNegativeValue is a 64-bit unsigned integer containing the absolute value of the negative number that was stored in the CBOR stream. Additionally, QCborNegativeValue(0) represents the number -264.

Calls C++ function: QCborNegativeInteger QCborStreamReader::toNegativeInteger() const.

C++ documentation:

Returns the negative integer value of the current element. QCborNegativeValue is a 64-bit unsigned integer containing the absolute value of the negative number that was stored in the CBOR stream. Additionally, QCborNegativeValue(0) represents the number -264.

This function does not perform any type conversions, including from boolean or CBOR tag. Therefore, it may only be called if isNegativeInteger() is true; calling it in any other condition is an error.

This function may be used to obtain numbers beyond the range of the return type of toInteger(). However, use of negative numbers smaller than -263 is extremely discouraged.

See also type(), toInteger(), isNegativeInteger(), and isUnsignedInteger().

source

pub unsafe fn to_simple_type(&self) -> QCborSimpleType

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns value of the current simple type.

Calls C++ function: QCborSimpleType QCborStreamReader::toSimpleType() const.

C++ documentation:

Returns value of the current simple type.

This function does not perform any type conversions, including from integer. Therefore, it may only be called if isSimpleType() is true; calling it in any other condition is an error.

See also isSimpleType(), isTrue(), isFalse(), isBool(), isNull(), and isUndefined().

source

pub unsafe fn to_tag(&self) -> QCborTag

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the tag value of the current element.

Calls C++ function: QCborTag QCborStreamReader::toTag() const.

C++ documentation:

Returns the tag value of the current element.

This function does not perform any type conversions, including from integer. Therefore, it may only be called if isTag() is true; calling it in any other condition is an error.

Tags are 64-bit numbers attached to generic CBOR types that give them further meaning. For a list of known tags, see the QCborKnownTags enumeration.

See also isTag(), toInteger(), and QCborKnownTags.

source

pub unsafe fn to_unsigned_integer(&self) -> u64

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the unsigned integer value of the current element.

Calls C++ function: quint64 QCborStreamReader::toUnsignedInteger() const.

C++ documentation:

Returns the unsigned integer value of the current element.

This function does not perform any type conversions, including from boolean or CBOR tag. Therefore, it may only be called if isUnsignedInteger() is true; calling it in any other condition is an error.

This function may be used to obtain numbers beyond the range of the return type of toInteger().

See also type(), toInteger(), isUnsignedInteger(), and isNegativeInteger().

source

pub unsafe fn type_(&self) -> Type

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.

Returns the type of the current element. It is one of the valid types or Invalid.

Calls C++ function: QCborStreamReader::Type QCborStreamReader::type() const.

C++ documentation:

Returns the type of the current element. It is one of the valid types or Invalid.

See also isValid(), isUnsignedInteger(), isNegativeInteger(), isInteger(), isByteArray(), isString(), isArray(), isMap(), isTag(), isSimpleType(), isBool(), isFalse(), isTrue(), isNull(), isUndefined(), isFloat16(), isFloat(), and isDouble().

Trait Implementations§

source§

impl CppDeletable for QCborStreamReader

Available on cpp_lib_version="5.12.2" or cpp_lib_version="5.13.0" or cpp_lib_version="5.14.0" only.
source§

unsafe fn delete(&self)

Destroys this QCborStreamReader object and frees any associated resources.

Calls C++ function: [destructor] void QCborStreamReader::~QCborStreamReader().

C++ documentation:

Destroys this QCborStreamReader object and frees any associated resources.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.