fix[protocol]: 修复long第5位写入多一位的问题

This commit is contained in:
jaysunxiao
2021-06-07 20:02:12 +08:00
parent aae5582f9f
commit dbdcd944d4
@@ -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++);