From d42c6409c882be622900702ee7c2f9c5c7e1a9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=89=91=E5=99=A8=E8=BF=91?= Date: Sun, 19 Sep 2021 17:52:14 +0800 Subject: [PATCH] =?UTF-8?q?deployed=202.0.6.RELEASE=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=9B=86=E5=90=88=E7=B1=BB=E5=9E=8B=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E5=9F=9FBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../yezhihao/protostar/field/DynamicTotalField.java | 13 +++++-------- .../yezhihao/protostar/schema/CollectionSchema.java | 6 +++++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 330f944..d24f9f4 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.github.yezhihao protostar - 2.0.5.RELEASE + 2.0.6.RELEASE jar Protostar diff --git a/src/main/java/io/github/yezhihao/protostar/field/DynamicTotalField.java b/src/main/java/io/github/yezhihao/protostar/field/DynamicTotalField.java index 2ebbdf2..eaa24e5 100644 --- a/src/main/java/io/github/yezhihao/protostar/field/DynamicTotalField.java +++ b/src/main/java/io/github/yezhihao/protostar/field/DynamicTotalField.java @@ -33,8 +33,7 @@ public class DynamicTotalField extends BasicField { public void writeTo(ByteBuf output, Object message) throws Exception { Collection value = (Collection) f.get(message); - if (value != null) - schema.writeTo(output, totalSize, value); + schema.writeTo(output, totalSize, value); } @Override @@ -63,14 +62,12 @@ public class DynamicTotalField extends BasicField { public void writeTo(ByteBuf output, Object message) throws Exception { Collection value = (Collection) f.get(message); - if (value != null) { - int total = value.size(); - String hex = StrUtils.leftPad(Integer.toHexString(total), totalSize << 1, '0'); - println(this.index, this.field.desc() + "总数", hex, total); + int total = value == null ? 0 : value.size(); + String hex = StrUtils.leftPad(Integer.toHexString(total), totalSize << 1, '0'); + println(this.index, this.field.desc() + "总数", hex, total); - schema.writeTo(output, totalSize, value); - } + schema.writeTo(output, totalSize, value); } } } \ No newline at end of file diff --git a/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java b/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java index 71771c2..ec73325 100644 --- a/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java +++ b/src/main/java/io/github/yezhihao/protostar/schema/CollectionSchema.java @@ -38,6 +38,8 @@ public class CollectionSchema implements Schema> { @Override public Collection readFrom(ByteBuf input, int totalSize) { int total = ByteBufUtils.readInt(input, totalSize); + if (total <= 0) + return null; Collection list = new ArrayList<>(total); for (int i = 0; i < total; i++) { T obj = schema.readFrom(input); @@ -58,8 +60,10 @@ public class CollectionSchema implements Schema> { @Override public void writeTo(ByteBuf output, int totalSize, Collection list) { - if (list == null || list.isEmpty()) + if (list == null || list.isEmpty()) { + ByteBufUtils.writeInt(output, totalSize, 0); return; + } ByteBufUtils.writeInt(output, totalSize, list.size()); for (T obj : list) {