public static int getVarInt ( byte [ ] src , int offset , int [ ] dst ) { int result = 0 ; int shift = 0 ; int b ; do { if ( shift >= 32 ) { // Out of range throw new IndexOutOfBoundsException ( "varint too long" ) ; } // Get 7 bits from next byte b = src [ offset ++ ] ; result |= ( b & 0x7F ) << shift ; shift += 7 ; } while ( ( b & 0x80 ) != 0 ) ; dst [ 0 ] = result ; return offset ; }
Reads a varint from src places its values into the first element of dst and returns the offset in to src of the first byte after the varint .