import struct


def encode_varint(number):
	"""
	Write a VarInt to a string.
	
	:param number: Number to encode as a VarInt.
	:return: The encoded VarInt.
	"""
	# Python ints are variable length, which means there's no fixed size.
	# Typical programming language implementation exploits the sign bit moving
	# when doing bitwise shifts, but that's not possible here.
	# To force an int32-like type, we use the `struct` module to make it fit.
	number = struct.unpack(">I", struct.pack(">i", number))[0]
	out = b""
	while True:
		part = number & 0x7f
		number = number >> 7
		if number != 0:
			part |= 0x80  # In-place OR operation
			out += part.to_bytes(1, byteorder="big")
		else:
			out += part.to_bytes(1, byteorder="big")
			return out