@Test public void testSize3Varint() { final int size = 3; final int num = 0x4000; assertThat(ProtobufVarint32LengthFieldPrepender.computeRawVarint32Size(num), is(size)); final byte[] buf = new byte[size + num]; buf[0] = (byte) (0x80 & 0xFF); buf[1] = (byte) (0x80 & 0xFF); buf[2] = 0x01; for (int i = size; i < num + size; ++i) { buf[i] = 1; } assertTrue(ch.writeOutbound(wrappedBuffer(buf, size, buf.length - size))); ByteBuf expected = wrappedBuffer(buf); ByteBuf actual = ch.readOutbound(); assertThat(expected, is(actual)); assertFalse(ch.finish()); expected.release(); actual.release(); }
static int computeRawVarint32Size(final int value) { if ((value & (0xffffffff << 7)) == 0) { return 1; } if ((value & (0xffffffff << 14)) == 0) { return 2; } if ((value & (0xffffffff << 21)) == 0) { return 3; } if ((value & (0xffffffff << 28)) == 0) { return 4; } return 5; }
ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> { static int computeRawVarint32Size(final int value) { if ((value & (0xffffffff << 7)) == 0) { return 1; } if ((value & (0xffffffff << 14)) == 0) { return 2; } if ((value & (0xffffffff << 21)) == 0) { return 3; } if ((value & (0xffffffff << 28)) == 0) { return 4; } return 5; } }
ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> { static int computeRawVarint32Size(final int value) { if ((value & (0xffffffff << 7)) == 0) { return 1; } if ((value & (0xffffffff << 14)) == 0) { return 2; } if ((value & (0xffffffff << 21)) == 0) { return 3; } if ((value & (0xffffffff << 28)) == 0) { return 4; } return 5; }  }
ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> { static int computeRawVarint32Size(final int value) { if ((value & (0xffffffff << 7)) == 0) { return 1; } if ((value & (0xffffffff << 14)) == 0) { return 2; } if ((value & (0xffffffff << 21)) == 0) { return 3; } if ((value & (0xffffffff << 28)) == 0) { return 4; } return 5; }   }
ProtobufVarint32LengthFieldPrepender extends MessageToByteEncoder<ByteBuf> { static int computeRawVarint32Size(final int value) { if ((value & (0xffffffff << 7)) == 0) { return 1; } if ((value & (0xffffffff << 14)) == 0) { return 2; } if ((value & (0xffffffff << 21)) == 0) { return 3; } if ((value & (0xffffffff << 28)) == 0) { return 4; } return 5; }    }