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

The QCborStreamWriter class is a simple CBOR encoder operating on a one-way stream.

C++ class: QCborStreamWriter.

C++ documentation:

The QCborStreamWriter class is a simple CBOR encoder operating on a one-way stream.

This class can be used to quickly encode a stream of CBOR content directly to either a QByteArray or 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.

QCborStreamWriter provides a StAX-like API, similar to that of QXmlStreamWriter. It is rather low-level and requires a bit of knowledge of CBOR encoding. For a simpler API, see QCborValue and especially the encoding function QCborValue::toCbor().

The typical use of QCborStreamWriter is to create the object on the target QByteArray or QIODevice, then call one of the append() overloads with the desired type to be encoded. To create arrays and maps, QCborStreamWriter provides startArray() and startMap() overloads, which must be terminated by the corresponding endArray() and endMap() functions.

The following example encodes the equivalent of this JSON content:

{ "label": "journald", "autoDetect": false, "condition": "libs.journald", "output": [ "privateFeature" ] }

writer.startMap(4); // 4 elements in the map

writer.append(QLatin1String(“label”)); writer.append(QLatin1String(“journald”));

writer.append(QLatin1String(“autoDetect”)); writer.append(false);

writer.append(QLatin1String(“condition”)); writer.append(QLatin1String(“libs.journald”));

writer.append(QLatin1String(“output”)); writer.startArray(1); writer.append(QLatin1String(“privateFeature”)); writer.endArray();

writer.endMap();

Implementations§

source§

impl QCborStreamWriter

source

pub unsafe fn append_u64(&self, u: u64)

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 QCborStreamWriter::append(quint64 u).

C++ documentation:

This is an overloaded function.

Appends the 64-bit unsigned value u to the CBOR stream, creating a CBOR Unsigned Integer value. In the following example, we write the values 0, 232 and UINT64_MAX:

writer.append(0U); writer.append(Q_UINT64_C(4294967296)); writer.append(std::numeric_limits<quint64>::max());

See also QCborStreamReader::isUnsignedInteger() and QCborStreamReader::toUnsignedInteger().

source

pub unsafe fn append_i64(&self, i: i64)

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 QCborStreamWriter::append(qint64 i).

C++ documentation:

This is an overloaded function.

Appends the 64-bit signed value i to the CBOR stream. This will create either a CBOR Unsigned Integer or CBOR NegativeInteger value based on the sign of the parameter. In the following example, we write the values 0, -1, 232 and INT64_MAX:

writer.append(0); writer.append(-1); writer.append(Q_INT64_C(4294967296)); writer.append(std::numeric_limits<qint64>::max());

See also QCborStreamReader::isInteger() and QCborStreamReader::toInteger().

source

pub unsafe fn append_q_cbor_negative_integer(&self, n: QCborNegativeInteger)

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 QCborStreamWriter::append(QCborNegativeInteger n).

C++ documentation:

This is an overloaded function.

Appends the 64-bit negative value n to the CBOR stream. QCborNegativeInteger is a 64-bit enum that holds the absolute value of the negative number we want to write. If n is zero, the value written will be equivalent to 264 (that is, -18,446,744,073,709,551,616).

In the following example, we write the values -1, -232 and INT64_MIN:

writer.append(QCborNegativeInteger(1)); writer.append(QCborNegativeInteger(Q_INT64_C(4294967296))); writer.append(QCborNegativeInteger(-quint64(std::numeric_limits<qint64>::min())));

Note how this function can be used to encode numbers that cannot fit a standard computer's 64-bit signed integer like qint64. That is, if n is larger than std::numeric_limits<qint64>::max() or is 0, this will represent a negative number smaller than std::numeric_limits<qint64>::min().

See also QCborStreamReader::isNegativeInteger() and QCborStreamReader::toNegativeInteger().

source

pub unsafe fn append_q_byte_array(&self, ba: 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.

This is an overloaded function.

Calls C++ function: void QCborStreamWriter::append(const QByteArray& ba).

C++ documentation:

This is an overloaded function.

Appends the byte array ba to the stream, creating a CBOR Byte String value. QCborStreamWriter will attempt to write the entire string in one chunk.

The following example will load and append the contents of a file to the stream:

void writeFile(QCborStreamWriter &writer, const QString &fileName) { QFile f(fileName); if (f.open(QIODevice::ReadOnly)) writer.append(f.readAll()); }

As the example shows, unlike JSON, CBOR requires no escaping for binary content.

See also appendByteString(), QCborStreamReader::isByteArray(), and QCborStreamReader::readByteArray().

source

pub unsafe fn append_q_latin1_string( &self, str: impl CastInto<Ref<QLatin1String>> )

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 QCborStreamWriter::append(QLatin1String str).

C++ documentation:

This is an overloaded function.

Appends the text string str to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk.

The following example appends a simple string to the stream:

writer.append(QLatin1String(“Hello, World”));

Performance note: CBOR requires that all Text Strings be encoded in UTF-8, so this function will iterate over the characters in the string to determine whether the contents are US-ASCII or not. If the string is found to contain characters outside of US-ASCII, it will allocate memory and convert to UTF-8. If this check is unnecessary, use appendTextString() instead.

See also QCborStreamReader::isString() and QCborStreamReader::readString().

source

pub unsafe fn append_q_string_view(&self, str: impl CastInto<Ref<QStringView>>)

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 QCborStreamWriter::append(QStringView str).

C++ documentation:

This is an overloaded function.

Appends the text string str to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk.

The following example writes an arbitrary QString to the stream:

void writeString(QCborStreamWriter &writer, const QString &str) { writer.append(str); }

See also QCborStreamReader::isString() and QCborStreamReader::readString().

source

pub unsafe fn append_q_cbor_tag(&self, tag: QCborTag)

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 QCborStreamWriter::append(QCborTag tag).

C++ documentation:

This is an overloaded function.

Appends the CBOR tag tag to the stream, creating a CBOR Tag value. All tags must be followed by another type which they provide meaning for.

In the following example, we append a CBOR Tag 36 (Regular Expression) and a QRegularExpression's pattern to the stream:

void writeRxPattern(QCborStreamWriter &writer, const QRegularExpression &rx) { writer.append(QCborTag(36)); writer.append(rx.pattern()); }

See also QCborStreamReader::isTag() and QCborStreamReader::toTag().

source

pub unsafe fn append_q_cbor_known_tags(&self, tag: QCborKnownTags)

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 QCborStreamWriter::append(QCborKnownTags tag).

C++ documentation:

This is an overloaded function.

Appends the CBOR tag tag to the stream, creating a CBOR Tag value. All tags must be followed by another type which they provide meaning for.

In the following example, we append a CBOR Tag 1 (Unix time_t) and an integer representing the current time to the stream, obtained using the time() function:

void writeCurrentTime(QCborStreamWriter &writer) { writer.append(QCborKnownTags::UnixTime_t); writer.append(time(nullptr)); }

See also QCborStreamReader::isTag() and QCborStreamReader::toTag().

source

pub unsafe fn append_q_cbor_simple_type(&self, st: QCborSimpleType)

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 QCborStreamWriter::append(QCborSimpleType st).

C++ documentation:

This is an overloaded function.

Appends the CBOR simple type st to the stream, creating a CBOR Simple Type value. In the following example, we write the simple type for Null as well as for type 32, which Qt has no support for.

writer.append(QCborSimpleType::Null); writer.append(QCborSimpleType(32));

Note: Using Simple Types for which there is no specification can lead to validation errors by the remote receiver. In addition, simple type values 24 through 31 (inclusive) are reserved and must not be used.

See also QCborStreamReader::isSimpleType() and QCborStreamReader::toSimpleType().

source

pub unsafe fn append_qfloat16(&self, f: impl CastInto<Ref<Qfloat16>>)

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 QCborStreamWriter::append(qfloat16 f).

C++ documentation:

This is an overloaded function.

Appends the floating point number f to the stream, creating a CBOR 16-bit Half-Precision Floating Point value. The following code can be used to convert a C++ float to qfloat16 if there's no loss of precision and append it, or instead append the float.

void writeFloat(QCborStreamWriter &writer, float f) { qfloat16 f16 = f; if (qIsNaN(f) || f16 == f) writer.append(f16); else writer.append(f); }

See also QCborStreamReader::isFloat16() and QCborStreamReader::toFloat16().

source

pub unsafe fn append_float(&self, f: 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.

This is an overloaded function.

Calls C++ function: void QCborStreamWriter::append(float f).

C++ documentation:

This is an overloaded function.

Appends the floating point number f to the stream, creating a CBOR 32-bit Single-Precision Floating Point value. The following code can be used to convert a C++ double to float if there's no loss of precision and append it, or instead append the double.

void writeFloat(QCborStreamWriter &writer, double d) { float f = d; if (qIsNaN(d) || d == f) writer.append(f); else writer.append(d); }

See also QCborStreamReader::isFloat() and QCborStreamReader::toFloat().

source

pub unsafe fn append_double(&self, d: 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.

This is an overloaded function.

Calls C++ function: void QCborStreamWriter::append(double d).

C++ documentation:

This is an overloaded function.

Appends the floating point number d to the stream, creating a CBOR 64-bit Double-Precision Floating Point value. QCborStreamWriter always appends the number as-is, performing no check for whether the number is the canonical form for NaN, an infinite, whether it is denormal or if it could be written with a shorter format.

The following code performs all those checks, except for the denormal one, which is expected to be taken into account by the system FPU or floating point emulation directly.

void writeDouble(QCborStreamWriter &writer, double d) { float f; if (qIsNaN(d)) { writer.append(qfloat16(qQNaN())); } else if (qIsInf(d)) { writer.append(d < 0 ? -qInf() : qInf()); } else if ((f = d) == d) { qfloat16 f16 = f; if (f16 == f) writer.append(f16); else writer.append(f); } else { writer.append(d); } }

Determining if a double can be converted to an integral with no loss of precision is left as an exercise to the reader.

See also QCborStreamReader::isDouble() and QCborStreamReader::toDouble().

source

pub unsafe fn append_bool(&self, b: bool)

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 QCborStreamWriter::append(bool b).

C++ documentation:

This is an overloaded function.

Appends the boolean value b to the stream, creating either a CBOR False value or a CBOR True value. This function is equivalent to (and implemented as):

writer.append(b ? QCborSimpleType::True : QCborSimpleType::False);

See also appendNull(), appendUndefined(), QCborStreamReader::isBool(), and QCborStreamReader::toBool().

source

pub unsafe fn append_int(&self, i: 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.

Calls C++ function: void QCborStreamWriter::append(int i).

source

pub unsafe fn append_uint(&self, u: c_uint)

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

Calls C++ function: void QCborStreamWriter::append(unsigned int u).

source

pub unsafe fn append_char_longlong(&self, str: *const c_char, size: 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 QCborStreamWriter::append(const char* str, long long size = …).

C++ documentation:

This is an overloaded function.

Appends size bytes of text starting from str to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk. If size is -1, this function will write strlen(\a str) bytes.

The string pointed to by str is expected to be properly encoded UTF-8. QCborStreamWriter performs no validation that this is the case.

Unlike the QLatin1String overload of append(), this function is not limited to 2 GB. However, note that neither QCborStreamReader nor QCborValue support reading CBOR streams with text strings larger than 2 GB.

See also append(QLatin1String), append(QStringView), QCborStreamReader::isString(), and QCborStreamReader::readString().

source

pub unsafe fn append_char(&self, str: *const c_char)

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 QCborStreamWriter::append(const char* str).

C++ documentation:

This is an overloaded function.

Appends size bytes of text starting from str to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk. If size is -1, this function will write strlen(\a str) bytes.

The string pointed to by str is expected to be properly encoded UTF-8. QCborStreamWriter performs no validation that this is the case.

Unlike the QLatin1String overload of append(), this function is not limited to 2 GB. However, note that neither QCborStreamReader nor QCborValue support reading CBOR streams with text strings larger than 2 GB.

See also append(QLatin1String), append(QStringView), QCborStreamReader::isString(), and QCborStreamReader::readString().

source

pub unsafe fn append_byte_string(&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.

Appends len bytes of data starting from data to the stream, creating a CBOR Byte String value. QCborStreamWriter will attempt to write the entire string in one chunk.

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

C++ documentation:

Appends len bytes of data starting from data to the stream, creating a CBOR Byte String value. QCborStreamWriter will attempt to write the entire string in one chunk.

Unlike the QByteArray overload of append(), this function is not limited by QByteArray's size limits. However, note that neither QCborStreamReader::readByteArray() nor QCborValue support reading CBOR streams with byte arrays larger than 2 GB.

See also append(), appendTextString(), QCborStreamReader::isByteArray(), and QCborStreamReader::readByteArray().

source

pub unsafe fn append_null(&self)

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

Appends a CBOR Null value to the stream. This function is equivalent to (and implemented as):

Calls C++ function: void QCborStreamWriter::appendNull().

C++ documentation:

Appends a CBOR Null value to the stream. This function is equivalent to (and implemented as):


     writer.append(QCborSimpleType::Null);

See also append(std::nullptr_t), append(QCborSimpleType), and QCborStreamReader::isNull().

source

pub unsafe fn append_text_string(&self, utf8: *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.

Appends len bytes of text starting from utf8 to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk.

Calls C++ function: void QCborStreamWriter::appendTextString(const char* utf8, long long len).

C++ documentation:

Appends len bytes of text starting from utf8 to the stream, creating a CBOR Text String value. QCborStreamWriter will attempt to write the entire string in one chunk.

The string pointed to by utf8 is expected to be properly encoded UTF-8. QCborStreamWriter performs no validation that this is the case.

Unlike the QLatin1String overload of append(), this function is not limited to 2 GB. However, note that neither QCborStreamReader::readString() nor QCborValue support reading CBOR streams with text strings larger than 2 GB.

See also append(QLatin1String), append(QStringView), QCborStreamReader::isString(), and QCborStreamReader::readString().

source

pub unsafe fn append_undefined(&self)

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

Appends a CBOR Undefined value to the stream. This function is equivalent to (and implemented as):

Calls C++ function: void QCborStreamWriter::appendUndefined().

C++ documentation:

Appends a CBOR Undefined value to the stream. This function is equivalent to (and implemented as):


     writer.append(QCborSimpleType::Undefined);

See also append(QCborSimpleType) and QCborStreamReader::isUndefined().

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 this QCborStreamWriter object is writing to. The device must have previously been set with either the constructor or with setDevice().

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

C++ documentation:

Returns the QIODevice that this QCborStreamWriter object is writing to. The device must have previously been set with either the constructor or with setDevice().

If this object was created by writing to a QByteArray, this function will return an internal instance of QBuffer, which is owned by QCborStreamWriter.

See also setDevice().

source

pub unsafe fn end_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.

Terminates the array started by either overload of startArray() and returns true if the correct number of elements was added to the array. This function must be called for every startArray() used.

Calls C++ function: bool QCborStreamWriter::endArray().

C++ documentation:

Terminates the array started by either overload of startArray() and returns true if the correct number of elements was added to the array. This function must be called for every startArray() used.

A return of false indicates error in the application and an unrecoverable error in this stream. QCborStreamWriter also writes a warning using qWarning() if that happens.

Calling this function when the current container is not an array is also an error, though QCborStreamWriter cannot currently detect this condition.

See also startArray(), startArray(quint64), and endMap().

source

pub unsafe fn end_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.

Terminates the map started by either overload of startMap() and returns true if the correct number of elements was added to the array. This function must be called for every startMap() used.

Calls C++ function: bool QCborStreamWriter::endMap().

C++ documentation:

Terminates the map started by either overload of startMap() and returns true if the correct number of elements was added to the array. This function must be called for every startMap() used.

A return of false indicates error in the application and an unrecoverable error in this stream. QCborStreamWriter also writes a warning using qWarning() if that happens.

Calling this function when the current container is not a map is also an error, though QCborStreamWriter cannot currently detect this condition.

See also startMap(), startMap(quint64), and endArray().

source

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

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 QCborStreamWriter object that will write the stream to device. The device must be opened before the first append() call is made. This constructor can be used with any class that derives from QIODevice, such as QFile, QProcess or QTcpSocket.

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

C++ documentation:

Creates a QCborStreamWriter object that will write the stream to device. The device must be opened before the first append() call is made. This constructor can be used with any class that derives from QIODevice, such as QFile, QProcess or QTcpSocket.

QCborStreamWriter has no buffering, so every append() call will result in one or more calls to the device's write() method.

The following example writes an empty map to a file:

QFile f(“output”, QIODevice::WriteOnly); QCborStreamWriter writer(&f); writer.startMap(0); writer.endMap();

QCborStreamWriter does not take ownership of device.

See also device() and setDevice().

source

pub unsafe fn from_q_byte_array( data: impl CastInto<Ptr<QByteArray>> ) -> CppBox<QCborStreamWriter>

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 QCborStreamWriter object that will append the stream to data. All streaming is done immediately to the byte array, without the need for flushing any buffers.

Calls C++ function: [constructor] void QCborStreamWriter::QCborStreamWriter(QByteArray* data).

C++ documentation:

Creates a QCborStreamWriter object that will append the stream to data. All streaming is done immediately to the byte array, without the need for flushing any buffers.

The following example writes a number to a byte array then returns it.

QByteArray encodedNumber(qint64 value) { QByteArray ba; QCborStreamWriter writer(&ba); writer.append(value); return ba; }

QCborStreamWriter does not take ownership of data.

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.

Replaces the device or byte array that this QCborStreamWriter object is writing to with device.

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

C++ documentation:

Replaces the device or byte array that this QCborStreamWriter object is writing to with device.

See also device().

source

pub unsafe fn start_array_0a(&self)

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

Starts a CBOR Array with indeterminate length in the CBOR stream. Each startArray() call must be paired with one endArray() call and the current CBOR element extends until the end of the array.

Calls C++ function: void QCborStreamWriter::startArray().

C++ documentation:

Starts a CBOR Array with indeterminate length in the CBOR stream. Each startArray() call must be paired with one endArray() call and the current CBOR element extends until the end of the array.

The array created by this function has no explicit length. Instead, its length is implied by the elements contained in it. Note, however, that use of indeterminate-length arrays is not compliant with canonical CBOR encoding.

The following example appends elements from the linked list of strings passed as input:

void appendList(QCborStreamWriter &writer, const QLinkedList<QString> &list) { writer.startArray(); for (const QString &s : list) writer.append(s); writer.endArray(); }

See also startArray(quint64), endArray(), startMap(), QCborStreamReader::isArray(), and QCborStreamReader::isLengthKnown().

source

pub unsafe fn start_array_1a(&self, count: u64)

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 QCborStreamWriter::startArray(quint64 count).

C++ documentation:

This is an overloaded function.

Starts a CBOR Array with explicit length of count items in the CBOR stream. Each startArray call must be paired with one endArray() call and the current CBOR element extends until the end of the array.

The array created by this function has an explicit length and therefore exactly count items must be added to the CBOR stream. Adding fewer or more items will result in failure during endArray() and the CBOR stream will be corrupt. However, explicit-length arrays are required by canonical CBOR encoding.

The following example appends all strings found in the QStringList passed as input:

void appendList(QCborStreamWriter &writer, const QStringList &list) { writer.startArray(list.size()); for (const QString &s : list) writer.append(s); writer.endArray(); }

Size limitations: The parameter to this function is quint64, which would seem to allow up to 264-1 elements in the array. However, both QCborStreamWriter and QCborStreamReader are currently limited to 232-2 items on 32-bit systems and 264-2 items on 64-bit ones. Also note that QCborArray is currently limited to 227 elements in any platform.

See also startArray(), endArray(), startMap(), QCborStreamReader::isArray(), and QCborStreamReader::isLengthKnown().

source

pub unsafe fn start_map_0a(&self)

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

Starts a CBOR Map with indeterminate length in the CBOR stream. Each startMap() call must be paired with one endMap() call and the current CBOR element extends until the end of the map.

Calls C++ function: void QCborStreamWriter::startMap().

C++ documentation:

Starts a CBOR Map with indeterminate length in the CBOR stream. Each startMap() call must be paired with one endMap() call and the current CBOR element extends until the end of the map.

The map created by this function has no explicit length. Instead, its length is implied by the elements contained in it. Note, however, that use of indeterminate-length maps is not compliant with canonical CBOR encoding (canonical encoding also requires keys to be unique and in sorted order).

The following example appends elements from the linked list of int and string pairs passed as input:

void appendMap(QCborStreamWriter &writer, const QLinkedList<QPair<int, QString>> &list) { writer.startMap(); for (const auto pair : list) { writer.append(pair.first) writer.append(pair.second); } writer.endMap(); }

See also startMap(quint64), endMap(), startArray(), QCborStreamReader::isMap(), and QCborStreamReader::isLengthKnown().

source

pub unsafe fn start_map_1a(&self, count: u64)

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 QCborStreamWriter::startMap(quint64 count).

C++ documentation:

This is an overloaded function.

Starts a CBOR Map with explicit length of count items in the CBOR stream. Each startMap call must be paired with one endMap() call and the current CBOR element extends until the end of the map.

The map created by this function has an explicit length and therefore exactly count pairs of items must be added to the CBOR stream. Adding fewer or more items will result in failure during endMap() and the CBOR stream will be corrupt. However, explicit-length map are required by canonical CBOR encoding.

The following example appends all strings found in the QMap passed as input:

void appendMap(QCborStreamWriter &writer, const QMap<int, QString> &map) { writer.startMap(map.size()); for (auto it = map.begin(); it != map.end(); ++it) { writer.append(it.key()); writer.append(it.value()); } writer.endMap(); }

Size limitations: The parameter to this function is quint64, which would seem to allow up to 264-1 pairs in the map. However, both QCborStreamWriter and QCborStreamReader are currently limited to 231-1 items on 32-bit systems and 263-1 items on 64-bit ones. Also note that QCborMap is currently limited to 226 elements in any platform.

See also startMap(), endMap(), startArray(), QCborStreamReader::isMap(), and QCborStreamReader::isLengthKnown().

Trait Implementations§

source§

impl CppDeletable for QCborStreamWriter

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 QCborStreamWriter object and frees any resources associated.

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

C++ documentation:

Destroys this QCborStreamWriter object and frees any resources associated.

QCborStreamWriter does not perform error checking to see if all required items were written to the stream prior to the object being destroyed. It is the programmer's responsibility to ensure that it was done.

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.