@Test public void testEncode() throws Exception { checkEncoding(0x7F, 0x7F); checkEncoding(0x80, 0x81, 0x00); checkEncoding(0x2000, 0xC0, 0x00); checkEncoding(0x3FFF, 0xFF, 0x7F); checkEncoding(0x4000, 0x81, 0x80, 0x00); checkEncoding(0x1FFFFF, 0xFF, 0xFF, 0x7F); checkEncoding(0x200000, 0x81, 0x80, 0x80, 0x00); checkEncoding(0x08000000, 0xC0, 0x80, 0x80, 0x00); checkEncoding(0x0FFFFFFF, 0xFF, 0xFF, 0xFF, 0x7F); checkEncoding(Integer.MAX_VALUE, 0x87, 0xFF, 0xFF, 0xFF, 0x7F); }
public static void encode(int value, ByteBuffer out) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int b; boolean msbFound = false; b = ((value & 0x70000000) >> 28); if (b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0xFE00000) >> 21); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x1FC000) >> 14); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x3F80) >> 7); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); } b = (value & 0x7F); out.put((byte) (b)); }
VLQ { public static void encode(int value, ByteBuffer out) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int b; boolean msbFound = false; b = ((value & 0x70000000) >> 28); if (b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0xFE00000) >> 21); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x1FC000) >> 14); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x3F80) >> 7); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); } b = (value & 0x7F); out.put((byte) (b)); } }
VLQ { public static void encode(int value, ByteBuffer out) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int b; boolean msbFound = false; b = ((value & 0x70000000) >> 28); if (b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0xFE00000) >> 21); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x1FC000) >> 14); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x3F80) >> 7); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); } b = (value & 0x7F); out.put((byte) (b)); }  }
VLQ { public static void encode(int value, ByteBuffer out) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int b; boolean msbFound = false; b = ((value & 0x70000000) >> 28); if (b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0xFE00000) >> 21); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x1FC000) >> 14); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x3F80) >> 7); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); } b = (value & 0x7F); out.put((byte) (b)); }  static void encode(int value, ByteBuffer out); static int decode(ReadBuffer in); static int encodedSize(int value); }
VLQ { public static void encode(int value, ByteBuffer out) { if (value < 0) { throw new IllegalArgumentException("Cannot encode negative values"); } int b; boolean msbFound = false; b = ((value & 0x70000000) >> 28); if (b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0xFE00000) >> 21); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x1FC000) >> 14); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); msbFound = true; } b = ((value & 0x3F80) >> 7); if (msbFound || b != 0) { out.put(((byte) (b | 0x80))); } b = (value & 0x7F); out.put((byte) (b)); }  static void encode(int value, ByteBuffer out); static int decode(ReadBuffer in); static int encodedSize(int value);  }