Add readByteArray shortcut

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-02-11 04:32:49 +01:00
parent 502db8ec5c
commit de71900cb9
5 changed files with 10 additions and 7 deletions

View File

@ -28,7 +28,7 @@ public record EncryptionResponsePacket(byte[] sharedSecret, byte[] verifyToken)
private static final Gson GSON = new Gson();
public EncryptionResponsePacket(BinaryReader reader) {
this(reader.readBytes(reader.readVarInt()), reader.readBytes(reader.readVarInt()));
this(reader.readByteArray(), reader.readByteArray());
}
@Override

View File

@ -11,8 +11,8 @@ public record EncryptionRequestPacket(@NotNull String serverId,
byte @NotNull [] verifyToken) implements ServerPacket {
public EncryptionRequestPacket(BinaryReader reader) {
this(reader.readSizedString(),
reader.readBytes(reader.readVarInt()),
reader.readBytes(reader.readVarInt()));
reader.readByteArray(),
reader.readByteArray());
}
@Override

View File

@ -40,7 +40,7 @@ public record MapDataPacket(int mapId, byte scale, boolean locked,
byte rows = reader.readByte();
byte x = reader.readByte();
byte z = reader.readByte();
byte[] data = reader.readBytes(reader.readVarInt());
byte[] data = reader.readByteArray();
return new MapDataPacket(mapId, scale, locked,
trackingPosition, icons, new ColorContent(columns, rows, x, z,
data));
@ -86,7 +86,7 @@ public record MapDataPacket(int mapId, byte scale, boolean locked,
byte @NotNull [] data) implements Writeable {
public ColorContent(BinaryReader reader) {
this(reader.readByte(), reader.readByte(), reader.readByte(), reader.readByte(),
reader.readBytes(reader.readVarInt()));
reader.readByteArray());
}
public void write(BinaryWriter writer) {

View File

@ -24,8 +24,7 @@ public record ChunkData(@NotNull NBTCompound heightmaps, byte @NotNull [] data,
}
public ChunkData(BinaryReader reader) {
this((NBTCompound) reader.readTag(),
reader.readBytes(reader.readVarInt()),
this((NBTCompound) reader.readTag(), reader.readByteArray(),
readBlockEntities(reader));
}

View File

@ -131,6 +131,10 @@ public class BinaryReader extends InputStream {
return bytes;
}
public byte[] readByteArray() {
return readBytes(readVarInt());
}
public String[] readSizedStringArray(int maxLength) {
final int size = readVarInt();
String[] strings = new String[size];