[Interest] CBOR Questions
jhihn at gmx.com
Wed Mar 6 15:50:28 CET 2019
> 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.
More information about the Interest