Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Has anyone tried the CBOR stream reader and writer?
Forum Updated to NodeBB v4.3 + New Features

Has anyone tried the CBOR stream reader and writer?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 791 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mjsmithers
    wrote on last edited by mjsmithers
    #1

    Hi,

    Just wondering if anyone has tried the CBOR stream reader and writer?
    https://doc.qt.io/qt-5/qcborstreamreader.html

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

    Regards,
    Michael

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You're mixing thing up here - QJson never had support for streams. You're looking for https://doc.qt.io/qt-5/qcborvalue.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • M Offline
        M Offline
        mjsmithers
        wrote on last edited by
        #3

        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.

        kshegunovK 1 Reply Last reply
        0
        • M mjsmithers

          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.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @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 a QCborValue. Basically you can use the CBOR implementation exactly the same way you've been using JSON.

          Read and abide by the Qt Code of Conduct

          M 1 Reply Last reply
          4
          • kshegunovK kshegunov

            @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 a QCborValue. Basically you can use the CBOR implementation exactly the same way you've been using JSON.

            M Offline
            M Offline
            mjsmithers
            wrote on last edited by
            #5

            @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.

            M 1 Reply Last reply
            0
            • M mjsmithers

              @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.

              M Offline
              M Offline
              mjsmithers
              wrote on last edited by
              #6

              @mjsmithers Actually I just found QCborMap().toCborValue().toByteArray()

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved