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

View File

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

View File

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