mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-05 10:20:42 +01:00
Simplify var-int reading
This commit is contained in:
parent
455c21208e
commit
9bcf89b677
@ -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");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user