From dd370d224fb390b93d62d89f697572ac53160cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=99=A8=E8=BF=91?= Date: Wed, 23 Dec 2020 18:20:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8@Repeatable=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A4=9A=E7=89=88=E6=9C=AC=E6=B3=A8=E8=A7=A3=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yezhihao/protostar/annotation/Field.java | 6 ++---- .../yezhihao/protostar/multiversion/Test.java | 15 ++++++++------- .../io/github/yezhihao/protostar/simple/Test.java | 5 +++-- 3 files changed, 13 insertions(+), 13 deletions(-) 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 c2cb4ad..67db46d 100644 --- a/src/main/java/io/github/yezhihao/protostar/annotation/Field.java +++ b/src/main/java/io/github/yezhihao/protostar/annotation/Field.java @@ -2,15 +2,13 @@ package io.github.yezhihao.protostar.annotation; import io.github.yezhihao.protostar.DataType; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import java.lang.annotation.*; /** * @author yezhihao * home https://gitee.com/yezhihao/jt808-server */ +@Repeatable(Fs.class) @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface Field { diff --git a/src/test/java/io/github/yezhihao/protostar/multiversion/Test.java b/src/test/java/io/github/yezhihao/protostar/multiversion/Test.java index a59b9be..f95676f 100644 --- a/src/test/java/io/github/yezhihao/protostar/multiversion/Test.java +++ b/src/test/java/io/github/yezhihao/protostar/multiversion/Test.java @@ -4,7 +4,6 @@ import io.github.yezhihao.protostar.DataType; import io.github.yezhihao.protostar.ProtostarUtil; import io.github.yezhihao.protostar.Schema; import io.github.yezhihao.protostar.annotation.Field; -import io.github.yezhihao.protostar.annotation.Fs; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -20,11 +19,12 @@ public class Test { Schema schema_v1 = multiVersionSchema.get(1); ByteBuf buffer = Unpooled.buffer(32); - schema_v0.writeTo(buffer, foo()); + Foo foo = foo(); + schema_v0.writeTo(buffer, foo); String hex = ByteBufUtil.hexDump(buffer); System.out.println(hex); - Foo foo = schema_v0.readFrom(buffer); + foo = schema_v0.readFrom(buffer); System.out.println(foo); System.out.println("=========================version: 0"); @@ -52,8 +52,8 @@ public class Test { private int id; private LocalDateTime dateTime; - @Fs({@Field(index = 0, type = DataType.STRING, lengthSize = 1, desc = "名称", version = 0), - @Field(index = 0, type = DataType.STRING, length = 10, desc = "名称", version = 1)}) + @Field(index = 0, type = DataType.STRING, lengthSize = 1, desc = "名称", version = 0) + @Field(index = 0, type = DataType.STRING, length = 10, desc = "名称", version = 1) public String getName() { return name; } @@ -62,8 +62,8 @@ public class Test { this.name = name; } - @Fs({@Field(index = 1, type = DataType.WORD, desc = "ID", version = 0), - @Field(index = 1, type = DataType.DWORD, desc = "ID", version = 1)}) + @Field(index = 1, type = DataType.WORD, desc = "ID", version = 0) + @Field(index = 1, type = DataType.DWORD, desc = "ID", version = 1) public int getId() { return id; } @@ -72,6 +72,7 @@ public class Test { this.id = id; } + @Field(index = 3, type = DataType.BCD8421, desc = "日期", version = {0, 1}) @Field(index = 3, type = DataType.BCD8421, desc = "日期", version = {0, 1}) public LocalDateTime getDateTime() { return dateTime; diff --git a/src/test/java/io/github/yezhihao/protostar/simple/Test.java b/src/test/java/io/github/yezhihao/protostar/simple/Test.java index 49671f4..ba2271a 100644 --- a/src/test/java/io/github/yezhihao/protostar/simple/Test.java +++ b/src/test/java/io/github/yezhihao/protostar/simple/Test.java @@ -21,11 +21,12 @@ public class Test { Schema schema = multiVersionSchema.get(0); ByteBuf buffer = Unpooled.buffer(32); - schema.writeTo(buffer, foo()); + Foo foo = foo(); + schema.writeTo(buffer, foo); String hex = ByteBufUtil.hexDump(buffer); System.out.println(hex); - Foo foo = schema.readFrom(buffer); + foo = schema.readFrom(buffer); System.out.println(foo); }