text: //
  // Autogenerated by Thrift Compiler (0.10.0)
  //
  // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
  //
  "use strict";
  
  var thrift = require('thrift');
  var Thrift = thrift.Thrift;
  var Q = thrift.Q;
  
  var common_ttypes = require('./common_types');
  
  
  var BaseService = require('./BaseService');
  var BaseServiceClient = BaseService.Client;
  var BaseServiceProcessor = BaseService.Processor;
  var ttypes = require('./sftp_types');
  //HELPER FUNCTIONS AND STRUCTURES
  
  var PublicSFTPService_deleteObject_args = function(args) {
    this.ctx = null;
    this.ID = null;
    if (args) {
      if (args.ctx !== undefined && args.ctx !== null) {
        this.ctx = new common_ttypes.Context(args.ctx);
      }
      if (args.ID !== undefined && args.ID !== null) {
        this.ID = args.ID;
      }
    }
  };
  PublicSFTPService_deleteObject_args.prototype = {};
  PublicSFTPService_deleteObject_args.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.ctx = new common_ttypes.Context();
          this.ctx.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 2:
        if (ftype == Thrift.Type.STRING) {
          this.ID = input.readString();
        } else {
          input.skip(ftype);
        }
        break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_deleteObject_args.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_deleteObject_args');
    if (this.ctx !== null && this.ctx !== undefined) {
      output.writeFieldBegin('ctx', Thrift.Type.STRUCT, 1);
      this.ctx.write(output);
      output.writeFieldEnd();
    }
    if (this.ID !== null && this.ID !== undefined) {
      output.writeFieldBegin('ID', Thrift.Type.STRING, 2);
      output.writeString(this.ID);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPService_deleteObject_result = function(args) {
    this.err = null;
    if (args instanceof common_ttypes.Error) {
      this.err = args;
      return;
    }
    if (args) {
      if (args.err !== undefined && args.err !== null) {
        this.err = args.err;
      }
    }
  };
  PublicSFTPService_deleteObject_result.prototype = {};
  PublicSFTPService_deleteObject_result.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.err = new common_ttypes.Error();
          this.err.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 0:
          input.skip(ftype);
          break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_deleteObject_result.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_deleteObject_result');
    if (this.err !== null && this.err !== undefined) {
      output.writeFieldBegin('err', Thrift.Type.STRUCT, 1);
      this.err.write(output);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPService_renameObject_args = function(args) {
    this.ctx = null;
    this.ID = null;
    this.newName = null;
    if (args) {
      if (args.ctx !== undefined && args.ctx !== null) {
        this.ctx = new common_ttypes.Context(args.ctx);
      }
      if (args.ID !== undefined && args.ID !== null) {
        this.ID = args.ID;
      }
      if (args.newName !== undefined && args.newName !== null) {
        this.newName = args.newName;
      }
    }
  };
  PublicSFTPService_renameObject_args.prototype = {};
  PublicSFTPService_renameObject_args.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.ctx = new common_ttypes.Context();
          this.ctx.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 2:
        if (ftype == Thrift.Type.STRING) {
          this.ID = input.readString();
        } else {
          input.skip(ftype);
        }
        break;
        case 3:
        if (ftype == Thrift.Type.STRING) {
          this.newName = input.readString();
        } else {
          input.skip(ftype);
        }
        break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_renameObject_args.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_renameObject_args');
    if (this.ctx !== null && this.ctx !== undefined) {
      output.writeFieldBegin('ctx', Thrift.Type.STRUCT, 1);
      this.ctx.write(output);
      output.writeFieldEnd();
    }
    if (this.ID !== null && this.ID !== undefined) {
      output.writeFieldBegin('ID', Thrift.Type.STRING, 2);
      output.writeString(this.ID);
      output.writeFieldEnd();
    }
    if (this.newName !== null && this.newName !== undefined) {
      output.writeFieldBegin('newName', Thrift.Type.STRING, 3);
      output.writeString(this.newName);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPService_renameObject_result = function(args) {
    this.err = null;
    if (args instanceof common_ttypes.Error) {
      this.err = args;
      return;
    }
    if (args) {
      if (args.err !== undefined && args.err !== null) {
        this.err = args.err;
      }
    }
  };
  PublicSFTPService_renameObject_result.prototype = {};
  PublicSFTPService_renameObject_result.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.err = new common_ttypes.Error();
          this.err.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 0:
          input.skip(ftype);
          break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_renameObject_result.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_renameObject_result');
    if (this.err !== null && this.err !== undefined) {
      output.writeFieldBegin('err', Thrift.Type.STRUCT, 1);
      this.err.write(output);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPService_moveToWorkspace_args = function(args) {
    this.ctx = null;
    this.ID = null;
    this.parentID = null;
    if (args) {
      if (args.ctx !== undefined && args.ctx !== null) {
        this.ctx = new common_ttypes.Context(args.ctx);
      }
      if (args.ID !== undefined && args.ID !== null) {
        this.ID = args.ID;
      }
      if (args.parentID !== undefined && args.parentID !== null) {
        this.parentID = args.parentID;
      }
    }
  };
  PublicSFTPService_moveToWorkspace_args.prototype = {};
  PublicSFTPService_moveToWorkspace_args.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.ctx = new common_ttypes.Context();
          this.ctx.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 2:
        if (ftype == Thrift.Type.STRING) {
          this.ID = input.readString();
        } else {
          input.skip(ftype);
        }
        break;
        case 3:
        if (ftype == Thrift.Type.STRING) {
          this.parentID = input.readString();
        } else {
          input.skip(ftype);
        }
        break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_moveToWorkspace_args.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_moveToWorkspace_args');
    if (this.ctx !== null && this.ctx !== undefined) {
      output.writeFieldBegin('ctx', Thrift.Type.STRUCT, 1);
      this.ctx.write(output);
      output.writeFieldEnd();
    }
    if (this.ID !== null && this.ID !== undefined) {
      output.writeFieldBegin('ID', Thrift.Type.STRING, 2);
      output.writeString(this.ID);
      output.writeFieldEnd();
    }
    if (this.parentID !== null && this.parentID !== undefined) {
      output.writeFieldBegin('parentID', Thrift.Type.STRING, 3);
      output.writeString(this.parentID);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPService_moveToWorkspace_result = function(args) {
    this.success = null;
    this.err = null;
    if (args instanceof common_ttypes.Error) {
      this.err = args;
      return;
    }
    if (args) {
      if (args.success !== undefined && args.success !== null) {
        this.success = Thrift.copyList(args.success, [ttypes.MoveFileInfo]);
      }
      if (args.err !== undefined && args.err !== null) {
        this.err = args.err;
      }
    }
  };
  PublicSFTPService_moveToWorkspace_result.prototype = {};
  PublicSFTPService_moveToWorkspace_result.prototype.read = function(input) {
    input.readStructBegin();
    while (true)
    {
      var ret = input.readFieldBegin();
      var fname = ret.fname;
      var ftype = ret.ftype;
      var fid = ret.fid;
      if (ftype == Thrift.Type.STOP) {
        break;
      }
      switch (fid)
      {
        case 0:
        if (ftype == Thrift.Type.LIST) {
          var _size0 = 0;
          var _rtmp34;
          this.success = [];
          var _etype3 = 0;
          _rtmp34 = input.readListBegin();
          _etype3 = _rtmp34.etype;
          _size0 = _rtmp34.size;
          for (var _i5 = 0; _i5 < _size0; ++_i5)
          {
            var elem6 = null;
            elem6 = new ttypes.MoveFileInfo();
            elem6.read(input);
            this.success.push(elem6);
          }
          input.readListEnd();
        } else {
          input.skip(ftype);
        }
        break;
        case 1:
        if (ftype == Thrift.Type.STRUCT) {
          this.err = new common_ttypes.Error();
          this.err.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  PublicSFTPService_moveToWorkspace_result.prototype.write = function(output) {
    output.writeStructBegin('PublicSFTPService_moveToWorkspace_result');
    if (this.success !== null && this.success !== undefined) {
      output.writeFieldBegin('success', Thrift.Type.LIST, 0);
      output.writeListBegin(Thrift.Type.STRUCT, this.success.length);
      for (var iter7 in this.success)
      {
        if (this.success.hasOwnProperty(iter7))
        {
          iter7 = this.success[iter7];
          iter7.write(output);
        }
      }
      output.writeListEnd();
      output.writeFieldEnd();
    }
    if (this.err !== null && this.err !== undefined) {
      output.writeFieldBegin('err', Thrift.Type.STRUCT, 1);
      this.err.write(output);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var PublicSFTPServiceClient = exports.Client = function(output, pClass) {
      this.output = output;
      this.pClass = pClass;
      this._seqid = 0;
      this._reqs = {};
  };
  Thrift.inherits(PublicSFTPServiceClient, BaseServiceClient);
  PublicSFTPServiceClient.prototype.seqid = function() { return this._seqid; };
  PublicSFTPServiceClient.prototype.new_seqid = function() { return this._seqid += 1; };
  PublicSFTPServiceClient.prototype.deleteObject = function(ctx, ID, callback) {
    this._seqid = this.new_seqid();
    if (callback === undefined) {
      var _defer = Q.defer();
      this._reqs[this.seqid()] = function(error, result) {
        if (error) {
          _defer.reject(error);
        } else {
          _defer.resolve(result);
        }
      };
      this.send_deleteObject(ctx, ID);
      return _defer.promise;
    } else {
      this._reqs[this.seqid()] = callback;
      this.send_deleteObject(ctx, ID);
    }
  };
  
  PublicSFTPServiceClient.prototype.send_deleteObject = function(ctx, ID) {
    var output = new this.pClass(this.output);
    output.writeMessageBegin('deleteObject', Thrift.MessageType.CALL, this.seqid());
    var args = new PublicSFTPService_deleteObject_args();
    args.ctx = ctx;
    args.ID = ID;
    args.write(output);
    output.writeMessageEnd();
    return this.output.flush();
  };
  
  PublicSFTPServiceClient.prototype.recv_deleteObject = function(input,mtype,rseqid) {
    var callback = this._reqs[rseqid] || function() {};
    delete this._reqs[rseqid];
    if (mtype == Thrift.MessageType.EXCEPTION) {
      var x = new Thrift.TApplicationException();
      x.read(input);
      input.readMessageEnd();
      return callback(x);
    }
    var result = new PublicSFTPService_deleteObject_result();
    result.read(input);
    input.readMessageEnd();
  
    if (null !== result.err) {
      return callback(result.err);
    }
    callback(null);
  };
  PublicSFTPServiceClient.prototype.renameObject = function(ctx, ID, newName, callback) {
    this._seqid = this.new_seqid();
    if (callback === undefined) {
      var _defer = Q.defer();
      this._reqs[this.seqid()] = function(error, result) {
        if (error) {
          _defer.reject(error);
        } else {
          _defer.resolve(result);
        }
      };
      this.send_renameObject(ctx, ID, newName);
      return _defer.promise;
    } else {
      this._reqs[this.seqid()] = callback;
      this.send_renameObject(ctx, ID, newName);
    }
  };
  
  PublicSFTPServiceClient.prototype.send_renameObject = function(ctx, ID, newName) {
    var output = new this.pClass(this.output);
    output.writeMessageBegin('renameObject', Thrift.MessageType.CALL, this.seqid());
    var args = new PublicSFTPService_renameObject_args();
    args.ctx = ctx;
    args.ID = ID;
    args.newName = newName;
    args.write(output);
    output.writeMessageEnd();
    return this.output.flush();
  };
  
  PublicSFTPServiceClient.prototype.recv_renameObject = function(input,mtype,rseqid) {
    var callback = this._reqs[rseqid] || function() {};
    delete this._reqs[rseqid];
    if (mtype == Thrift.MessageType.EXCEPTION) {
      var x = new Thrift.TApplicationException();
      x.read(input);
      input.readMessageEnd();
      return callback(x);
    }
    var result = new PublicSFTPService_renameObject_result();
    result.read(input);
    input.readMessageEnd();
  
    if (null !== result.err) {
      return callback(result.err);
    }
    callback(null);
  };
  PublicSFTPServiceClient.prototype.moveToWorkspace = function(ctx, ID, parentID, callback) {
    this._seqid = this.new_seqid();
    if (callback === undefined) {
      var _defer = Q.defer();
      this._reqs[this.seqid()] = function(error, result) {
        if (error) {
          _defer.reject(error);
        } else {
          _defer.resolve(result);
        }
      };
      this.send_moveToWorkspace(ctx, ID, parentID);
      return _defer.promise;
    } else {
      this._reqs[this.seqid()] = callback;
      this.send_moveToWorkspace(ctx, ID, parentID);
    }
  };
  
  PublicSFTPServiceClient.prototype.send_moveToWorkspace = function(ctx, ID, parentID) {
    var output = new this.pClass(this.output);
    output.writeMessageBegin('moveToWorkspace', Thrift.MessageType.CALL, this.seqid());
    var args = new PublicSFTPService_moveToWorkspace_args();
    args.ctx = ctx;
    args.ID = ID;
    args.parentID = parentID;
    args.write(output);
    output.writeMessageEnd();
    return this.output.flush();
  };
  
  PublicSFTPServiceClient.prototype.recv_moveToWorkspace = function(input,mtype,rseqid) {
    var callback = this._reqs[rseqid] || function() {};
    delete this._reqs[rseqid];
    if (mtype == Thrift.MessageType.EXCEPTION) {
      var x = new Thrift.TApplicationException();
      x.read(input);
      input.readMessageEnd();
      return callback(x);
    }
    var result = new PublicSFTPService_moveToWorkspace_result();
    result.read(input);
    input.readMessageEnd();
  
    if (null !== result.err) {
      return callback(result.err);
    }
    if (null !== result.success) {
      return callback(null, result.success);
    }
    return callback('moveToWorkspace failed: unknown result');
  };
  var PublicSFTPServiceProcessor = exports.Processor = function(handler) {
    this._handler = handler;
  }
  ;
  Thrift.inherits(PublicSFTPServiceProcessor, BaseServiceProcessor);
  PublicSFTPServiceProcessor.prototype.process = function(input, output) {
    var r = input.readMessageBegin();
    if (this['process_' + r.fname]) {
      return this['process_' + r.fname].call(this, r.rseqid, input, output);
    } else {
      input.skip(Thrift.Type.STRUCT);
      input.readMessageEnd();
      var x = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN_METHOD, 'Unknown function ' + r.fname);
      output.writeMessageBegin(r.fname, Thrift.MessageType.EXCEPTION, r.rseqid);
      x.write(output);
      output.writeMessageEnd();
      output.flush();
    }
  }
  ;
  PublicSFTPServiceProcessor.prototype.process_deleteObject = function(seqid, input, output) {
    var args = new PublicSFTPService_deleteObject_args();
    args.read(input);
    input.readMessageEnd();
    if (this._handler.deleteObject.length === 2) {
      Q.fcall(this._handler.deleteObject, args.ctx, args.ID)
        .then(function(result) {
          var result_obj = new PublicSFTPService_deleteObject_result({success: result});
          output.writeMessageBegin("deleteObject", Thrift.MessageType.REPLY, seqid);
          result_obj.write(output);
          output.writeMessageEnd();
          output.flush();
        }, function (err) {
          var result;
          if (err instanceof common_ttypes.Error) {
            result = new PublicSFTPService_deleteObject_result(err);
            output.writeMessageBegin("deleteObject", Thrift.MessageType.REPLY, seqid);
          } else {
            result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
            output.writeMessageBegin("deleteObject", Thrift.MessageType.EXCEPTION, seqid);
          }
          result.write(output);
          output.writeMessageEnd();
          output.flush();
        });
    } else {
      this._handler.deleteObject(args.ctx, args.ID, function (err, result) {
        var result_obj;
        if ((err === null || typeof err === 'undefined') || err instanceof common_ttypes.Error) {
          result_obj = new PublicSFTPService_deleteObject_result((err !== null || typeof err === 'undefined') ? err : {success: result});
          output.writeMessageBegin("deleteObject", Thrift.MessageType.REPLY, seqid);
        } else {
          result_obj = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
          output.writeMessageBegin("deleteObject", Thrift.MessageType.EXCEPTION, seqid);
        }
        result_obj.write(output);
        output.writeMessageEnd();
        output.flush();
      });
    }
  };
  PublicSFTPServiceProcessor.prototype.process_renameObject = function(seqid, input, output) {
    var args = new PublicSFTPService_renameObject_args();
    args.read(input);
    input.readMessageEnd();
    if (this._handler.renameObject.length === 3) {
      Q.fcall(this._handler.renameObject, args.ctx, args.ID, args.newName)
        .then(function(result) {
          var result_obj = new PublicSFTPService_renameObject_result({success: result});
          output.writeMessageBegin("renameObject", Thrift.MessageType.REPLY, seqid);
          result_obj.write(output);
          output.writeMessageEnd();
          output.flush();
        }, function (err) {
          var result;
          if (err instanceof common_ttypes.Error) {
            result = new PublicSFTPService_renameObject_result(err);
            output.writeMessageBegin("renameObject", Thrift.MessageType.REPLY, seqid);
          } else {
            result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
            output.writeMessageBegin("renameObject", Thrift.MessageType.EXCEPTION, seqid);
          }
          result.write(output);
          output.writeMessageEnd();
          output.flush();
        });
    } else {
      this._handler.renameObject(args.ctx, args.ID, args.newName, function (err, result) {
        var result_obj;
        if ((err === null || typeof err === 'undefined') || err instanceof common_ttypes.Error) {
          result_obj = new PublicSFTPService_renameObject_result((err !== null || typeof err === 'undefined') ? err : {success: result});
          output.writeMessageBegin("renameObject", Thrift.MessageType.REPLY, seqid);
        } else {
          result_obj = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
          output.writeMessageBegin("renameObject", Thrift.MessageType.EXCEPTION, seqid);
        }
        result_obj.write(output);
        output.writeMessageEnd();
        output.flush();
      });
    }
  };
  PublicSFTPServiceProcessor.prototype.process_moveToWorkspace = function(seqid, input, output) {
    var args = new PublicSFTPService_moveToWorkspace_args();
    args.read(input);
    input.readMessageEnd();
    if (this._handler.moveToWorkspace.length === 3) {
      Q.fcall(this._handler.moveToWorkspace, args.ctx, args.ID, args.parentID)
        .then(function(result) {
          var result_obj = new PublicSFTPService_moveToWorkspace_result({success: result});
          output.writeMessageBegin("moveToWorkspace", Thrift.MessageType.REPLY, seqid);
          result_obj.write(output);
          output.writeMessageEnd();
          output.flush();
        }, function (err) {
          var result;
          if (err instanceof common_ttypes.Error) {
            result = new PublicSFTPService_moveToWorkspace_result(err);
            output.writeMessageBegin("moveToWorkspace", Thrift.MessageType.REPLY, seqid);
          } else {
            result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
            output.writeMessageBegin("moveToWorkspace", Thrift.MessageType.EXCEPTION, seqid);
          }
          result.write(output);
          output.writeMessageEnd();
          output.flush();
        });
    } else {
      this._handler.moveToWorkspace(args.ctx, args.ID, args.parentID, function (err, result) {
        var result_obj;
        if ((err === null || typeof err === 'undefined') || err instanceof common_ttypes.Error) {
          result_obj = new PublicSFTPService_moveToWorkspace_result((err !== null || typeof err === 'undefined') ? err : {success: result});
          output.writeMessageBegin("moveToWorkspace", Thrift.MessageType.REPLY, seqid);
        } else {
          result_obj = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
          output.writeMessageBegin("moveToWorkspace", Thrift.MessageType.EXCEPTION, seqid);
        }
        result_obj.write(output);
        output.writeMessageEnd();
        output.flush();
      });
    }
  };
  