[Interest] CBOR Questions

Jérôme Godbout godboutj at amotus.ca
Wed Mar 6 16:12:48 CET 2019

I think the CBOR is the (de)serialization, the length and CRC or any other features like that is part of your transport protocol and not the CBOR itself. You need to transfer the whole data first and then pass it to CBOR deserialization when all data is received, you could also split with start delimiter. I think you want to mix 2 different layers.

-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Jason H
Sent: March 6, 2019 9:50 AM
To: Thiago Macieira <thiago.macieira at intel.com>
Cc: interest at qt-project.org
Subject: Re: [Interest] CBOR Questions

> Sent: Tuesday, March 05, 2019 at 11:42 PM
> From: "Thiago Macieira" <thiago.macieira at intel.com>
> To: interest at qt-project.org
> Subject: Re: [Interest] CBOR Questions
> On Tuesday, 5 March 2019 11:09:52 PST Jason H wrote:
> > It seems the simplest, most reliable way to implement complete reads 
> > is to serialize the QByteArray data in a QDataStream. Unfortunately 
> > it looks like CBOR types do not have QDataStream support? If I were 
> > to request anything in terms of new API that would probably be it.
> The simplest is to use the QCborValue::fromCbor overload that takes a 
> QByteArray (your buffer) and QCborParserError. Every time you receive 
> data, you try to parse and then you check the error
>  - if it's QCborError::EndOfFile, wait for more data
>  - if it's QCborError::NoError, remove "offset" bytes from the beginning of 
>    the buffer and process the loaded map
>  - if it's anything else, give up

That seems extremely CPU wasteful. While a QDataStream would know exactly when all the bytes are there and would parse the object in one go. 

But short of that, it seems maybe like we need a API that has update() like a Hashing algorithm, and a way to return a list of top-level objects with a function that much implements the loop with the logic you expressed. 

I'm not a fan of keep "trying until it works". Such protocols are never good. HTTP has content-length, or chunked encoding, but there's no "keep trying until it works" header. I realize this is more an issue with the CBOR standard not having a top-level item sentinel, and not a Qt implementation thing. 
Interest mailing list
Interest at qt-project.org

More information about the Interest mailing list