Encodes an integer in the HPACK prefix format. This method assumes that the buffer has already had the first 8-n bits filled. As such it will modify the last byte that is already present in the buffer, and potentially add more if required @param source The buffer that contains the integer @par
(ByteBuffer source, int value, int n)
| 202 | * @param n The encoding prefix length |
| 203 | */ |
| 204 | static void encodeInteger(ByteBuffer source, int value, int n) { |
| 205 | int twoNminus1 = PREFIX_TABLE[n]; |
| 206 | int pos = source.position() - 1; |
| 207 | if (value < twoNminus1) { |
| 208 | source.put(pos, (byte) (source.get(pos) | value)); |
| 209 | } else { |
| 210 | source.put(pos, (byte) (source.get(pos) | twoNminus1)); |
| 211 | value = value - twoNminus1; |
| 212 | while (value >= 128) { |
| 213 | source.put((byte) (value % 128 + 128)); |
| 214 | value = value / 128; |
| 215 | } |
| 216 | source.put((byte) value); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | /* |
| 221 | * Unused. Will be removed in Tomcat 12 onwards. |
no test coverage detected