question: public static int encodeLength ( int len ) { if ( len <= 32 ) { return 0 ; } int code = Integer . numberOfLeadingZeros ( len ) ; int remaining = len << ( code + 1 ) ; code += code ; if ( ( remaining & ( 1 << 31 ) ) != 0 ) { code -- ; } if ( ( remaining << 1 ) != 0 ) { code -- ; } code = Math . min ( 31 , 52 - code ) ; return code ; }
target:  Convert the length to a length code 0..31. 31 means more than 1 MB.