Closed ustc-zzzz closed 1 month ago
I noticed the payload size doubling after testing. buf.writeBytes
writes to the calling buffer object and its signature requires a source buffer, a start index for the source buffer and a length of how much to read from the source. With the pull request write
would try to read as many bytes as the target buf
already contains and not respecting the size of the source buffer.
I guess the intended fix would have been buf.readBytes(this.buffer, this.buffer.readerIndex(), this.buffer.readableBytes());
?
Yes, buf.readBytes(this.buffer)
increases the reader index of this.buffer
so with commit 856c6cadce5d0905b391c4a627bea9d7be57ce6a i have fixed possible side effects a little differently to make the payloads intentions more clear.
Anyway, thanks for bringing this to my attention.
The encoder of a
StreamCodec
should not produce any side effect on the object to encode, which allows encoding multiple times. For example:The internal data of a packet should not change after multiple encodings while
ClientboundCustomQueryPacket
s andServerboundCustomQueryAnswerPacket
s in the current version of NeoForwarding do not fit the situation: the relatedwrite
methods can only be called once because the internal reader indexes ofFriendlyByteBuf
s as members ofPlayerDataForwarding.VelocityPlayerInfoPayload
s andPlayerDataForwarding.QueryAnswerPayload
s will change.This pull request fixes this issue by replacing
write
methods with overloads by which side effects will not be produced.