Archived
0

использованы костыли для предотвращения "рваных" пакетоов

Пакеты иногда могут приходить не полностью, а кусками. Раньше из-за этого
возникали ошибки декода пакетов, у которых данные обрывались.
This commit is contained in:
2018-09-16 22:18:36 +03:00
parent 3ee1b16c92
commit 30d15cfa0f
3 changed files with 22 additions and 19 deletions

View File

@@ -13,25 +13,31 @@ import java.util.UUID;
@Slf4j
public abstract class NetInputStream_p340 extends NetInputStream {
@Override
public int readVarInt() {
public int readVarInt(int[] countReadBytes) {
int numRead = 0;
int result = 0;
byte read;
do {
if ((numRead+1) > 5) {
log.warn("VarInt is too big");
break;
}
read = readByte();
int value = (read & 0b01111111);
result |= (value << (7 * numRead));
numRead++;
if (numRead > 5) {
log.warn("VarInt is too big");
break;
}
} while ((read & 0b10000000) != 0);
if (countReadBytes != null && countReadBytes.length == 1) countReadBytes[0] = numRead;
return result;
}
@Override
public int readVarInt() {
return readVarInt(null);
}
@Override
public String readString() {
int size = readVarInt();