Rneame CustomByteType -> FixedByteArrayType

This commit is contained in:
Nassim Jahnke 2023-10-20 17:22:00 +10:00
parent 6481cec270
commit 21d293dd7f
2 changed files with 14 additions and 9 deletions

View File

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

View File

@ -22,27 +22,31 @@
*/
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;
public class CustomByteType extends PartialType<byte[], Integer> {
public class FixedByteArrayType extends Type<byte[]> {
public CustomByteType(Integer param) {
super(param, byte[].class);
private final int arrayLength;
public FixedByteArrayType(final int arrayLength) {
super(byte[].class);
this.arrayLength = arrayLength;
}
@Override
public byte[] read(ByteBuf byteBuf, Integer integer) throws Exception {
if (byteBuf.readableBytes() < integer) throw new RuntimeException("Readable bytes does not match expected!");
public byte[] read(final ByteBuf byteBuf) throws Exception {
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);
return byteArray;
}
@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);
}
}