int readVarint32 ( ) { byte b ; // negative number implies MSB set if ( ( b = readByte ( ) ) >= 0 ) { return b ; } int result = b & 0x7f ; if ( ( b = readByte ( ) ) >= 0 ) { return result | b << 7 ; } result |= ( b & 0x7f ) << 7 ; if ( ( b = readByte ( ) ) >= 0 ) { return result | b << 14 ; } result |= ( b & 0x7f ) << 14 ; if ( ( b = readByte ( ) ) >= 0 ) { return result | b << 21 ; } result |= ( b & 0x7f ) << 21 ; b = readByte ( ) ; if ( ( b & 0xf0 ) != 0 ) { throw new IllegalArgumentException ( "Greater than 32-bit varint at position " + ( pos ( ) - 1 ) ) ; } return result | b << 28 ; }
included in the main api as this is used commonly for example reading proto tags