[][src]Struct qt_core::QCborStreamReader

#[repr(C)]
pub struct QCborStreamReader { /* fields omitted */ }

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(); } }

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> StaticUpcast<T> for T[src]

impl<T, U> CastInto<U> for T where
    U: CastFrom<T>, 
[src]