mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-14 08:26:45 +00:00
ref[protocol]: refactor field method
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
|
||||
package com.zfoo.protocol.serializer.gdscript;
|
||||
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.Field;
|
||||
public interface IGoSerializer {
|
||||
|
||||
/**
|
||||
* 获取属性的类型和名称
|
||||
* 获取属性的类型
|
||||
*/
|
||||
String fieldType(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ public class CodeGenerateKotlin implements ICodeGenerate {
|
||||
for (var fieldNote : fieldNotes) {
|
||||
ktBuilder.append(fieldNote).append(LS);
|
||||
}
|
||||
var pair = ktSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
var pair = ktSerializer(fieldRegistration.serializer()).fieldTypeValue(field, fieldRegistration);
|
||||
ktBuilder.append(StringUtils.format("var {}: {} = {}", fieldName, pair.getKey(), pair.getValue())).append(LS);
|
||||
}
|
||||
return ktBuilder.toString();
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface IKtSerializer {
|
||||
/**
|
||||
* 获取属性的类型,默认值
|
||||
*/
|
||||
Pair<String, String> field(Field field, IFieldRegistration fieldRegistration);
|
||||
Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtArraySerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("Array<{}>", CodeGenerateKotlin.toKotlinClassName(field.getType().getComponentType().getSimpleName()));
|
||||
return new Pair<>(type, "emptyArray()");
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class KtArraySerializer implements IKtSerializer {
|
||||
builder.append(StringUtils.format("val {} = buffer.readInt()", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var pair = CodeGenerateKotlin.ktSerializer(arrayField.getArrayElementRegistration().serializer()).field(field, arrayField.getArrayElementRegistration());
|
||||
var pair = CodeGenerateKotlin.ktSerializer(arrayField.getArrayElementRegistration().serializer()).fieldTypeValue(field, arrayField.getArrayElementRegistration());
|
||||
var defaultValue = pair.getValue();
|
||||
if (defaultValue.equals("null")) {
|
||||
defaultValue = StringUtils.format("{}()", typeName);
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtBoolSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Boolean", "false");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtByteSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Byte", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtDoubleSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Double", "0.0");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtFloatSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Float", "0f");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtIntSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtListSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateKotlin.toKotlinClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "emptyList()");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtLongSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Long", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtMapSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateKotlin.toKotlinClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "emptyMap()");
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtObjectProtocolSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
|
||||
var type = StringUtils.format("{}?", protocolSimpleName);
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtSetSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateKotlin.toKotlinClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "emptySet()");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtShortSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Short", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class KtStringSerializer implements IKtSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("String", "\"\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ public class CodeGeneratePhp implements ICodeGenerate {
|
||||
for (var fieldNote : fieldNotes) {
|
||||
phpBuilder.append(fieldNote).append(LS);
|
||||
}
|
||||
var pair = phpSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
var pair = phpSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration);
|
||||
phpBuilder.append(StringUtils.format("var {} ${} = {};", pair.getKey(), fieldName, pair.getValue())).append(LS);
|
||||
}
|
||||
return phpBuilder.toString();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
package com.zfoo.protocol.serializer.php;
|
||||
|
||||
import com.zfoo.protocol.model.Pair;
|
||||
import com.zfoo.protocol.model.Triple;
|
||||
import com.zfoo.protocol.registration.field.IFieldRegistration;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -25,9 +24,9 @@ import java.lang.reflect.Field;
|
||||
public interface IPhpSerializer {
|
||||
|
||||
/**
|
||||
* 获取属性的类型,名称,默认值
|
||||
* 获取属性的类型,默认值
|
||||
*/
|
||||
Pair<String, String> field(Field field, IFieldRegistration fieldRegistration);
|
||||
Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpArraySerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("array", "array()");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpBoolSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("bool", "false");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpByteSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpDoubleSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("float", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpFloatSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("float", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpIntSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpListSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("array", "array()");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpLongSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpMapSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("array", "array()");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpObjectProtocolSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("mixed", "null");
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpSetSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("array", "array()");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpShortSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class PhpStringSerializer implements IPhpSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("string", "\"\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -279,7 +279,7 @@ public class CodeGenerateScala implements ICodeGenerate {
|
||||
for (var fieldNote : fieldNotes) {
|
||||
scalaBuilder.append(fieldNote).append(LS);
|
||||
}
|
||||
var pair = scalaSerializer(fieldRegistration.serializer()).field(field, fieldRegistration);
|
||||
var pair = scalaSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration);
|
||||
scalaBuilder.append(StringUtils.format("var {}: {} = {}", fieldName, pair.getKey(), pair.getValue())).append(LS);
|
||||
}
|
||||
return scalaBuilder.toString();
|
||||
|
||||
@@ -25,7 +25,7 @@ public interface IScalaSerializer {
|
||||
/**
|
||||
* 获取属性的类型,默认值
|
||||
*/
|
||||
Pair<String, String> field(Field field, IFieldRegistration fieldRegistration);
|
||||
Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaArraySerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("Array[{}]", CodeGenerateScala.toScalaClassName(field.getType().getComponentType().getSimpleName()));
|
||||
return new Pair<>(type, "_");
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class ScalaArraySerializer implements IScalaSerializer {
|
||||
builder.append(StringUtils.format("val {} = buffer.readInt", size)).append(LS);
|
||||
|
||||
GenerateProtocolFile.addTab(builder, deep);
|
||||
var pair = CodeGenerateScala.scalaSerializer(arrayField.getArrayElementRegistration().serializer()).field(field, arrayField.getArrayElementRegistration());
|
||||
var pair = CodeGenerateScala.scalaSerializer(arrayField.getArrayElementRegistration().serializer()).fieldTypeDefaultValue(field, arrayField.getArrayElementRegistration());
|
||||
var defaultValue = pair.getValue();
|
||||
if (defaultValue.equals("null")) {
|
||||
defaultValue = StringUtils.format("{}()", typeName);
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaBoolSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Boolean", "false");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaByteSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Byte", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaDoubleSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Double", "0D");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaFloatSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Float", "0f");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaIntSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Int", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaListSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateScala.toScalaClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "_");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaLongSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Long", "0L");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaMapSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateScala.toScalaClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "_");
|
||||
}
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaObjectProtocolSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
|
||||
return new Pair<>(protocolSimpleName, "_");
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaSetSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateScala.toScalaClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "_");
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaShortSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("Short", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class ScalaStringSerializer implements IScalaSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> field(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("String", "_");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -293,7 +293,7 @@ public class CodeGenerateTypeScript implements ICodeGenerate {
|
||||
for (var fieldNote : fieldNotes) {
|
||||
tsBuilder.append(fieldNote).append(LS);
|
||||
}
|
||||
var pair = tsSerializer(fieldRegistration.serializer()).fieldTypeValue(field, fieldRegistration);
|
||||
var pair = tsSerializer(fieldRegistration.serializer()).fieldTypeDefaultValue(field, fieldRegistration);
|
||||
tsBuilder.append(StringUtils.format("{}: {} = {};", fieldName, pair.getKey(), pair.getValue())).append(LS);
|
||||
}
|
||||
return tsBuilder.toString();
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface ITsSerializer {
|
||||
/**
|
||||
* 获取属性的类型,默认值
|
||||
*/
|
||||
Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration);
|
||||
Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
void writeObject(StringBuilder builder, String objectStr, int deep, Field field, IFieldRegistration fieldRegistration);
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsArraySerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("Array<{}>", CodeGenerateTypeScript.toTsClassName(field.getType().getComponentType().getSimpleName()));
|
||||
return new Pair<>(type, "[]");
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsBoolSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("boolean", "false");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsByteSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsDoubleSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsFloatSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsIntSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsListSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "[]");
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsLongSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsMapSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "new Map()");
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsObjectProtocolSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
ObjectProtocolField objectProtocolField = (ObjectProtocolField) fieldRegistration;
|
||||
var protocolSimpleName = EnhanceObjectProtocolSerializer.getProtocolClassSimpleName(objectProtocolField.getProtocolId());
|
||||
var type = StringUtils.format("{} | null", protocolSimpleName);
|
||||
|
||||
@@ -31,7 +31,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsSetSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
var type = StringUtils.format("{}", CodeGenerateTypeScript.toTsClassName(field.getGenericType().toString()));
|
||||
return new Pair<>(type, "new Set()");
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsShortSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("number", "0");
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import static com.zfoo.protocol.util.FileUtils.LS;
|
||||
public class TsStringSerializer implements ITsSerializer {
|
||||
|
||||
@Override
|
||||
public Pair<String, String> fieldTypeValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
public Pair<String, String> fieldTypeDefaultValue(Field field, IFieldRegistration fieldRegistration) {
|
||||
return new Pair<>("string", "''");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user