//
// Autogenerated by Thrift Compiler (0.13.0)
//
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
//
if (typeof Int64 === 'undefined' && typeof require === 'function') {
  var Int64 = require('node-int64');
}


//HELPER FUNCTIONS AND STRUCTURES

EditorPlugin_get_client_args = function(args) {
  this.codeChat_client_location = null;
  if (args) {
    if (args.codeChat_client_location !== undefined && args.codeChat_client_location !== null) {
      this.codeChat_client_location = args.codeChat_client_location;
    }
  }
};
EditorPlugin_get_client_args.prototype = {};
EditorPlugin_get_client_args.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    var ftype = ret.ftype;
    var fid = ret.fid;
    if (ftype == Thrift.Type.STOP) {
      break;
    }
    switch (fid) {
      case 1:
      if (ftype == Thrift.Type.I32) {
        this.codeChat_client_location = input.readI32().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

EditorPlugin_get_client_args.prototype.write = function(output) {
  output.writeStructBegin('EditorPlugin_get_client_args');
  if (this.codeChat_client_location !== null && this.codeChat_client_location !== undefined) {
    output.writeFieldBegin('codeChat_client_location', Thrift.Type.I32, 1);
    output.writeI32(this.codeChat_client_location);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

EditorPlugin_get_client_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined && args.success !== null) {
      this.success = new RenderClientReturn(args.success);
    }
  }
};
EditorPlugin_get_client_result.prototype = {};
EditorPlugin_get_client_result.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    var ftype = ret.ftype;
    var fid = ret.fid;
    if (ftype == Thrift.Type.STOP) {
      break;
    }
    switch (fid) {
      case 0:
      if (ftype == Thrift.Type.STRUCT) {
        this.success = new RenderClientReturn();
        this.success.read(input);
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

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

EditorPlugin_start_render_args = function(args) {
  this.text = null;
  this.path = null;
  this.id = null;
  this.is_dirty = null;
  if (args) {
    if (args.text !== undefined && args.text !== null) {
      this.text = args.text;
    }
    if (args.path !== undefined && args.path !== null) {
      this.path = args.path;
    }
    if (args.id !== undefined && args.id !== null) {
      this.id = args.id;
    }
    if (args.is_dirty !== undefined && args.is_dirty !== null) {
      this.is_dirty = args.is_dirty;
    }
  }
};
EditorPlugin_start_render_args.prototype = {};
EditorPlugin_start_render_args.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    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().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 2:
      if (ftype == Thrift.Type.STRING) {
        this.path = input.readString().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 3:
      if (ftype == Thrift.Type.I32) {
        this.id = input.readI32().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 4:
      if (ftype == Thrift.Type.BOOL) {
        this.is_dirty = input.readBool().value;
      } else {
        input.skip(ftype);
      }
      break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

EditorPlugin_start_render_args.prototype.write = function(output) {
  output.writeStructBegin('EditorPlugin_start_render_args');
  if (this.text !== null && this.text !== undefined) {
    output.writeFieldBegin('text', Thrift.Type.STRING, 1);
    output.writeString(this.text);
    output.writeFieldEnd();
  }
  if (this.path !== null && this.path !== undefined) {
    output.writeFieldBegin('path', Thrift.Type.STRING, 2);
    output.writeString(this.path);
    output.writeFieldEnd();
  }
  if (this.id !== null && this.id !== undefined) {
    output.writeFieldBegin('id', Thrift.Type.I32, 3);
    output.writeI32(this.id);
    output.writeFieldEnd();
  }
  if (this.is_dirty !== null && this.is_dirty !== undefined) {
    output.writeFieldBegin('is_dirty', Thrift.Type.BOOL, 4);
    output.writeBool(this.is_dirty);
    output.writeFieldEnd();
  }
  output.writeFieldStop();
  output.writeStructEnd();
  return;
};

EditorPlugin_start_render_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined && args.success !== null) {
      this.success = args.success;
    }
  }
};
EditorPlugin_start_render_result.prototype = {};
EditorPlugin_start_render_result.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    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().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

EditorPlugin_start_render_result.prototype.write = function(output) {
  output.writeStructBegin('EditorPlugin_start_render_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;
};

EditorPlugin_stop_client_args = function(args) {
  this.id = null;
  if (args) {
    if (args.id !== undefined && args.id !== null) {
      this.id = args.id;
    }
  }
};
EditorPlugin_stop_client_args.prototype = {};
EditorPlugin_stop_client_args.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    var ftype = ret.ftype;
    var fid = ret.fid;
    if (ftype == Thrift.Type.STOP) {
      break;
    }
    switch (fid) {
      case 1:
      if (ftype == Thrift.Type.I32) {
        this.id = input.readI32().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

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

EditorPlugin_stop_client_result = function(args) {
  this.success = null;
  if (args) {
    if (args.success !== undefined && args.success !== null) {
      this.success = args.success;
    }
  }
};
EditorPlugin_stop_client_result.prototype = {};
EditorPlugin_stop_client_result.prototype.read = function(input) {
  input.readStructBegin();
  while (true) {
    var ret = input.readFieldBegin();
    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().value;
      } else {
        input.skip(ftype);
      }
      break;
      case 0:
        input.skip(ftype);
        break;
      default:
        input.skip(ftype);
    }
    input.readFieldEnd();
  }
  input.readStructEnd();
  return;
};

EditorPlugin_stop_client_result.prototype.write = function(output) {
  output.writeStructBegin('EditorPlugin_stop_client_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;
};

EditorPluginClient = function(input, output) {
  this.input = input;
  this.output = (!output) ? input : output;
  this.seqid = 0;
};
EditorPluginClient.prototype = {};

EditorPluginClient.prototype.get_client = function(codeChat_client_location, callback) {
  this.send_get_client(codeChat_client_location, callback); 
  if (!callback) {
    return this.recv_get_client();
  }
};

EditorPluginClient.prototype.send_get_client = function(codeChat_client_location, callback) {
  var params = {
    codeChat_client_location: codeChat_client_location
  };
  var args = new EditorPlugin_get_client_args(params);
  try {
    this.output.writeMessageBegin('get_client', Thrift.MessageType.CALL, this.seqid);
    args.write(this.output);
    this.output.writeMessageEnd();
    if (callback) {
      var self = this;
      this.output.getTransport().flush(true, function() {
        var result = null;
        try {
          result = self.recv_get_client();
        } catch (e) {
          result = e;
        }
        callback(result);
      });
    } else {
      return this.output.getTransport().flush();
    }
  }
  catch (e) {
    if (typeof this.output.getTransport().reset === 'function') {
      this.output.getTransport().reset();
    }
    throw e;
  }
};

EditorPluginClient.prototype.recv_get_client = function() {
  var ret = this.input.readMessageBegin();
  var mtype = ret.mtype;
  if (mtype == Thrift.MessageType.EXCEPTION) {
    var x = new Thrift.TApplicationException();
    x.read(this.input);
    this.input.readMessageEnd();
    throw x;
  }
  var result = new EditorPlugin_get_client_result();
  result.read(this.input);
  this.input.readMessageEnd();

  if (null !== result.success) {
    return result.success;
  }
  throw 'get_client failed: unknown result';
};

EditorPluginClient.prototype.start_render = function(text, path, id, is_dirty, callback) {
  this.send_start_render(text, path, id, is_dirty, callback); 
  if (!callback) {
    return this.recv_start_render();
  }
};

EditorPluginClient.prototype.send_start_render = function(text, path, id, is_dirty, callback) {
  var params = {
    text: text,
    path: path,
    id: id,
    is_dirty: is_dirty
  };
  var args = new EditorPlugin_start_render_args(params);
  try {
    this.output.writeMessageBegin('start_render', Thrift.MessageType.CALL, this.seqid);
    args.write(this.output);
    this.output.writeMessageEnd();
    if (callback) {
      var self = this;
      this.output.getTransport().flush(true, function() {
        var result = null;
        try {
          result = self.recv_start_render();
        } catch (e) {
          result = e;
        }
        callback(result);
      });
    } else {
      return this.output.getTransport().flush();
    }
  }
  catch (e) {
    if (typeof this.output.getTransport().reset === 'function') {
      this.output.getTransport().reset();
    }
    throw e;
  }
};

EditorPluginClient.prototype.recv_start_render = function() {
  var ret = this.input.readMessageBegin();
  var mtype = ret.mtype;
  if (mtype == Thrift.MessageType.EXCEPTION) {
    var x = new Thrift.TApplicationException();
    x.read(this.input);
    this.input.readMessageEnd();
    throw x;
  }
  var result = new EditorPlugin_start_render_result();
  result.read(this.input);
  this.input.readMessageEnd();

  if (null !== result.success) {
    return result.success;
  }
  throw 'start_render failed: unknown result';
};

EditorPluginClient.prototype.stop_client = function(id, callback) {
  this.send_stop_client(id, callback); 
  if (!callback) {
    return this.recv_stop_client();
  }
};

EditorPluginClient.prototype.send_stop_client = function(id, callback) {
  var params = {
    id: id
  };
  var args = new EditorPlugin_stop_client_args(params);
  try {
    this.output.writeMessageBegin('stop_client', Thrift.MessageType.CALL, this.seqid);
    args.write(this.output);
    this.output.writeMessageEnd();
    if (callback) {
      var self = this;
      this.output.getTransport().flush(true, function() {
        var result = null;
        try {
          result = self.recv_stop_client();
        } catch (e) {
          result = e;
        }
        callback(result);
      });
    } else {
      return this.output.getTransport().flush();
    }
  }
  catch (e) {
    if (typeof this.output.getTransport().reset === 'function') {
      this.output.getTransport().reset();
    }
    throw e;
  }
};

EditorPluginClient.prototype.recv_stop_client = function() {
  var ret = this.input.readMessageBegin();
  var mtype = ret.mtype;
  if (mtype == Thrift.MessageType.EXCEPTION) {
    var x = new Thrift.TApplicationException();
    x.read(this.input);
    this.input.readMessageEnd();
    throw x;
  }
  var result = new EditorPlugin_stop_client_result();
  result.read(this.input);
  this.input.readMessageEnd();

  if (null !== result.success) {
    return result.success;
  }
  throw 'stop_client failed: unknown result';
};
