CloudburstMC / Protocol

A protocol library for Minecraft Bedrock Edition
https://git.io/ProtocolLib
Apache License 2.0
312 stars 94 forks source link

Use new InflateStream to inflate WrappedPacket in WrapperSerializer #62

Closed mtsr closed 1 year ago

mtsr commented 4 years ago

I did an initial implementation that uses a stream rather than inflating the whole compressed buffer at once. This limits memory usage to some extent, although the compressed buffer can still be rather large. Changing that doesn't seem feasible at this point.

This also solves the problem of Nintendo Switch split-screen sending WrappedPackets / Batches that are larger than the 2MB limit.

Buffer is currently 2MB, but since it only has to hold between CHUNK_SIZE and the size of the next packet from the WrappedPacket, this should be plenty. Could be decreased if we have a good idea of the maximum packet size we can expect.

Uses InflateStream from CloudburstMC/Natives#1.

InflateStream is close to java.util.zip.InflaterStream, which could be used, but can't deal with current Natives.

mtsr commented 4 years ago

f0427a6 moves a spammy log to TRACE. This logs remaining bytes in the compressed buffer. This is consistently a single byte, but the value changes. Is this the last byte from the last packet that I just fail to handle correctly in readerIndex() or is there an actual bug?

Packets seem to inflate correctly...