Help about compression!


I am using wildfire 3.0 and want to make it send packets compressed. And my question is :

How does client know the end of the compressed packet ?I know the packet is in Zlib format. Could you tell me how client judge that the end of packet?

ZLib in C needs the length of the compressed data, if client doesn’‘t know packet’'s end not to say decompress it!

Any suggestion is welcomed Thank you


He Qi

Zlib needs the length of the data you have available, and you know that. Zlib will decompress as much as it can of the available data it has. Just keep on feeding zlib data whenever you get it, zlib will do the rest.

If you want some example code, you can look at Compressor::write(QByteArray) (for compression) and Decompressor::write(QBytearray) here, for zlib compression and decompression, used in an XMPP client. It flushes the zlib stream upon every compressed packet, in order to be able to send every stanza immediately. (PS: I’'m not sure if this is the optimal code, i am not a zlib expert, but wanted to be safe)


Thanks for your response.

I am new to jzlib.

If I give the ZInputStream a byte array , which 4 compressed packets in the head of byte array

and some bytes which are not full packet but part of compressed packet, do you mean that the JZlib will give me the first 4 packets decompressed and the rest is decompressed when the packet get completed and I can gain the packet ?

Message was edited by: foreverqihe

I don’'t know JZLib, unfortunately. But it would seem to me that, if you have set it to incremental decompression, that sounds like the behavior i would expect.