Unsolved Has anyone tried the CBOR stream reader and writer?
-
Hi,
Just wondering if anyone has tried the CBOR stream reader and writer?
https://doc.qt.io/qt-5/qcborstreamreader.htmlWhilst 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();
}Regards,
Michael -
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.
-
@mjsmithers said in Has anyone tried the CBOR stream reader and writer?:
Thanks but qcborvalue doesn't deal with name & value pairs.
It does, through
QCborMap
, which can be contained in aQCborValue
. 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.
QJsonObject jo;
QJsonDocument saveDoc(jo);
QFile file;
file.open(filename);
file.write(saveDoc.toJson());
file.close();Any ideas? Thanks in advance.
-
@mjsmithers Actually I just found QCborMap().toCborValue().toByteArray()