//
// Autogenerated by Thrift Compiler (0.9.1)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
var Thrift = require('../lib/thrift').Thrift;

var ttypes = require('./api_upload_types');
//HELPER FUNCTIONS AND STRUCTURES

UploadSvc_upload_log_args = function(args) {
  this.message = null;
  if (args) {
    if (args.message !== undefined) {
      this.message = args.message;
    }
  }
};
UploadSvc_upload_log_args.prototype = {};
UploadSvc_upload_log_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.STRING) {
        this.message = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_upload_log_args.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_upload_log_args');
  if (this.message !== null && this.message !== undefined) {
    output.writeFieldBegin('message', Thrift.Type.STRING, 1);
    output.writeString(this.message);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_upload_log_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined) {
      this.success = args.success;
    }
  }
};
UploadSvc_upload_log_result.prototype = {};
UploadSvc_upload_log_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.STRING) {
        this.success = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_upload_log_result.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_upload_log_result');
  if (this.success !== null && this.success !== undefined) {
    output.writeFieldBegin('success', Thrift.Type.STRING, 0);
    output.writeString(this.success);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_test_connect_args = function(args) {
};
UploadSvc_test_connect_args.prototype = {};
UploadSvc_test_connect_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;
    }
    input.skip(ftype);
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_test_connect_args.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_test_connect_args');
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_test_connect_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined) {
      this.success = args.success;
    }
  }
};
UploadSvc_test_connect_result.prototype = {};
UploadSvc_test_connect_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.STRING) {
        this.success = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_test_connect_result.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_test_connect_result');
  if (this.success !== null && this.success !== undefined) {
    output.writeFieldBegin('success', Thrift.Type.STRING, 0);
    output.writeString(this.success);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_get_by_id_args = function(args) {
  this.id = null;
  if (args) {
    if (args.id !== undefined) {
      this.id = args.id;
    }
  }
};
UploadSvc_get_by_id_args.prototype = {};
UploadSvc_get_by_id_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.STRING) {
        this.id = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_get_by_id_args.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_get_by_id_args');
  if (this.id !== null && this.id !== undefined) {
    output.writeFieldBegin('id', Thrift.Type.STRING, 1);
    output.writeString(this.id);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_get_by_id_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined) {
      this.success = args.success;
    }
  }
};
UploadSvc_get_by_id_result.prototype = {};
UploadSvc_get_by_id_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.STRING) {
        this.success = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_get_by_id_result.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_get_by_id_result');
  if (this.success !== null && this.success !== undefined) {
    output.writeFieldBegin('success', Thrift.Type.STRING, 0);
    output.writeString(this.success);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_search_log_args = function(args) {
  this.text = null;
  if (args) {
    if (args.text !== undefined) {
      this.text = args.text;
    }
  }
};
UploadSvc_search_log_args.prototype = {};
UploadSvc_search_log_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.STRING) {
        this.text = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_search_log_args.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_search_log_args');
  if (this.text !== null && this.text !== undefined) {
    output.writeFieldBegin('text', Thrift.Type.STRING, 1);
    output.writeString(this.text);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_search_log_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined) {
      this.success = args.success;
    }
  }
};
UploadSvc_search_log_result.prototype = {};
UploadSvc_search_log_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 = input.readString();
          this.success.push(elem6);
        }
        input.readListEnd();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_search_log_result.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_search_log_result');
  if (this.success !== null && this.success !== undefined) {
    output.writeFieldBegin('success', Thrift.Type.LIST, 0);
    output.writeListBegin(Thrift.Type.STRING, this.success.length);
    for (var iter7 in this.success)
    {
      if (this.success.hasOwnProperty(iter7))
      {
        iter7 = this.success[iter7];
        output.writeString(iter7);
      }
    }
    output.writeListEnd();
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_get_token_args = function(args) {
};
UploadSvc_get_token_args.prototype = {};
UploadSvc_get_token_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;
    }
    input.skip(ftype);
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_get_token_args.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_get_token_args');
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvc_get_token_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined) {
      this.success = args.success;
    }
  }
};
UploadSvc_get_token_result.prototype = {};
UploadSvc_get_token_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.STRING) {
        this.success = input.readString();
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

UploadSvc_get_token_result.prototype.write = function(output) {
  output.writeStructBegin('UploadSvc_get_token_result');
  if (this.success !== null && this.success !== undefined) {
    output.writeFieldBegin('success', Thrift.Type.STRING, 0);
    output.writeString(this.success);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

UploadSvcClient = exports.Client = function(output, pClass) {
    this.output = output;
    this.pClass = pClass;
    this.seqid = 0;
    this._reqs = {};
};
UploadSvcClient.prototype = {};
UploadSvcClient.prototype.upload_log = function(message, callback) {
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
  this.send_upload_log(message);
};

UploadSvcClient.prototype.send_upload_log = function(message) {
  var output = new this.pClass(this.output);
  output.writeMessageBegin('upload_log', Thrift.MessageType.CALL, this.seqid);
  var args = new UploadSvc_upload_log_args();
  args.message = message;
  args.write(output);
  output.writeMessageEnd();
  return this.output.flush();
};

UploadSvcClient.prototype.recv_upload_log = 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 UploadSvc_upload_log_result();
  result.read(input);
  input.readMessageEnd();

  if (null !== result.success) {
    return callback(null, result.success);
  }
  return callback('upload_log failed: unknown result');
};
UploadSvcClient.prototype.test_connect = function(callback) {
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
  this.send_test_connect();
};

UploadSvcClient.prototype.send_test_connect = function() {
  var output = new this.pClass(this.output);
  output.writeMessageBegin('test_connect', Thrift.MessageType.CALL, this.seqid);
  var args = new UploadSvc_test_connect_args();
  args.write(output);
  output.writeMessageEnd();
  return this.output.flush();
};

UploadSvcClient.prototype.recv_test_connect = 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 UploadSvc_test_connect_result();
  result.read(input);
  input.readMessageEnd();

  if (null !== result.success) {
    return callback(null, result.success);
  }
  return callback('test_connect failed: unknown result');
};
UploadSvcClient.prototype.get_by_id = function(id, callback) {
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
  this.send_get_by_id(id);
};

UploadSvcClient.prototype.send_get_by_id = function(id) {
  var output = new this.pClass(this.output);
  output.writeMessageBegin('get_by_id', Thrift.MessageType.CALL, this.seqid);
  var args = new UploadSvc_get_by_id_args();
  args.id = id;
  args.write(output);
  output.writeMessageEnd();
  return this.output.flush();
};

UploadSvcClient.prototype.recv_get_by_id = 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 UploadSvc_get_by_id_result();
  result.read(input);
  input.readMessageEnd();

  if (null !== result.success) {
    return callback(null, result.success);
  }
  return callback('get_by_id failed: unknown result');
};
UploadSvcClient.prototype.search_log = function(text, callback) {
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
  this.send_search_log(text);
};

UploadSvcClient.prototype.send_search_log = function(text) {
  var output = new this.pClass(this.output);
  output.writeMessageBegin('search_log', Thrift.MessageType.CALL, this.seqid);
  var args = new UploadSvc_search_log_args();
  args.text = text;
  args.write(output);
  output.writeMessageEnd();
  return this.output.flush();
};

UploadSvcClient.prototype.recv_search_log = 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 UploadSvc_search_log_result();
  result.read(input);
  input.readMessageEnd();

  if (null !== result.success) {
    return callback(null, result.success);
  }
  return callback('search_log failed: unknown result');
};
UploadSvcClient.prototype.get_token = function(callback) {
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
  this.send_get_token();
};

UploadSvcClient.prototype.send_get_token = function() {
  var output = new this.pClass(this.output);
  output.writeMessageBegin('get_token', Thrift.MessageType.CALL, this.seqid);
  var args = new UploadSvc_get_token_args();
  args.write(output);
  output.writeMessageEnd();
  return this.output.flush();
};

UploadSvcClient.prototype.recv_get_token = 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 UploadSvc_get_token_result();
  result.read(input);
  input.readMessageEnd();

  if (null !== result.success) {
    return callback(null, result.success);
  }
  return callback('get_token failed: unknown result');
};
UploadSvcProcessor = exports.Processor = function(handler) {
  this._handler = handler
}
UploadSvcProcessor.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();
  }
}

UploadSvcProcessor.prototype.process_upload_log = function(seqid, input, output) {
  var args = new UploadSvc_upload_log_args();
  args.read(input);
  input.readMessageEnd();
  this._handler.upload_log(args.message, function (err, result) {
    var result = new UploadSvc_upload_log_result((err != null ? err : {success: result}));
    output.writeMessageBegin("upload_log", Thrift.MessageType.REPLY, seqid);
    result.write(output);
    output.writeMessageEnd();
    output.flush();
  })
}

UploadSvcProcessor.prototype.process_test_connect = function(seqid, input, output) {
  var args = new UploadSvc_test_connect_args();
  args.read(input);
  input.readMessageEnd();
  this._handler.test_connect(function (err, result) {
    var result = new UploadSvc_test_connect_result((err != null ? err : {success: result}));
    output.writeMessageBegin("test_connect", Thrift.MessageType.REPLY, seqid);
    result.write(output);
    output.writeMessageEnd();
    output.flush();
  })
}

UploadSvcProcessor.prototype.process_get_by_id = function(seqid, input, output) {
  var args = new UploadSvc_get_by_id_args();
  args.read(input);
  input.readMessageEnd();
  this._handler.get_by_id(args.id, function (err, result) {
    var result = new UploadSvc_get_by_id_result((err != null ? err : {success: result}));
    output.writeMessageBegin("get_by_id", Thrift.MessageType.REPLY, seqid);
    result.write(output);
    output.writeMessageEnd();
    output.flush();
  })
}

UploadSvcProcessor.prototype.process_search_log = function(seqid, input, output) {
  var args = new UploadSvc_search_log_args();
  args.read(input);
  input.readMessageEnd();
  this._handler.search_log(args.text, function (err, result) {
    var result = new UploadSvc_search_log_result((err != null ? err : {success: result}));
    output.writeMessageBegin("search_log", Thrift.MessageType.REPLY, seqid);
    result.write(output);
    output.writeMessageEnd();
    output.flush();
  })
}

UploadSvcProcessor.prototype.process_get_token = function(seqid, input, output) {
  var args = new UploadSvc_get_token_args();
  args.read(input);
  input.readMessageEnd();
  this._handler.get_token(function (err, result) {
    var result = new UploadSvc_get_token_result((err != null ? err : {success: result}));
    output.writeMessageBegin("get_token", Thrift.MessageType.REPLY, seqid);
    result.write(output);
    output.writeMessageEnd();
    output.flush();
  })
}

