Simplify var-int reading

This commit is contained in:
TheMode 2021-08-06 14:30:55 +02:00
parent 455c21208e
commit 9bcf89b677

View File

@ -52,8 +52,7 @@ public final class BinaryBuffer {
public int readVarInt() { public int readVarInt() {
int value = 0; int value = 0;
final int maxRead = Math.min(5, readableBytes()); for (int i = 0; i < 5; i++) {
for (int i = 0; i < maxRead; i++) {
final int offset = readerOffset + i; final int offset = readerOffset + i;
final byte k = nioBuffer.get(offset); final byte k = nioBuffer.get(offset);
value |= (k & 0x7F) << i * 7; value |= (k & 0x7F) << i * 7;
@ -62,7 +61,6 @@ public final class BinaryBuffer {
return value; return value;
} }
} }
this.readerOffset += maxRead;
throw new RuntimeException("VarInt is too big"); throw new RuntimeException("VarInt is too big");
} }