@Theory public void testWriteReadInteger( @TestedOn(ints = {1, 2, 3, 4, 5, 6, 7, 8}) int n, @TestedOn(ints = {0, 1, 17, 4711, 80087, 22193521}) int i) throws Exception { final int maxMaskBits = 8 - n; for (int maskBits = 0; maskBits < maxMaskBits; maskBits++) { final int mask = 0xFF << (8 - maskBits); final ByteBuf buf = Unpooled.buffer(); writeInteger(buf, mask, n, i); assertThat(Hpack.readInteger(buf, n), is(i)); } }
@Test public void testIntegerSize() throws Exception { for (int n = 1; n <= 8; n++) { for (int i = 0; i < 32; i++) { for (int j = 0; j <= i; j++) { int value = Math.toIntExact((1L << j) - 1); ByteBuf buf = Unpooled.buffer(); Hpack.writeInteger(buf, 0, n, value); int calculatedSize = Hpack.integerSize(n, value); final int actualSize = buf.readableBytes(); assertThat(actualSize, is(calculatedSize)); } } } }
private void writeLiteralHeaderFieldIncrementalIndexingIndexedName( final ByteBuf buf, final int i) { writeInteger(buf, 0x40, 6, i); }