Add binary strings

This commit is contained in:
Andrea Cavalli 2024-09-26 19:49:02 +02:00
parent 6bafed9886
commit 26448fc1b8
3 changed files with 27 additions and 16 deletions

View File

@ -3,7 +3,6 @@ package it.cavallium.datagen.plugin;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.ParameterizedTypeName;
import com.squareup.javapoet.TypeName;
import it.cavallium.datagen.NativeNullable;
import it.cavallium.datagen.nativedata.*;
import it.unimi.dsi.fastutil.booleans.BooleanList;
import it.unimi.dsi.fastutil.bytes.ByteList;
@ -20,15 +19,15 @@ import java.util.stream.Stream;
public final class ComputedTypeArrayNative implements ComputedTypeArray {
private final String baseType;
private final boolean byteStrings;
private final boolean binaryStrings;
private ComputedTypeNative computedChild;
private final ComputedTypeSupplier computedTypeSupplier;
public ComputedTypeArrayNative(String baseType, ComputedTypeSupplier computedTypeSupplier, boolean byteStrings) {
public ComputedTypeArrayNative(String baseType, ComputedTypeSupplier computedTypeSupplier, boolean binaryStrings) {
this.baseType = baseType;
this.computedTypeSupplier = computedTypeSupplier;
this.byteStrings = byteStrings;
this.binaryStrings = binaryStrings;
}
public ComputedType getBase() {
@ -105,7 +104,7 @@ public final class ComputedTypeArrayNative implements ComputedTypeArray {
case "long" -> ClassName.get(ArraylongSerializer.class);
case "float" -> ClassName.get(ArrayfloatSerializer.class);
case "double" -> ClassName.get(ArraydoubleSerializer.class);
case "String" -> byteStrings ? ClassName.get(ArrayBinaryStringSerializer.class) : ClassName.get(ArrayStringSerializer.class);
case "String" -> binaryStrings ? ClassName.get(ArrayBinaryStringSerializer.class) : ClassName.get(ArrayStringSerializer.class);
case "Int52" -> ClassName.get(ArrayInt52Serializer.class);
default -> throw new UnsupportedOperationException();
};
@ -113,10 +112,14 @@ public final class ComputedTypeArrayNative implements ComputedTypeArray {
@Override
public FieldLocation getJSerializerInstance(String basePackageName) {
if (baseType.equals("String") && binaryStrings) {
return new FieldLocation(ClassName.get(Serializers.class), "NullableBinaryStringSerializerInstance");
} else {
var className = ClassName.get(Serializers.class);
var serializerFieldName = "Array" + baseType + "SerializerInstance";
return new FieldLocation(className, serializerFieldName);
}
}
@Override
public TypeName getJUpgraderName(String basePackageName) {

View File

@ -65,8 +65,12 @@ public final class ComputedTypeNative implements ComputedType {
@Override
public FieldLocation getJSerializerInstance(String basePackageName) {
if (type.equals("String") && binaryStrings) {
return new FieldLocation(ClassName.get(Serializers.class), "BinaryStringSerializerInstance");
} else {
return new FieldLocation(ClassName.get(Serializers.class), type + "SerializerInstance");
}
}
@Override
public TypeName getJUpgraderName(String basePackageName) {

View File

@ -106,6 +106,9 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
@Override
public FieldLocation getJSerializerInstance(String basePackageName) {
if (baseType.equals("String") && binaryStrings) {
return new FieldLocation(ClassName.get(Serializers.class), "NullableBinaryStringSerializerInstance");
} else {
var className = switch (baseType) {
case "boolean", "byte", "short", "char", "int", "long", "float", "double", "String", "Int52" ->
ClassName.get(Serializers.class);
@ -114,6 +117,7 @@ public final class ComputedTypeNullableNative implements ComputedTypeNullable {
var serializerFieldName = "Nullable" + baseType + "SerializerInstance";
return new FieldLocation(className, serializerFieldName);
}
}
@Override
public TypeName getJUpgraderName(String basePackageName) {