code: def VarintEncode(value):
    
    result = b""
    if value < 0:
      raise ValueError("Varint can not encode a negative number.")
  
    bits = value & 0x7f
    value >>= 7
  
    while value:
      result += HIGH_CHR_MAP[bits]
      bits = value & 0x7f
      value >>= 7
  
    result += CHR_MAP[bits]
  
    return result
docs: Convert an integer to a varint and write it using the write function.