def decode_integer(data, prefix_bits):
 multiple = (lambda index: (128 ** (index - 1)))
 max_number = ((2 ** prefix_bits) - 1)
 mask = (255 >> (8 - prefix_bits))
 index = 0
 number = (to_byte(data[index]) & mask)
 if (number == max_number):
  while True:
   index += 1
   next_byte = to_byte(data[index])
   if (next_byte >= 128):
    number += ((next_byte - 128) * multiple(index))
   else:
    number += (next_byte * multiple(index))
    break
 return (number, (index + 1))

def decode_integer ( data , prefix_bits ) : multiple = ( lambda index : ( 128 ** ( index - 1 ) ) ) max_number = ( ( 2 ** prefix_bits ) - 1 ) mask = ( 255 >> ( 8 - prefix_bits ) ) index = 0 number = ( to_byte ( data [ index ] ) & mask ) if ( number == max_number ) : while True : index += 1 next_byte = to_byte ( data [ index ] ) if ( next_byte >= 128 ) : number += ( ( next_byte - 128 ) * multiple ( index ) ) else : number += ( next_byte * multiple ( index ) ) break return ( number , ( index + 1 ) )
this decodes an integer according to the wacky integer encoding rules defined in the hpack spec .