Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug in how we previously handled packet compression. Originally, our handling was done based on a boolean, either do enable compression, or don't.
However this doesn't really work, as the way we recognize whether to enable compression is through the server, sending us the
LoginSetCompression
packet, which only contains a compression threshold value. This value can be -1, in which case compression should be disabled, it can also be 0, in which case compression would indeed always be enabled, but for any other value, compression should only be enabled if the packet length surpasses this threshold, and we only know the packet length during writing, so our interaction functions need to be aware of it.Note that if this threshold isn't crossed, but is set, the packet format still changes (there is an extra varint after packet length, which generally contains the uncompressed length, but when compression wasn't used - below threshold, it will be set to 0, and the packet id and data fields below remain uncompressed).
This PR changes
sync_write_packet
andasync_write_packet
functions and replacescompressed
bool parameter tocompression_threshold
parameter, which is now being used properly. This however breaks compatibility, as these writer functions are a part of the public API, and thecompressed
parameter will no longer be available. Considering it didn't really even work properly before, it's unlikely that someone was actually using it yet, nevertheless it is a breaking change.This does also affect how packet reading works,
however there is no breaking change, as only the logic needed to change, to account for the possibility of the data length being 0, in which case compression wasn't used. This function still only takes acompressed
bool flag parameter, rather than acompression_threshold
, as if the threshold is non-negative, the packet format fundamentally changes, so we should already be reading the packets differently. For that reason, a bool flag is sufficient here, and should just be set toTrue
whenever the threshold is >= 0.Edit: Even though that makes logical sense, I've decided against making the reader use
compressed
bool flag, as it might be annoying for the user to have to docompressed=compresssion_threshold >= 0
every time when calling the function, as opposed to justcompression_threshold=compression_threshold
. So while the reader doesn't need to know this value, it also doesn't hurt to know it, and we just figure out whether or not compression is enabled ourselves, instead of bothering the user with it. Making this a breaking change too. The underlying_deserialize_packet
function still only takes acompressed
bool flag though.