deployed 2.0.6.RELEASE,修复集合类型长度域BUG

master
剑器近 2021-09-19 17:52:14 +08:00
parent 44050e72ce
commit d42c6409c8
3 changed files with 11 additions and 10 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.yezhihao</groupId>
<artifactId>protostar</artifactId>
<version>2.0.5.RELEASE</version>
<version>2.0.6.RELEASE</version>
<packaging>jar</packaging>
<name>Protostar</name>

View File

@ -33,8 +33,7 @@ public class DynamicTotalField<T> extends BasicField<T> {
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<T> extends BasicField<T> {
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);
}
}
}

View File

@ -38,6 +38,8 @@ public class CollectionSchema<T> implements Schema<Collection<T>> {
@Override
public Collection<T> readFrom(ByteBuf input, int totalSize) {
int total = ByteBufUtils.readInt(input, totalSize);
if (total <= 0)
return null;
Collection<T> list = new ArrayList<>(total);
for (int i = 0; i < total; i++) {
T obj = schema.readFrom(input);
@ -58,8 +60,10 @@ public class CollectionSchema<T> implements Schema<Collection<T>> {
@Override
public void writeTo(ByteBuf output, int totalSize, Collection<T> 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) {