NumberUtils { public static void encodeUnsignedMedium(ByteBuf byteBuf, int i) { requireUnsignedMedium(i); byteBuf.writeByte(i >> 16); byteBuf.writeByte(i >> 8); byteBuf.writeByte(i); } private  NumberUtils(); static int requireNonNegative(int i, String message); static long requirePositive(long l, String message); static int requirePositive(int i, String message); static int requireUnsignedByte(int i); static int requireUnsignedMedium(int i); static int requireUnsignedShort(int i); static void encodeUnsignedMedium(ByteBuf byteBuf, int i); static final int MEDIUM_BYTES; }
@Test void encodeUnsignedMedium() { ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(); NumberUtils.encodeUnsignedMedium(buffer, 129); buffer.markReaderIndex(); assertThat(buffer.readUnsignedMedium()).as("reading as unsigned medium").isEqualTo(129); buffer.resetReaderIndex(); assertThat(buffer.readMedium()).as("reading as signed medium").isEqualTo(129); }
@Test void encodeUnsignedMediumLarge() { ByteBuf buffer = ByteBufAllocator.DEFAULT.buffer(); NumberUtils.encodeUnsignedMedium(buffer, 0xFFFFFC); buffer.markReaderIndex(); assertThat(buffer.readUnsignedMedium()).as("reading as unsigned medium").isEqualTo(16777212); buffer.resetReaderIndex(); assertThat(buffer.readMedium()).as("reading as signed medium").isEqualTo(-4); }