3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 00:50:13 +01:00

Rneame CustomByteType -> FixedByteArrayType

Dieser Commit ist enthalten in:
Nassim Jahnke 2023-10-20 17:22:00 +10:00
Ursprung 6481cec270
Commit 21d293dd7f
2 geänderte Dateien mit 14 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
@Deprecated
public abstract class PartialType<T, X> extends Type<T> { public abstract class PartialType<T, X> extends Type<T> {
private final X param; private final X param;

Datei anzeigen

@ -22,27 +22,31 @@
*/ */
package com.viaversion.viaversion.api.type.types; package com.viaversion.viaversion.api.type.types;
import com.viaversion.viaversion.api.type.PartialType; import com.viaversion.viaversion.api.type.Type;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public class CustomByteType extends PartialType<byte[], Integer> { public class FixedByteArrayType extends Type<byte[]> {
public CustomByteType(Integer param) { private final int arrayLength;
super(param, byte[].class);
public FixedByteArrayType(final int arrayLength) {
super(byte[].class);
this.arrayLength = arrayLength;
} }
@Override @Override
public byte[] read(ByteBuf byteBuf, Integer integer) throws Exception { public byte[] read(final ByteBuf byteBuf) throws Exception {
if (byteBuf.readableBytes() < integer) throw new RuntimeException("Readable bytes does not match expected!"); if (byteBuf.readableBytes() < this.arrayLength) {
throw new RuntimeException("Readable bytes does not match expected!");
}
byte[] byteArray = new byte[integer]; final byte[] byteArray = new byte[this.arrayLength];
byteBuf.readBytes(byteArray); byteBuf.readBytes(byteArray);
return byteArray; return byteArray;
} }
@Override @Override
public void write(ByteBuf byteBuf, Integer integer, byte[] bytes) throws Exception { public void write(final ByteBuf byteBuf, final byte[] bytes) throws Exception {
byteBuf.writeBytes(bytes); byteBuf.writeBytes(bytes);
} }
} }