Split binary sequence into more buffers (QByteArray).
Unsolved
General and Desktop
-
I have a QByteArrary that I fill from a stream, more precisely the data are JPEG encoded frame (SOI =
0xffd8
, EOI =0xffd9
), one after the other.QByteArrary::split method only allow to search for a
char
character and not for achar *
data type. Is there another way to look for a determined sequence in an a binary buffer ?Of course I can develope my own function, but if there is something alredy done it would be perfect.
Thanks in advance.
Regards,
s. -
@simozz You can use https://doc.qt.io/qt-5/qbytearray.html#indexOf-1 and then https://doc.qt.io/qt-5/qbytearray.html#mid
But this is a bit more work as just using split(). -
const unsigned char soi[]={0xff,0xd8,0}; const unsigned char eoi[]={0xff,0xd9,0}; const int startOfItem = dataArray.indexOf(reinterpret_cast<const char*>(soi)); const int endOfItem = dataArray.indexOf(reinterpret_cast<const char*>(eoi),startOfItem); if(startOfItem>0 && endOfItem>0) qDebug() << dataArray.mid(startOfItem,endOfItem-startOfItem+1).toBase64();