[−][src]Struct qt_core::QCborStreamWriter
The QCborStreamWriter class is a simple CBOR encoder operating on a one-way stream.
C++ class: QCborStreamWriter
.
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();
Auto Trait Implementations
impl Send for QCborStreamWriter
impl Sync for QCborStreamWriter
impl Unpin for QCborStreamWriter
impl UnwindSafe for QCborStreamWriter
impl RefUnwindSafe for QCborStreamWriter
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> StaticUpcast<T> for T
[src]
unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>
[src]
unsafe fn static_upcast_mut(ptr: MutPtr<T>) -> MutPtr<T>
[src]
impl<T, U> CastInto<U> for T where
U: CastFrom<T>,
[src]
U: CastFrom<T>,