private static int readRawVarint32 ( ByteBuf buffer ) { if ( ! buffer . isReadable ( ) ) { return 0 ; } buffer . markReaderIndex ( ) ; byte tmp = buffer . readByte ( ) ; if ( tmp >= 0 ) { return tmp ; } else { int result = tmp & 127 ; if ( ! buffer . isReadable ( ) ) { buffer . resetReaderIndex ( ) ; return 0 ; } if ( ( tmp = buffer . readByte ( ) ) >= 0 ) { result |= tmp << 7 ; } else { result |= ( tmp & 127 ) << 7 ; if ( ! buffer . isReadable ( ) ) { buffer . resetReaderIndex ( ) ; return 0 ; } if ( ( tmp = buffer . readByte ( ) ) >= 0 ) { result |= tmp << 14 ; } else { result |= ( tmp & 127 ) << 14 ; if ( ! buffer . isReadable ( ) ) { buffer . resetReaderIndex ( ) ; return 0 ; } if ( ( tmp = buffer . readByte ( ) ) >= 0 ) { result |= tmp << 21 ; } else { result |= ( tmp & 127 ) << 21 ; if ( ! buffer . isReadable ( ) ) { buffer . resetReaderIndex ( ) ; return 0 ; } result |= ( tmp = buffer . readByte ( ) ) << 28 ; if ( tmp < 0 ) { throw new CorruptedFrameException ( "malformed varint." ) ; } } } } return result ; } }
Reads variable length 32bit int from buffer