VLQ { public static int encodedSize(int value) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int i = 1; while ((value & 0xFFFFFF80) != 0L) { value >>>= 7; i++; } return i; }  static void encode(int value, ByteBuffer out); static int decode(ReadBuffer in); static int encodedSize(int value);  }
@Test public void testEncodedSize() throws Exception { assertThat(VLQ.encodedSize(0x7F), is(1)); assertThat(VLQ.encodedSize(0x80), is(2)); assertThat(VLQ.encodedSize(0x2000), is(2)); assertThat(VLQ.encodedSize(0x3FFF), is(2)); assertThat(VLQ.encodedSize(0x4000), is(3)); assertThat(VLQ.encodedSize(0x1FFFFF), is(3)); assertThat(VLQ.encodedSize(0x200000), is(4)); assertThat(VLQ.encodedSize(0x08000000), is(4)); assertThat(VLQ.encodedSize(0x0FFFFFFF), is(4)); assertThat(VLQ.encodedSize(Integer.MAX_VALUE), is(5)); }
@Test(expected = IllegalArgumentException.class) public void testEncodedSizeNegativeValueFails() throws Exception { VLQ.encodedSize(-1); }