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


var FacebookService = require('./FacebookService')
var FacebookServiceClient = FacebookService.Client
var ttypes = require('./scribe_types');
//HELPER FUNCTIONS AND STRUCTURES

var scribe_Log_args = function(args){
  this.messages = null
if( args != null ){  if (null != args.messages)
  this.messages = args.messages
}}
scribe_Log_args.prototype = {}
scribe_Log_args.prototype.read = function(input){ 
  var ret = input.readStructBegin()
  while (1) 
  {
    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.LIST) {
        {
          var _size0 = 0
          var rtmp3
          this.messages = []
          var _etype3 = 0
          rtmp3 = input.readListBegin()
          _etype3 = rtmp3.etype
          _size0 = rtmp3.size
          for (var _i4 = 0; _i4 < _size0; ++_i4)
          {
            var elem5 = null
            elem5 = new ttypes.LogEntry()
            elem5.read(input)
            this.messages.push(elem5)
          }
          input.readListEnd()
        }
      } else {
        input.skip(ftype)
      }
      break
      default:
        input.skip(ftype)
    }
    input.readFieldEnd()
  }
  input.readStructEnd()
  return
}

scribe_Log_args.prototype.write = function(output){ 
  output.writeStructBegin('scribe_Log_args')
  if (null != this.messages) {
    output.writeFieldBegin('messages', Thrift.Type.LIST, 1)
    {
      output.writeListBegin(Thrift.Type.STRUCT, this.messages.length)
      {
        for(var iter6 in this.messages)
        {
          if (this.messages.hasOwnProperty(iter6))
          {
            iter6=this.messages[iter6]
            iter6.write(output)
          }
        }
      }
      output.writeListEnd()
    }
    output.writeFieldEnd()
  }
  output.writeFieldStop()
  output.writeStructEnd()
  return
}

var scribe_Log_result = function(args){
  this.success = null
if( args != null ){  if (null != args.success)
  this.success = args.success
}}
scribe_Log_result.prototype = {}
scribe_Log_result.prototype.read = function(input){ 
  var ret = input.readStructBegin()
  while (1) 
  {
    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.I32) {
        this.success = input.readI32()
      } else {
        input.skip(ftype)
      }
      break
      default:
        input.skip(ftype)
    }
    input.readFieldEnd()
  }
  input.readStructEnd()
  return
}

scribe_Log_result.prototype.write = function(output){ 
  output.writeStructBegin('scribe_Log_result')
  if (null != this.success) {
    output.writeFieldBegin('success', Thrift.Type.I32, 0)
    output.writeI32(this.success)
    output.writeFieldEnd()
  }
  output.writeFieldStop()
  output.writeStructEnd()
  return
}

var scribeClient = exports.Client = function(output, pClass) {
    this.output = output;
    this.pClass = pClass;
    this.seqid = 0;
    this._reqs = {}
}
Thrift.inherits(scribeClient, FacebookServiceClient)
scribeClient.prototype.Log = function(messages,callback){
  this.seqid += 1;
  this._reqs[this.seqid] = callback;
    this.send_Log(messages)
}

scribeClient.prototype.send_Log = function(messages){
  var output = new this.pClass(this.output);
  output.writeMessageBegin('Log', Thrift.MessageType.CALL, this.seqid)
  var args = new scribe_Log_args()
  args.messages = messages
  args.write(output)
  output.writeMessageEnd()
  return this.output.flush()
}

scribeClient.prototype.recv_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 scribe_Log_result()
  result.read(input)
  input.readMessageEnd()

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

scribeProcessor.prototype.process_Log = function(seqid, input, output) {
  var args = new scribe_Log_args()
  args.read(input)
  input.readMessageEnd()
  var result = new scribe_Log_result()
  this._handler.Log(args.messages, function(success) {
    result.success = success
    output.writeMessageBegin("Log", Thrift.MessageType.REPLY, seqid)
    result.write(output)
    output.writeMessageEnd()
    output.flush()
  })
}

