From a802097a21b831edbb9cd8fe7095d2d87b8154da 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 21:01:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=98=E9=95=BF=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2=E7=9A=84=E9=95=BF=E5=BA=A6=E5=9F=9F=E7=9A=84?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protostar/field/DynamicLengthField.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/io/github/yezhihao/protostar/field/DynamicLengthField.java b/src/main/java/io/github/yezhihao/protostar/field/DynamicLengthField.java index afc7473..2b68394 100644 --- a/src/main/java/io/github/yezhihao/protostar/field/DynamicLengthField.java +++ b/src/main/java/io/github/yezhihao/protostar/field/DynamicLengthField.java @@ -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 extends BasicField { 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 extends BasicField { } 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); } } } \ No newline at end of file