отделяем сериализацию от сущностей

This commit is contained in:
2020-04-21 18:35:07 +03:00
parent 4905f59301
commit cf47c189ed
34 changed files with 418 additions and 260 deletions

View File

@@ -0,0 +1,36 @@
package mc.nbt.codec.vanilla;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import mc.nbt.TypeTag;
import java.util.stream.Stream;
@RequiredArgsConstructor
@Getter
public enum CodecEnum {
END(TypeTag.END, new TagEndCodec()),
BYTE(TypeTag.BYTE, new TagByteCodec()),
SHORT(TypeTag.SHORT, new TagShortCodec()),
INT(TypeTag.INT, new TagIntCodec()),
LONG(TypeTag.LONG, new TagLongCodec()),
FLOAT(TypeTag.FLOAT, new TagFloatCodec()),
DOUBLE(TypeTag.DOUBLE, new TagDoubleCodec()),
BYTE_ARRAY(TypeTag.BYTE_ARRAY, new TagByteArrayCodec()),
STRING(TypeTag.STRING, new TagStringCodec()),
LIST(TypeTag.LIST, new TagListCodec()),
COMPOUND(TypeTag.COMPOUND, new TagCompoundCodec()),
INT_ARRAY(TypeTag.INT_ARRAY, new TagIntArrayCodec()),
LONG_ARRAY(TypeTag.LONG_ARRAY, new TagLongArrayCodec());
public static CodecEnum valueOfTypeTag(TypeTag typeTag) {
return Stream.of(CodecEnum.values())
.filter(codecEnum -> codecEnum.getTypeTag() == typeTag)
.findFirst()
.orElseThrow(() -> new RuntimeException("Codec for " + typeTag.name() + " not found"));
}
private final TypeTag typeTag;
private final Codec codec;
}