text: //
  // Autogenerated by Thrift Compiler (0.13.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 Int64 = require('node-int64');
  
  
  var ttypes = require('./unpkg_types');
  //HELPER FUNCTIONS AND STRUCTURES
  
  var UnpkgService_Publish_args = function(args) {
    this.req = null;
    if (args) {
      if (args.req !== undefined && args.req !== null) {
        this.req = new ttypes.PublishRequest(args.req);
      }
    }
  };
  UnpkgService_Publish_args.prototype = {};
  UnpkgService_Publish_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.STRUCT) {
          this.req = new ttypes.PublishRequest();
          this.req.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 0:
          input.skip(ftype);
          break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  UnpkgService_Publish_args.prototype.write = function(output) {
    output.writeStructBegin('UnpkgService_Publish_args');
    if (this.req !== null && this.req !== undefined) {
      output.writeFieldBegin('req', Thrift.Type.STRUCT, 1);
      this.req.write(output);
      output.writeFieldEnd();
    }
    output.writeFieldStop();
    output.writeStructEnd();
    return;
  };
  
  var UnpkgService_Publish_result = function(args) {
    this.success = null;
    if (args) {
      if (args.success !== undefined && args.success !== null) {
        this.success = new ttypes.PublishResponse(args.success);
      }
    }
  };
  UnpkgService_Publish_result.prototype = {};
  UnpkgService_Publish_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 ttypes.PublishResponse();
          this.success.read(input);
        } else {
          input.skip(ftype);
        }
        break;
        case 0:
          input.skip(ftype);
          break;
        default:
          input.skip(ftype);
      }
      input.readFieldEnd();
    }
    input.readStructEnd();
    return;
  };
  
  UnpkgService_Publish_result.prototype.write = function(output) {
    output.writeStructBegin('UnpkgService_Publish_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;
  };
  
  var UnpkgServiceClient = exports.Client = function(output, pClass) {
    this.output = output;
    this.pClass = pClass;
    this._seqid = 0;
    this._reqs = {};
  };
  UnpkgServiceClient.prototype = {};
  UnpkgServiceClient.prototype.seqid = function() { return this._seqid; };
  UnpkgServiceClient.prototype.new_seqid = function() { return this._seqid += 1; };
  
  UnpkgServiceClient.prototype.Publish = function(req, 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_Publish(req);
      return _defer.promise;
    } else {
      this._reqs[this.seqid()] = callback;
      this.send_Publish(req);
    }
  };
  
  UnpkgServiceClient.prototype.send_Publish = function(req) {
    var output = new this.pClass(this.output);
    var params = {
      req: req
    };
    var args = new UnpkgService_Publish_args(params);
    try {
      output.writeMessageBegin('Publish', Thrift.MessageType.CALL, this.seqid());
      args.write(output);
      output.writeMessageEnd();
      return this.output.flush();
    }
    catch (e) {
      delete this._reqs[this.seqid()];
      if (typeof output.reset === 'function') {
        output.reset();
      }
      throw e;
    }
  };
  
  UnpkgServiceClient.prototype.recv_Publish = 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 UnpkgService_Publish_result();
    result.read(input);
    input.readMessageEnd();
  
    if (null !== result.success) {
      return callback(null, result.success);
    }
    return callback('Publish failed: unknown result');
  };
  var UnpkgServiceProcessor = exports.Processor = function(handler) {
    this._handler = handler;
  };
  UnpkgServiceProcessor.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();
    }
  };
  UnpkgServiceProcessor.prototype.process_Publish = function(seqid, input, output) {
    var args = new UnpkgService_Publish_args();
    args.read(input);
    input.readMessageEnd();
    if (this._handler.Publish.length === 1) {
      Q.fcall(this._handler.Publish.bind(this._handler),
        args.req
      ).then(function(result) {
        var result_obj = new UnpkgService_Publish_result({success: result});
        output.writeMessageBegin("Publish", Thrift.MessageType.REPLY, seqid);
        result_obj.write(output);
        output.writeMessageEnd();
        output.flush();
      }).catch(function (err) {
        var result;
        result = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
        output.writeMessageBegin("Publish", Thrift.MessageType.EXCEPTION, seqid);
        result.write(output);
        output.writeMessageEnd();
        output.flush();
      });
    } else {
      this._handler.Publish(args.req, function (err, result) {
        var result_obj;
        if ((err === null || typeof err === 'undefined')) {
          result_obj = new UnpkgService_Publish_result((err !== null || typeof err === 'undefined') ? err : {success: result});
          output.writeMessageBegin("Publish", Thrift.MessageType.REPLY, seqid);
        } else {
          result_obj = new Thrift.TApplicationException(Thrift.TApplicationExceptionType.UNKNOWN, err.message);
          output.writeMessageBegin("Publish", Thrift.MessageType.EXCEPTION, seqid);
        }
        result_obj.write(output);
        output.writeMessageEnd();
        output.flush();
      });
    }
  };
  