@Test public void testVarintSize() { int numtests = 1000; Random r = new Random(0); for (int i = 0; i < 5; i++) { int min = (int) Math.pow(2, 7 * i); int max = (int) Math.min(Integer.MAX_VALUE, Math.pow(2, 7 * (i + 1))); for (int j = 0; j < numtests; j++) { int value = r.nextInt(max - min) + min; assertEquals(i + 1, ProtobufVarint.sizeOf(value)); } } }
public static int sizeOf(int value) { int numBytes = 0; do { value >>= 7; numBytes++; } while (value != 0); return numBytes; }
ProtobufVarint { public static int sizeOf(int value) { int numBytes = 0; do { value >>= 7; numBytes++; } while (value != 0); return numBytes; } }
ProtobufVarint { public static int sizeOf(int value) { int numBytes = 0; do { value >>= 7; numBytes++; } while (value != 0); return numBytes; } private  ProtobufVarint(); }
ProtobufVarint { public static int sizeOf(int value) { int numBytes = 0; do { value >>= 7; numBytes++; } while (value != 0); return numBytes; } private  ProtobufVarint(); static int readRawVarint32(InputStream in); static int readRawVarint32(ByteBuffer b); static void writeRawVarint32(ByteBuffer buf, int value); static void writeRawVarint32(OutputStream out, int value); static int sizeOf(int value); }
ProtobufVarint { public static int sizeOf(int value) { int numBytes = 0; do { value >>= 7; numBytes++; } while (value != 0); return numBytes; } private  ProtobufVarint(); static int readRawVarint32(InputStream in); static int readRawVarint32(ByteBuffer b); static void writeRawVarint32(ByteBuffer buf, int value); static void writeRawVarint32(OutputStream out, int value); static int sizeOf(int value);  }