diff --git a/pom.xml b/pom.xml
index bb65b9a..6b386bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
io.github.yezhihao
protostar
- 2.0.1.RELEASE
+ 2.0.2.RELEASE
jar
Protostar
diff --git a/src/main/java/io/github/yezhihao/protostar/DataType.java b/src/main/java/io/github/yezhihao/protostar/DataType.java
index 7b0d667..98a1b33 100644
--- a/src/main/java/io/github/yezhihao/protostar/DataType.java
+++ b/src/main/java/io/github/yezhihao/protostar/DataType.java
@@ -7,25 +7,25 @@ package io.github.yezhihao.protostar;
*/
public enum DataType {
- //无符号单字节整型(字节, 8位)
+ /** 无符号单字节整型(8位) */
BYTE(1),
- //无符号双字节整型(字节,16位)
+ /** 无符号双字节整型(16位) */
WORD(2),
- //无符号四字节整型(字节,32位)
+ /** 无符号四字节整型(32位) */
DWORD(4),
- //无符号八字节整型(字节,64位)
+ /** 无符号八字节整型(64位) */
QWORD(8),
- //N字节,字节数组
+ /** 字节数组 */
BYTES(-1),
- //N字节,BCD8421码
+ /** BCD8421码 */
BCD8421(-1),
- //字符串,若无数据置空
+ /** 字符串 */
STRING(-1),
- //对象
+ /** 对象 */
OBJ(-1),
- //列表
+ /** 列表 */
LIST(-1),
- //字典
+ /** 字典 */
MAP(-1);
public int length;
diff --git a/src/main/java/io/github/yezhihao/protostar/FieldFactory.java b/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
index 5f7a260..63d34f9 100644
--- a/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
+++ b/src/main/java/io/github/yezhihao/protostar/FieldFactory.java
@@ -1,14 +1,11 @@
package io.github.yezhihao.protostar;
-import io.github.yezhihao.protostar.annotation.Convert;
import io.github.yezhihao.protostar.annotation.Field;
import io.github.yezhihao.protostar.field.BasicField;
import io.github.yezhihao.protostar.field.DynamicLengthField;
import io.github.yezhihao.protostar.field.FixedField;
import io.github.yezhihao.protostar.field.FixedLengthField;
import io.github.yezhihao.protostar.schema.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.time.LocalDateTime;
@@ -19,7 +16,7 @@ import java.time.LocalDateTime;
* home https://gitee.com/yezhihao/jt808-server
*/
public abstract class FieldFactory {
- protected static Logger log = LoggerFactory.getLogger(FieldFactory.class.getSimpleName());
+
public static boolean EXPLAIN = false;
public static BasicField create(Field field, java.lang.reflect.Field f) {
@@ -59,19 +56,16 @@ public abstract class FieldFactory {
fieldSchema = StringSchema.Chars.getInstance(field.pad(), field.charset());
break;
case OBJ:
- if (schema != null) {
+ if (schema != null)
fieldSchema = ObjectSchema.getInstance(schema);
- } else {
- Convert convert = f.getAnnotation(Convert.class);
- fieldSchema = ConvertSchema.getInstance(convert.converter());
- }
+ else
+ fieldSchema = ConvertSchema.getInstance(field.converter());
break;
case LIST:
fieldSchema = CollectionSchema.getInstance(schema);
break;
case MAP:
- Convert convert = f.getAnnotation(Convert.class);
- fieldSchema = ConvertSchema.getInstance(convert.converter());
+ fieldSchema = ConvertSchema.getInstance(field.converter());
break;
default:
throw new RuntimeException("不支持的类型转换");
diff --git a/src/main/java/io/github/yezhihao/protostar/annotation/Convert.java b/src/main/java/io/github/yezhihao/protostar/annotation/Convert.java
deleted file mode 100644
index 3f93d04..0000000
--- a/src/main/java/io/github/yezhihao/protostar/annotation/Convert.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package io.github.yezhihao.protostar.annotation;
-
-import io.github.yezhihao.protostar.converter.Converter;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * 启用自定义消息转换
- * @author yezhihao
- * home https://gitee.com/yezhihao/jt808-server
- */
-@Target(ElementType.FIELD)
-@Retention(RetentionPolicy.RUNTIME)
-public @interface Convert {
-
- Class extends Converter> converter();
-
-}
\ No newline at end of file
diff --git a/src/main/java/io/github/yezhihao/protostar/annotation/Field.java b/src/main/java/io/github/yezhihao/protostar/annotation/Field.java
index 22281d5..2d13217 100644
--- a/src/main/java/io/github/yezhihao/protostar/annotation/Field.java
+++ b/src/main/java/io/github/yezhihao/protostar/annotation/Field.java
@@ -1,6 +1,7 @@
package io.github.yezhihao.protostar.annotation;
import io.github.yezhihao.protostar.DataType;
+import io.github.yezhihao.protostar.converter.Converter;
import java.lang.annotation.*;
@@ -23,9 +24,11 @@ public @interface Field {
String charset() default "GBK";
- byte pad() default 0x00;
+ byte pad() default 0;
String desc() default "";
int[] version() default {-1, 0, 1};
+
+ Class extends Converter> converter() default Converter.class;
}
\ No newline at end of file
diff --git a/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java b/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java
index 9a83bba..5cb14b9 100644
--- a/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java
+++ b/src/main/java/io/github/yezhihao/protostar/converter/MapConverter.java
@@ -1,12 +1,18 @@
package io.github.yezhihao.protostar.converter;
+import io.github.yezhihao.protostar.PrepareLoadStrategy;
+import io.github.yezhihao.protostar.Schema;
import io.github.yezhihao.protostar.util.ByteBufUtils;
import io.netty.buffer.ByteBuf;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.TreeMap;
-public abstract class MapConverter implements Converter