[Interest] QCborValue is not suitable for using in sockets data exchange?

Thiago Macieira thiago.macieira at intel.com
Thu May 19 22:00:42 CEST 2022


On Thursday, 19 May 2022 09:41:03 PDT Alexander Dyagilev wrote:
> Hello,
> 
> One can easily write it to socket. E.g.
> 
> socket->write(value.toCbor());
> 
> But how to read it then? It seems it's not possible.

I have yet to properly implement continued parsing with QCborValue. 
QCborStreamReader supports it, though.

> I.e. the following solution:
> 
> MyClient::MyClient()
> {
>        QCborStreamReader cborReader = new QCborStreamReader(socket);
> }

This code doesn't compile. You probably don't want to use new anyway.

> MyClient::onReadyRead()
> {
>     QCborValue::fromCbor(cborReader);
> }
> 
> Seems to be wrong. I.e. there can situation that data for the current
> item is not completely received yet. What happens then? It seems thing
> will stop working, because QCborValue::fromCbor can't resume from the
> point it stopped due to EndOfFile.

The problem here is that you are not confirming that the socket has received a 
single full CBOR element so QCborValue can parse it. QCborStreamReader can 
resume an incomplete parsing (call reparse() on it), but QCborValue cannot. 
Any sub-elements that have been consumed will be lost if you try.

> Am I right? And one just has to use plain
> QCborStreamReader/QCborStreamWriter.

For the moment.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering





More information about the Interest mailing list