Has anyone tried the CBOR stream reader and writer?
mjsmithers last edited by mjsmithers
Just wondering if anyone has tried the CBOR stream reader and writer?
Whilst the documentation suggests the data should be in name & value pairs, the stream reader has no name lookup so the values may as well be serialised without any associated names.
I started looking into CBOR because with Qt 5.15, the binary JSON is deemed deprecated. However the CBOR implementation seems almost pointless. In JSON I make heavy use of things like:
if (json_object.contains("The name I want"))
my_variable = json_object["The name I want"].toDouble();
You're mixing thing up here - QJson never had support for streams. You're looking for https://doc.qt.io/qt-5/qcborvalue.html
Thanks but qcborvalue doesn't deal with name & value pairs. It seems a lot lower level in nature. I want to be able to look for values by name and store values by name without having the explicitly to the serialisation.
Thanks but qcborvalue doesn't deal with name & value pairs.
It does, through
QCborMap, which can be contained in a
QCborValue. Basically you can use the CBOR implementation exactly the same way you've been using JSON.
@kshegunov Thanks. So I've figure out QCborMap but I don't see any way to write a map to a file or to a QByteArray. JSON has QJsonDocument e.g.
Any ideas? Thanks in advance.
@mjsmithers Actually I just found QCborMap().toCborValue().toByteArray()