fix: чтение пакетов
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
package mc.protocol.io;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
class ByteArrayNetInputStream extends NetInputStream {
|
||||
|
||||
private final ByteBuffer byteBuffer;
|
||||
private int index = 0;
|
||||
|
||||
public ByteArrayNetInputStream(byte[] buffer) {
|
||||
byteBuffer = ByteBuffer.wrap(buffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markReadIndex() {
|
||||
index = byteBuffer.position();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetReadIndex() {
|
||||
byteBuffer.position(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readableBytes() {
|
||||
return byteBuffer.limit(); //TODO нужно простестировать
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte readByte() {
|
||||
return byteBuffer.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readBytes(byte[] buffer, int offset, int lengtn) {
|
||||
return readableBytes() - byteBuffer.get(buffer, offset, lengtn).remaining();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readShort() {
|
||||
return byteBuffer.getShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() {
|
||||
return byteBuffer.getInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() {
|
||||
return byteBuffer.getLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float readFloat() {
|
||||
return byteBuffer.getFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double readDouble() {
|
||||
return byteBuffer.getDouble();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package mc.protocol.io;
|
||||
|
||||
import mc.protocol.io.coder.ByteArrayNetInputStream;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package mc.protocol.io;
|
||||
|
||||
import mc.protocol.io.coder.ByteArrayNetInputStream;
|
||||
import mc.protocol.io.coder.ByteArrayNetOutputStream;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
Reference in New Issue
Block a user