B4J Question [SOLVED] B4XSearializator Compression type for jRDC2 C++ Client

Binary01

Active Member
Licensed User
Longtime User
Hi,

B4XSerializator doesn't encrypt the data.
It takes objects and converts them (serializes them) to bytes.
You can use your own serialization method if you want to interact with a non-B4X program.

But
I have existing working jRDC2 servers and B4X clients Apps.

Now I want to link jRDC2 Server with Computer Software that developed with Qt C++.

I also found .Net B4XSearializator for SharpLib for .NET platform and another language python code also.
I want to create a Qt C++ Client for jRDC2 Server.
My problem is to get suitable B4XSearializator' compression.

When I use data with qCompress code without zlib and send data to jRDC2 Server
jRDC2 Server shows (ZipException) java.util.zip.ZipException: unknown compression method

B4X:
//Qt C++
QByteArray convertObjectToBytes(const QVariant &obj)
{       
QByteArray byteArray;       
QDataStream writer(&byteArray, QIODevice::WriteOnly);       
writeObject(writer, obj);       
QByteArray compressedData = qCompress(byteArray);       
return compressedData;   
}

I found a code in phthon.
b = zlib.compress(self._writer.getvalue())

So I change to zlib compression , jRDC2 Server shows (EOFException) java.io.EOFException
B4X:
//Qt C++
QByteArray byteArray;
    QDataStream writer(&byteArray, QIODevice::WriteOnly);
    writeObject(writer, obj);

    const int compressionLevel = Z_BEST_COMPRESSION;
    uLongf compressedDataSize = compressBound(byteArray.size());
    QByteArray compressedData(compressedDataSize, 0);

    int result = compress2(reinterpret_cast<Bytef *>(compressedData.data()), &compressedDataSize,
                           reinterpret_cast<const Bytef *>(byteArray.constData()), byteArray.size(), compressionLevel);

    if (result == Z_OK) {
        compressedData.resize(compressedDataSize);
        return compressedData;
    } else {
        // Handle the error, for example, by returning an empty QByteArray
        return QByteArray();
    }

How can I fix it?
 
Last edited:
Top