增加变长字符串的长度域的日志打印

master
剑器近 2021-09-19 21:01:43 +08:00
parent d42c6409c8
commit a802097a21
1 changed files with 13 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package io.github.yezhihao.protostar.field;
import io.github.yezhihao.protostar.Schema;
import io.github.yezhihao.protostar.annotation.Field;
import io.github.yezhihao.protostar.util.ByteBufUtils;
import io.github.yezhihao.protostar.util.StrUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
@ -61,14 +62,17 @@ public class DynamicLengthField<T> extends BasicField<T> {
int before = input.readerIndex();
int length = ByteBufUtils.readInt(input, lengthSize);
String hex = StrUtils.leftPad(Integer.toHexString(length), lengthSize << 1, '0');
println(this.index, this.field.desc() + "长度", hex, length);
if (!input.isReadable(length))
return false;
Object value = schema.readFrom(input, length);
f.set(message, value);
int after = input.readerIndex();
String hex = ByteBufUtil.hexDump(input.slice(before, after - before));
println(this.index, this.field.desc(), hex, value);
hex = ByteBufUtil.hexDump(input.slice(before + lengthSize, after - before - lengthSize));
println(this.index + lengthSize, this.field.desc(), hex, value);
return true;
}
@ -85,8 +89,13 @@ public class DynamicLengthField<T> extends BasicField<T> {
}
int after = output.writerIndex();
String hex = ByteBufUtil.hexDump(output.slice(before, after - before));
println(this.index, this.field.desc(), hex, value);
int length = ByteBufUtils.getInt(output, before, lengthSize);
String hex = StrUtils.leftPad(Integer.toHexString(length), lengthSize << 1, '0');
println(this.index, this.field.desc() + "长度", hex, length);
hex = ByteBufUtil.hexDump(output.slice(before + lengthSize, after - before - lengthSize));
println(this.index + lengthSize, this.field.desc(), hex, value);
}
}
}