/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 */
package org.apache.hadoop.scribe_log4j.thrift;

import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import com.facebook.thrift.*;

import com.facebook.thrift.protocol.*;
import com.facebook.thrift.transport.*;

public class scribe {

  public interface Iface extends com.facebook.fb303.FacebookService.Iface {

    public int Log(List<LogEntry> messages) throws TException;

  }

  public static class Client extends com.facebook.fb303.FacebookService.Client implements Iface {
    public Client(TProtocol prot)
    {
      this(prot, prot);
    }

    public Client(TProtocol iprot, TProtocol oprot)
    {
      super(iprot, oprot);
    }

    public int Log(List<LogEntry> messages) throws TException
    {
      send_Log(messages);
      return recv_Log();
    }

    public void send_Log(List<LogEntry> messages) throws TException
    {
      oprot_.writeMessageBegin(new TMessage("Log", TMessageType.CALL, seqid_));
      Log_args args = new Log_args();
      args.messages = messages;
      args.write(oprot_);
      oprot_.writeMessageEnd();
      oprot_.getTransport().flush();
    }

    public int recv_Log() throws TException
    {
      TMessage msg = iprot_.readMessageBegin();
      if (msg.type == TMessageType.EXCEPTION) {
        TApplicationException x = TApplicationException.read(iprot_);
        iprot_.readMessageEnd();
        throw x;
      }
      Log_result result = new Log_result();
      result.read(iprot_);
      iprot_.readMessageEnd();
      if (result.__isset.success) {
        return result.success;
      }
      throw new TApplicationException(TApplicationException.MISSING_RESULT, "Log failed: unknown result");
    }

  }
  public static class Processor extends com.facebook.fb303.FacebookService.Processor implements TProcessor {
    public Processor(Iface iface)
    {
      super(iface);
      iface_ = iface;
      processMap_.put("Log", new Log());
    }

    private Iface iface_;

    public boolean process(TProtocol iprot, TProtocol oprot) throws TException
    {
      TMessage msg = iprot.readMessageBegin();
      ProcessFunction fn = processMap_.get(msg.name);
      if (fn == null) {
        TProtocolUtil.skip(iprot, TType.STRUCT);
        iprot.readMessageEnd();
        TApplicationException x = new TApplicationException(TApplicationException.UNKNOWN_METHOD, "Invalid method name: '"+msg.name+"'");
        oprot.writeMessageBegin(new TMessage(msg.name, TMessageType.EXCEPTION, msg.seqid));
        x.write(oprot);
        oprot.writeMessageEnd();
        oprot.getTransport().flush();
        return true;
      }
      fn.process(msg.seqid, iprot, oprot);
      return true;
    }

    private class Log implements ProcessFunction {
      public void process(int seqid, TProtocol iprot, TProtocol oprot) throws TException
      {
        Log_args args = new Log_args();
        args.read(iprot);
        iprot.readMessageEnd();
        Log_result result = new Log_result();
        result.success = iface_.Log(args.messages);
        result.__isset.success = true;
        oprot.writeMessageBegin(new TMessage("Log", TMessageType.REPLY, seqid));
        result.write(oprot);
        oprot.writeMessageEnd();
        oprot.getTransport().flush();
      }

    }

  }

  public static class Log_args implements TBase, java.io.Serializable   {
    public List<LogEntry> messages;
    public static final int MESSAGES = 1;

    public final Isset __isset = new Isset();
    public static final class Isset implements java.io.Serializable {
      public boolean messages = false;
    }

    public Log_args() {
    }

    public Log_args(
      List<LogEntry> messages)
    {
      this();
      this.messages = messages;
      this.__isset.messages = (messages != null);
    }

    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof Log_args)
        return this.equals((Log_args)that);
      return false;
    }

    public boolean equals(Log_args that) {
      if (that == null)
        return false;

      boolean this_present_messages = true && (this.messages != null);
      boolean that_present_messages = true && (that.messages != null);
      if (this_present_messages || that_present_messages) {
        if (!(this_present_messages && that_present_messages))
          return false;
        if (!this.messages.equals(that.messages))
          return false;
      }

      return true;
    }

    public int hashCode() {
      return 0;
    }

    public void read(TProtocol iprot) throws TException {
      TField field;
      iprot.readStructBegin();
      while (true)
      {
        field = iprot.readFieldBegin();
        if (field.type == TType.STOP) {
          break;
        }
        switch (field.id)
        {
          case MESSAGES:
            if (field.type == TType.LIST) {
              {
                TList _list0 = iprot.readListBegin();
                this.messages = new ArrayList<LogEntry>(_list0.size);
                for (int _i1 = 0; _i1 < _list0.size; ++_i1)
                {
                  LogEntry _elem2 = new LogEntry();
                  _elem2 = new LogEntry();
                  _elem2.read(iprot);
                  this.messages.add(_elem2);
                }
                iprot.readListEnd();
              }
              this.__isset.messages = true;
            } else {
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          default:
            TProtocolUtil.skip(iprot, field.type);
            break;
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();
    }

    public void write(TProtocol oprot) throws TException {
      TStruct struct = new TStruct("Log_args");
      oprot.writeStructBegin(struct);
      TField field = new TField();
      if (this.messages != null) {
        field.name = "messages";
        field.type = TType.LIST;
        field.id = MESSAGES;
        oprot.writeFieldBegin(field);
        {
          oprot.writeListBegin(new TList(TType.STRUCT, this.messages.size()));
          for (LogEntry _iter3 : this.messages)          {
            _iter3.write(oprot);
          }
          oprot.writeListEnd();
        }
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

    public String toString() {
      StringBuilder sb = new StringBuilder("Log_args(");
      boolean first = true;

      if (!first) sb.append(", ");
      sb.append("messages:");
      sb.append(this.messages);
      first = false;
      sb.append(")");
      return sb.toString();
    }

  }

  public static class Log_result implements TBase, java.io.Serializable   {
    public int success;
    public static final int SUCCESS = 0;

    public final Isset __isset = new Isset();
    public static final class Isset implements java.io.Serializable {
      public boolean success = false;
    }

    public Log_result() {
    }

    public Log_result(
      int success)
    {
      this();
      this.success = success;
      this.__isset.success = true;
    }

    public boolean equals(Object that) {
      if (that == null)
        return false;
      if (that instanceof Log_result)
        return this.equals((Log_result)that);
      return false;
    }

    public boolean equals(Log_result that) {
      if (that == null)
        return false;

      boolean this_present_success = true;
      boolean that_present_success = true;
      if (this_present_success || that_present_success) {
        if (!(this_present_success && that_present_success))
          return false;
        if (this.success != that.success)
          return false;
      }

      return true;
    }

    public int hashCode() {
      return 0;
    }

    public void read(TProtocol iprot) throws TException {
      TField field;
      iprot.readStructBegin();
      while (true)
      {
        field = iprot.readFieldBegin();
        if (field.type == TType.STOP) {
          break;
        }
        switch (field.id)
        {
          case SUCCESS:
            if (field.type == TType.I32) {
              this.success = iprot.readI32();
              this.__isset.success = true;
            } else {
              TProtocolUtil.skip(iprot, field.type);
            }
            break;
          default:
            TProtocolUtil.skip(iprot, field.type);
            break;
        }
        iprot.readFieldEnd();
      }
      iprot.readStructEnd();
    }

    public void write(TProtocol oprot) throws TException {
      TStruct struct = new TStruct("Log_result");
      oprot.writeStructBegin(struct);
      TField field = new TField();

      if (this.__isset.success) {
        field.name = "success";
        field.type = TType.I32;
        field.id = SUCCESS;
        oprot.writeFieldBegin(field);
        oprot.writeI32(this.success);
        oprot.writeFieldEnd();
      }
      oprot.writeFieldStop();
      oprot.writeStructEnd();
    }

    public String toString() {
      StringBuilder sb = new StringBuilder("Log_result(");
      boolean first = true;

      if (!first) sb.append(", ");
      sb.append("success:");
      sb.append(this.success);
      first = false;
      sb.append(")");
      return sb.toString();
    }

  }

}
