private void assertReadVarint(byte[] data,long value) throws Exception {
  CodedInputStream input=CodedInputStream.newInstance(data);
  assertEquals((int)value,input.readRawVarint32());
  assertDataConsumed(data,input);
  input=CodedInputStream.newInstance(data);
  assertEquals(value,input.readRawVarint64());
  assertDataConsumed(data,input);
  input=CodedInputStream.newInstance(data);
  assertEquals(value,input.readRawVarint64SlowPath());
  assertDataConsumed(data,input);
  input=CodedInputStream.newInstance(data);
  assertTrue(input.skipField(WireFormat.WIRETYPE_VARINT));
  assertDataConsumed(data,input);
  for (int blockSize=1; blockSize <= 16; blockSize*=2) {
    input=CodedInputStream.newInstance(new SmallBlockInputStream(data,blockSize));
    assertEquals((int)value,input.readRawVarint32());
    assertDataConsumed(data,input);
    input=CodedInputStream.newInstance(new SmallBlockInputStream(data,blockSize));
    assertEquals(value,input.readRawVarint64());
    assertDataConsumed(data,input);
    input=CodedInputStream.newInstance(new SmallBlockInputStream(data,blockSize));
    assertEquals(value,input.readRawVarint64SlowPath());
    assertDataConsumed(data,input);
    input=CodedInputStream.newInstance(new SmallBlockInputStream(data,blockSize));
    assertTrue(input.skipField(WireFormat.WIRETYPE_VARINT));
    assertDataConsumed(data,input);
  }
  byte[] longerData=new byte[data.length + 1];
  System.arraycopy(data,0,longerData,0,data.length);
  InputStream rawInput=new ByteArrayInputStream(longerData);
  assertEquals((int)value,CodedInputStream.readRawVarint32(rawInput));
  assertEquals(1,rawInput.available());
}

private void assertReadVarint ( byte [ ] data , long value ) throws Exception { CodedInputStream input = CodedInputStream . newInstance ( data ) ; assertEquals ( ( int ) value , input . readRawVarint32 ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( data ) ; assertEquals ( value , input . readRawVarint64 ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( data ) ; assertEquals ( value , input . readRawVarint64SlowPath ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( data ) ; assertTrue ( input . skipField ( WireFormat . WIRETYPE_VARINT ) ) ; assertDataConsumed ( data , input ) ; for ( int blockSize = 1 ; blockSize <= 16 ; blockSize *= 2 ) { input = CodedInputStream . newInstance ( new SmallBlockInputStream ( data , blockSize ) ) ; assertEquals ( ( int ) value , input . readRawVarint32 ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( new SmallBlockInputStream ( data , blockSize ) ) ; assertEquals ( value , input . readRawVarint64 ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( new SmallBlockInputStream ( data , blockSize ) ) ; assertEquals ( value , input . readRawVarint64SlowPath ( ) ) ; assertDataConsumed ( data , input ) ; input = CodedInputStream . newInstance ( new SmallBlockInputStream ( data , blockSize ) ) ; assertTrue ( input . skipField ( WireFormat . WIRETYPE_VARINT ) ) ; assertDataConsumed ( data , input ) ; } byte [ ] longerData = new byte [ data . length + 1 ] ; System . arraycopy ( data , 0 , longerData , 0 , data . length ) ; InputStream rawInput = new ByteArrayInputStream ( longerData ) ; assertEquals ( ( int ) value , CodedInputStream . readRawVarint32 ( rawInput ) ) ; assertEquals ( 1 , rawInput . available ( ) ) ; }
parses the given bytes using readrawvarint32 ( ) and readrawvarint64 ( ) and checks that the result matches the given value .
