@Test public void testDecodeRemainingLength() { m_buff.writeByte(0x0); assertEquals(0, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeByte(0x007F); assertEquals(127, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0x80, (byte)0x01}); assertEquals(128, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0xFF, (byte)0x7F}); assertEquals(16383, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0x80, (byte)0x80, (byte)0x01}); assertEquals(16384, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0xFF, (byte)0xFF, (byte)0x7F}); assertEquals(2097151, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0x80, (byte)0x80, (byte)0x80, (byte)0x01}); assertEquals(2097152, Utils.decodeRemainingLenght(m_buff)); m_buff.clear().writeBytes(new byte[]{(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0x7F}); assertEquals(268435455, Utils.decodeRemainingLenght(m_buff)); }
static int decodeRemainingLenght(ByteBuf in) { int multiplier = 1; int value = 0; byte digit; do { if (in.readableBytes() < 1) { return -1; } digit = in.readByte(); value += (digit & 0x7F) * multiplier; multiplier *= 128; } while ((digit & 0x80) != 0); return value; }
Utils { static int decodeRemainingLenght(ByteBuf in) { int multiplier = 1; int value = 0; byte digit; do { if (in.readableBytes() < 1) { return -1; } digit = in.readByte(); value += (digit & 0x7F) * multiplier; multiplier *= 128; } while ((digit & 0x80) != 0); return value; } }
Utils { static int decodeRemainingLenght(ByteBuf in) { int multiplier = 1; int value = 0; byte digit; do { if (in.readableBytes() < 1) { return -1; } digit = in.readByte(); value += (digit & 0x7F) * multiplier; multiplier *= 128; } while ((digit & 0x80) != 0); return value; }  }
Utils { static int decodeRemainingLenght(ByteBuf in) { int multiplier = 1; int value = 0; byte digit; do { if (in.readableBytes() < 1) { return -1; } digit = in.readByte(); value += (digit & 0x7F) * multiplier; multiplier *= 128; } while ((digit & 0x80) != 0); return value; }   }
Utils { static int decodeRemainingLenght(ByteBuf in) { int multiplier = 1; int value = 0; byte digit; do { if (in.readableBytes() < 1) { return -1; } digit = in.readByte(); value += (digit & 0x7F) * multiplier; multiplier *= 128; } while ((digit & 0x80) != 0); return value; }   static final int MAX_LENGTH_LIMIT; }