Skip to content

Commit

Permalink
chore[protocol]: rename and delete unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Oct 7, 2023
1 parent 6a7c586 commit 289a0a0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 141 deletions.
9 changes: 4 additions & 5 deletions protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ For complex objects, ZFOO package size 2216, KRYO package size 2528, and Protobu

- Default data format support eliminates the need for users to register
manually.[参考类定义](src/test/java/com/zfoo/protocol/packet/ComplexObject.java)
- boolean,byte,short,int,long,float,double,char,String
- Boolean,Byte,Short,Integer,Long,Float,Double,Character,If it is null during serialization, a default value of 0
will be given (the default value of Character is Character.MIN VALUE)
- boolean,byte,short,int,long,float,double,String
- Boolean,Byte,Short,Integer,Long,Float,Double,String,If it is null during serialization, a default value will be given
- int[],Integer[],If it is null, it is parsed as an array of length 0
- Native generic List, Set, Map, deserialization return type Hash Set, Array List, Hash Map, and null pointer
safe (returns a collection of size 0)
Expand All @@ -110,8 +109,8 @@ For complex objects, ZFOO package size 2216, KRYO package size 2528, and Protobu
- int[][],Arrays above two dimensions, considering that not all languages support multidimensional arrays
- List<Integer>[],Map<Integer, Integer>[],The Java language itself does not support generic class arrays
- List<int[]>,Map<Integer, Integer[]>,Generics are set in arrays, which looks strange and has few actual uses
- Enumerated classes, considering that many other languages do not support enumerated classes, can be replaced at
the code level with int or string
- char or Character, many other languages do not support char and can be replaced with string
- Enumerated classes, many other languages do not support enumerated classes and can be replaced with int or string
- Custom generic class XXX Class, <T>generic classes are prone to performance and parsing problems in many
frameworks, and are not supported in all languages
- Circular references, although the underlying support circular references, but considering that circular references
Expand Down
5 changes: 3 additions & 2 deletions protocol/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ cpu: i9900k
### Ⅵ. 数据类型

- 默认的数据格式支持,无需用户手动注册,[参考类定义](src/test/java/com/zfoo/protocol/packet/ComplexObject.java)
- boolean,byte,short,int,long,float,double,char,String
- Boolean,Byte,Short,Integer,Long,Float,Double,Character,序列化的时候如果null,会给个默认值0(Character默认值为Character.MIN_VALUE)
- boolean,byte,short,int,long,float,double,String
- Boolean,Byte,Short,Integer,Long,Float,Double,String 序列化的时候如果null,会给个默认值
- int[],Integer[],如果是null,则解析后的为一个长度为0的数组
- 原生泛型List,Set,Map,反序列化返回类型为HashSet,ArrayList,HashMap,并且空指针安全(返回大小为0的集合)
- List<Integer>,必须指定泛型类,如果发送的是[1,1,null,1],接收到的是[1,1,0,1]
Expand All @@ -91,6 +91,7 @@ cpu: i9900k
- int[][],二维以上数组,考虑到不是所有语言都支持多维数组
- List<Integer>[],Map<Integer, Integer>[],Java语言本身就没有支持泛型类数组
- List<int[]>,Map<Integer, Integer[]>,泛型里面套数组,这种写法看起来比较奇怪,实际使用的地方很少
- char和Character类型,考虑到很多其他语言不支持char,可以用string在代码层面做替换
- 枚举类,考虑到很多其他语言不支持枚举类,可以用int或者string在代码层面做替换
- 自定义泛型类XXXClass<T>,泛型类在很多框架中都极易出现性能上和解析上的问题,而且并不是所有语言都支持
- 循环引用,虽然底层支持循环引用,但是考虑到循环引用带来语义上难以理解,容易出现错误,所以就屏蔽了
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public abstract class EnhanceUtils {

// 临时变量,是一个基本类型序列化器对应的增强类型序列化器
private static Map<ISerializer, IEnhanceSerializer> tempEnhanceSerializerMap = new HashMap<>();
private static Map<ISerializer, IEnhanceSerializer> enhanceSerializerMap = new HashMap<>();

public static String byteBufUtils = ByteBufUtils.class.getSimpleName();
public static String byteBufUtilsWriteBooleanFalse = byteBufUtils + ".writeBoolean($1, false);";
Expand Down Expand Up @@ -69,28 +69,28 @@ public abstract class EnhanceUtils {
}
}

tempEnhanceSerializerMap.put(BooleanSerializer.INSTANCE, new EnhanceBooleanSerializer());
tempEnhanceSerializerMap.put(ByteSerializer.INSTANCE, new EnhanceByteSerializer());
tempEnhanceSerializerMap.put(ShortSerializer.INSTANCE, new EnhanceShortSerializer());
tempEnhanceSerializerMap.put(IntSerializer.INSTANCE, new EnhanceIntSerializer());
tempEnhanceSerializerMap.put(LongSerializer.INSTANCE, new EnhanceLongSerializer());
tempEnhanceSerializerMap.put(FloatSerializer.INSTANCE, new EnhanceFloatSerializer());
tempEnhanceSerializerMap.put(DoubleSerializer.INSTANCE, new EnhanceDoubleSerializer());
tempEnhanceSerializerMap.put(StringSerializer.INSTANCE, new EnhanceStringSerializer());
tempEnhanceSerializerMap.put(ObjectProtocolSerializer.INSTANCE, new EnhanceObjectProtocolSerializer());
tempEnhanceSerializerMap.put(ListSerializer.INSTANCE, new EnhanceListSerializer());
tempEnhanceSerializerMap.put(SetSerializer.INSTANCE, new EnhanceSetSerializer());
tempEnhanceSerializerMap.put(MapSerializer.INSTANCE, new EnhanceMapSerializer());
tempEnhanceSerializerMap.put(ArraySerializer.INSTANCE, new EnhanceArraySerializer());
enhanceSerializerMap.put(BooleanSerializer.INSTANCE, new EnhanceBooleanSerializer());
enhanceSerializerMap.put(ByteSerializer.INSTANCE, new EnhanceByteSerializer());
enhanceSerializerMap.put(ShortSerializer.INSTANCE, new EnhanceShortSerializer());
enhanceSerializerMap.put(IntSerializer.INSTANCE, new EnhanceIntSerializer());
enhanceSerializerMap.put(LongSerializer.INSTANCE, new EnhanceLongSerializer());
enhanceSerializerMap.put(FloatSerializer.INSTANCE, new EnhanceFloatSerializer());
enhanceSerializerMap.put(DoubleSerializer.INSTANCE, new EnhanceDoubleSerializer());
enhanceSerializerMap.put(StringSerializer.INSTANCE, new EnhanceStringSerializer());
enhanceSerializerMap.put(ObjectProtocolSerializer.INSTANCE, new EnhanceObjectProtocolSerializer());
enhanceSerializerMap.put(ListSerializer.INSTANCE, new EnhanceListSerializer());
enhanceSerializerMap.put(SetSerializer.INSTANCE, new EnhanceSetSerializer());
enhanceSerializerMap.put(MapSerializer.INSTANCE, new EnhanceMapSerializer());
enhanceSerializerMap.put(ArraySerializer.INSTANCE, new EnhanceArraySerializer());
}

public static IEnhanceSerializer enhanceSerializer(ISerializer serializer) {
return tempEnhanceSerializerMap.get(serializer);
return enhanceSerializerMap.get(serializer);
}

public static void clear() {
tempEnhanceSerializerMap.clear();
tempEnhanceSerializerMap = null;
enhanceSerializerMap.clear();
enhanceSerializerMap = null;

byteBufUtils = null;
byteBufUtilsWriteBooleanFalse = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

/**
* 一个包里所包含的变量还有这个变量的序列化器
* 描述boolean,byte,short,int,long,float,double,char,String等基本序列化器
* 描述boolean,byte,short,int,long,float,double,String等基本序列化器
*
* @author godotg
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,60 +450,6 @@ public boolean writeObject(StringBuilder builder, String objectStr, Field field,
flag = false;
}
break;
case "char":
switch (language) {
case Enhance:
builder.append(StringUtils.format("{}.writeCharArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
break;
case GdScript:
case Python:
builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS);
break;
case Lua:
builder.append(StringUtils.format("buffer:writeCharArray({})", objectStr)).append(LS);
break;
case CSharp:
builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS);
break;
case Go:
builder.append(StringUtils.format("buffer.WriteCharArray({})", objectStr)).append(LS);
break;
case Cpp:
case JavaScript:
case TypeScript:
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
break;
default:
flag = false;
}
break;
case "Character":
switch (language) {
case Enhance:
builder.append(StringUtils.format("{}.writeCharBoxArray($1, {});", EnhanceUtils.byteBufUtils, objectStr));
break;
case GdScript:
case Python:
builder.append(StringUtils.format("buffer.writeCharArray({})", objectStr)).append(LS);
break;
case Lua:
builder.append(StringUtils.format("buffer:writeCharArray({})", objectStr)).append(LS);
break;
case CSharp:
builder.append(StringUtils.format("buffer.WriteCharArray({});", objectStr)).append(LS);
break;
case Go:
builder.append(StringUtils.format("buffer.WriteCharArray({})", objectStr)).append(LS);
break;
case Cpp:
case JavaScript:
case TypeScript:
builder.append(StringUtils.format("buffer.writeCharArray({});", objectStr)).append(LS);
break;
default:
flag = false;
}
break;
default:
if (arrayField.getArrayElementRegistration() instanceof ObjectProtocolField) {
var protocolId = ((ObjectProtocolField) arrayField.getArrayElementRegistration()).getProtocolId();
Expand Down Expand Up @@ -1015,68 +961,6 @@ public String readObject(StringBuilder builder, Field field, IFieldRegistration
flag = false;
}
break;
case "char":
switch (language) {
case Enhance:
builder.append(StringUtils.format("{}[] {} = {}.readCharArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS);
break;
case Python:
builder.append(StringUtils.format("{} = buffer.readCharArray()", array)).append(LS);
break;
case Lua:
builder.append(StringUtils.format("local {} = buffer:readCharArray()", array)).append(LS);
break;
case CSharp:
builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS);
break;
case Go:
builder.append(StringUtils.format("var {} = buffer.ReadCharArray()", array)).append(LS);
break;
case Cpp:
builder.append(StringUtils.format("auto {} = buffer.readCharArray();", array)).append(LS);
break;
case JavaScript:
case TypeScript:
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
break;
default:
flag = false;
}
break;
case "Character":
switch (language) {
case Enhance:
builder.append(StringUtils.format("{}[] {} = {}.readCharBoxArray($1);", arrayName, array, EnhanceUtils.byteBufUtils));
break;
case GdScript:
builder.append(StringUtils.format("var {} = buffer.readCharArray()", array)).append(LS);
break;
case Python:
builder.append(StringUtils.format("{} = buffer.readCharArray()", array)).append(LS);
break;
case Lua:
builder.append(StringUtils.format("local {} = buffer:readCharArray()", array)).append(LS);
break;
case CSharp:
builder.append(StringUtils.format("var {} = buffer.ReadCharArray();", array)).append(LS);
break;
case Go:
builder.append(StringUtils.format("var {} = buffer.ReadCharArray()", array)).append(LS);
break;
case Cpp:
builder.append(StringUtils.format("auto {} = buffer.readCharArray();", array)).append(LS);
break;
case JavaScript:
case TypeScript:
builder.append(StringUtils.format("const {} = buffer.readCharArray();", array)).append(LS);
break;
default:
flag = false;
}
break;
default:
if (arrayField.getArrayElementRegistration() instanceof ObjectProtocolField) {
var protocolId = ((ObjectProtocolField) arrayField.getArrayElementRegistration()).getProtocolId();
Expand Down

0 comments on commit 289a0a0

Please sign in to comment.