def encode_integer(integer, prefix_bits):
 max_number = ((2 ** prefix_bits) - 1)
 if (integer < max_number):
  return bytearray([integer])
 else:
  elements = [max_number]
  integer = (integer - max_number)
  while (integer >= 128):
   elements.append(((integer % 128) + 128))
   integer = (integer // 128)
  elements.append(integer)
  return bytearray(elements)

def encode_integer ( integer , prefix_bits ) : max_number = ( ( 2 ** prefix_bits ) - 1 ) if ( integer < max_number ) : return bytearray ( [ integer ] ) else : elements = [ max_number ] integer = ( integer - max_number ) while ( integer >= 128 ) : elements . append ( ( ( integer % 128 ) + 128 ) ) integer = ( integer // 128 ) elements . append ( integer ) return bytearray ( elements )
this encodes an integer according to the wacky integer encoding rules defined in the hpack spec .