def encode(i: int) ->bytes:
    """Return the varint bytes encoding of an integer."""
    if i <= 252:
        return bytes([i])
    elif i <= 65535:
        return b'\xfd' + i.to_bytes(2, byteorder='little')
    elif i <= 4294967295:
        return b'\xfe' + i.to_bytes(4, byteorder='little')
    elif i <= 18446744073709551615:
        return b'\xff' + i.to_bytes(8, byteorder='little')
    else:
        raise ValueError(f'integer too large ({hex(i)}) for varint encoding')
