From dbdcd944d4aa1cddf62153f5ab006e2dbf706df4 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Mon, 7 Jun 2021 20:02:12 +0800 Subject: [PATCH] =?UTF-8?q?fix[protocol]:=20=E4=BF=AE=E5=A4=8Dlong?= =?UTF-8?q?=E7=AC=AC5=E4=BD=8D=E5=86=99=E5=85=A5=E5=A4=9A=E4=B8=80?= =?UTF-8?q?=E4=BD=8D=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zfoo/protocol/buffer/ByteBufUtils.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java index 102e83ba..fc9f3c85 100644 --- a/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java +++ b/protocol/src/main/java/com/zfoo/protocol/buffer/ByteBufUtils.java @@ -203,16 +203,9 @@ public abstract class ByteBufUtils { bytes[index++] = (byte) (mask >>> 7 | 0x80); bytes[index++] = (byte) (mask >>> 14 | 0x80); bytes[index++] = (byte) (mask >>> 21 | 0x80); - bytes[index++] = (byte) (mask >>> 28 | 0x80); - - int a = (int) (mask >>> 35); - if (a == 0) { - byteBuf.writeBytes(bytes, 0, index); - return; - } - - int b = (int) (mask >>> 42); + int a = (int) (mask >>> 28); + int b = (int) (mask >>> 35); if (b == 0) { bytes[index++] = (byte) a; byteBuf.writeBytes(bytes, 0, index); @@ -220,7 +213,7 @@ public abstract class ByteBufUtils { } bytes[index++] = (byte) (a | 0x80); - a = (int) (mask >>> 49); + a = (int) (mask >>> 42); if (a == 0) { bytes[index++] = (byte) b; byteBuf.writeBytes(bytes, 0, index); @@ -228,7 +221,7 @@ public abstract class ByteBufUtils { } bytes[index++] = (byte) (b | 0x80); - b = (int) (mask >>> 56); + b = (int) (mask >>> 49); if (b == 0) { bytes[index++] = (byte) a; byteBuf.writeBytes(bytes, 0, index); @@ -236,10 +229,19 @@ public abstract class ByteBufUtils { } bytes[index++] = (byte) (a | 0x80); - bytes[index++] = (byte) b; + a = (int) (mask >>> 56); + if (a == 0) { + bytes[index++] = (byte) b; + byteBuf.writeBytes(bytes, 0, index); + return; + } + + bytes[index++] = (byte) (b | 0x80); + bytes[index++] = (byte) a; byteBuf.writeBytes(bytes, 0, index); } + public static long readLong(ByteBuf byteBuf) { int readIndex = byteBuf.readerIndex(); long b = byteBuf.getByte(readIndex++);