#
# Autogenerated by Thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#

require 'thrift/protocol/tprotocol'
require 'thrift/thrift'
require 'ThriftTest_types'

module ThriftTest
  class Client
    include ThriftClient

    def testVoid()
      send_testVoid()
      recv_testVoid()
    end

    def send_testVoid()
      send_message('testVoid', TestVoid_args)
    end

    def recv_testVoid()
      result = receive_message(TestVoid_result)
      return
    end

    def testString(thing)
      send_testString(thing)
      return recv_testString()
    end

    def send_testString(thing)
      send_message('testString', TestString_args, :thing => thing)
    end

    def recv_testString()
      result = receive_message(TestString_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testString failed: unknown result')
    end

    def testByte(thing)
      send_testByte(thing)
      return recv_testByte()
    end

    def send_testByte(thing)
      send_message('testByte', TestByte_args, :thing => thing)
    end

    def recv_testByte()
      result = receive_message(TestByte_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testByte failed: unknown result')
    end

    def testI32(thing)
      send_testI32(thing)
      return recv_testI32()
    end

    def send_testI32(thing)
      send_message('testI32', TestI32_args, :thing => thing)
    end

    def recv_testI32()
      result = receive_message(TestI32_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testI32 failed: unknown result')
    end

    def testI64(thing)
      send_testI64(thing)
      return recv_testI64()
    end

    def send_testI64(thing)
      send_message('testI64', TestI64_args, :thing => thing)
    end

    def recv_testI64()
      result = receive_message(TestI64_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testI64 failed: unknown result')
    end

    def testDouble(thing)
      send_testDouble(thing)
      return recv_testDouble()
    end

    def send_testDouble(thing)
      send_message('testDouble', TestDouble_args, :thing => thing)
    end

    def recv_testDouble()
      result = receive_message(TestDouble_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testDouble failed: unknown result')
    end

    def testStruct(thing)
      send_testStruct(thing)
      return recv_testStruct()
    end

    def send_testStruct(thing)
      send_message('testStruct', TestStruct_args, :thing => thing)
    end

    def recv_testStruct()
      result = receive_message(TestStruct_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testStruct failed: unknown result')
    end

    def testNest(thing)
      send_testNest(thing)
      return recv_testNest()
    end

    def send_testNest(thing)
      send_message('testNest', TestNest_args, :thing => thing)
    end

    def recv_testNest()
      result = receive_message(TestNest_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testNest failed: unknown result')
    end

    def testMap(thing)
      send_testMap(thing)
      return recv_testMap()
    end

    def send_testMap(thing)
      send_message('testMap', TestMap_args, :thing => thing)
    end

    def recv_testMap()
      result = receive_message(TestMap_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testMap failed: unknown result')
    end

    def testSet(thing)
      send_testSet(thing)
      return recv_testSet()
    end

    def send_testSet(thing)
      send_message('testSet', TestSet_args, :thing => thing)
    end

    def recv_testSet()
      result = receive_message(TestSet_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testSet failed: unknown result')
    end

    def testList(thing)
      send_testList(thing)
      return recv_testList()
    end

    def send_testList(thing)
      send_message('testList', TestList_args, :thing => thing)
    end

    def recv_testList()
      result = receive_message(TestList_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testList failed: unknown result')
    end

    def testEnum(thing)
      send_testEnum(thing)
      return recv_testEnum()
    end

    def send_testEnum(thing)
      send_message('testEnum', TestEnum_args, :thing => thing)
    end

    def recv_testEnum()
      result = receive_message(TestEnum_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testEnum failed: unknown result')
    end

    def testTypedef(thing)
      send_testTypedef(thing)
      return recv_testTypedef()
    end

    def send_testTypedef(thing)
      send_message('testTypedef', TestTypedef_args, :thing => thing)
    end

    def recv_testTypedef()
      result = receive_message(TestTypedef_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testTypedef failed: unknown result')
    end

    def testMapMap(hello)
      send_testMapMap(hello)
      return recv_testMapMap()
    end

    def send_testMapMap(hello)
      send_message('testMapMap', TestMapMap_args, :hello => hello)
    end

    def recv_testMapMap()
      result = receive_message(TestMapMap_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testMapMap failed: unknown result')
    end

    def testInsanity(argument)
      send_testInsanity(argument)
      return recv_testInsanity()
    end

    def send_testInsanity(argument)
      send_message('testInsanity', TestInsanity_args, :argument => argument)
    end

    def recv_testInsanity()
      result = receive_message(TestInsanity_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testInsanity failed: unknown result')
    end

    def testMulti(arg0, arg1, arg2, arg3, arg4, arg5)
      send_testMulti(arg0, arg1, arg2, arg3, arg4, arg5)
      return recv_testMulti()
    end

    def send_testMulti(arg0, arg1, arg2, arg3, arg4, arg5)
      send_message('testMulti', TestMulti_args, :arg0 => arg0, :arg1 => arg1, :arg2 => arg2, :arg3 => arg3, :arg4 => arg4, :arg5 => arg5)
    end

    def recv_testMulti()
      result = receive_message(TestMulti_result)
      return result.success unless result.success.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testMulti failed: unknown result')
    end

    def testException(arg)
      send_testException(arg)
      recv_testException()
    end

    def send_testException(arg)
      send_message('testException', TestException_args, :arg => arg)
    end

    def recv_testException()
      result = receive_message(TestException_result)
      raise result.err1 unless result.err1.nil?
      return
    end

    def testMultiException(arg0, arg1)
      send_testMultiException(arg0, arg1)
      return recv_testMultiException()
    end

    def send_testMultiException(arg0, arg1)
      send_message('testMultiException', TestMultiException_args, :arg0 => arg0, :arg1 => arg1)
    end

    def recv_testMultiException()
      result = receive_message(TestMultiException_result)
      return result.success unless result.success.nil?
      raise result.err1 unless result.err1.nil?
      raise result.err2 unless result.err2.nil?
      raise TApplicationException.new(TApplicationException::MISSING_RESULT, 'testMultiException failed: unknown result')
    end

  end

  class Processor
    include TProcessor

    def process_testVoid(seqid, iprot, oprot)
      args = read_args(iprot, TestVoid_args)
      result = TestVoid_result.new()
      @handler.testVoid()
      write_result(result, oprot, 'testVoid', seqid)
    end

    def process_testString(seqid, iprot, oprot)
      args = read_args(iprot, TestString_args)
      result = TestString_result.new()
      result.success = @handler.testString(args.thing)
      write_result(result, oprot, 'testString', seqid)
    end

    def process_testByte(seqid, iprot, oprot)
      args = read_args(iprot, TestByte_args)
      result = TestByte_result.new()
      result.success = @handler.testByte(args.thing)
      write_result(result, oprot, 'testByte', seqid)
    end

    def process_testI32(seqid, iprot, oprot)
      args = read_args(iprot, TestI32_args)
      result = TestI32_result.new()
      result.success = @handler.testI32(args.thing)
      write_result(result, oprot, 'testI32', seqid)
    end

    def process_testI64(seqid, iprot, oprot)
      args = read_args(iprot, TestI64_args)
      result = TestI64_result.new()
      result.success = @handler.testI64(args.thing)
      write_result(result, oprot, 'testI64', seqid)
    end

    def process_testDouble(seqid, iprot, oprot)
      args = read_args(iprot, TestDouble_args)
      result = TestDouble_result.new()
      result.success = @handler.testDouble(args.thing)
      write_result(result, oprot, 'testDouble', seqid)
    end

    def process_testStruct(seqid, iprot, oprot)
      args = read_args(iprot, TestStruct_args)
      result = TestStruct_result.new()
      result.success = @handler.testStruct(args.thing)
      write_result(result, oprot, 'testStruct', seqid)
    end

    def process_testNest(seqid, iprot, oprot)
      args = read_args(iprot, TestNest_args)
      result = TestNest_result.new()
      result.success = @handler.testNest(args.thing)
      write_result(result, oprot, 'testNest', seqid)
    end

    def process_testMap(seqid, iprot, oprot)
      args = read_args(iprot, TestMap_args)
      result = TestMap_result.new()
      result.success = @handler.testMap(args.thing)
      write_result(result, oprot, 'testMap', seqid)
    end

    def process_testSet(seqid, iprot, oprot)
      args = read_args(iprot, TestSet_args)
      result = TestSet_result.new()
      result.success = @handler.testSet(args.thing)
      write_result(result, oprot, 'testSet', seqid)
    end

    def process_testList(seqid, iprot, oprot)
      args = read_args(iprot, TestList_args)
      result = TestList_result.new()
      result.success = @handler.testList(args.thing)
      write_result(result, oprot, 'testList', seqid)
    end

    def process_testEnum(seqid, iprot, oprot)
      args = read_args(iprot, TestEnum_args)
      result = TestEnum_result.new()
      result.success = @handler.testEnum(args.thing)
      write_result(result, oprot, 'testEnum', seqid)
    end

    def process_testTypedef(seqid, iprot, oprot)
      args = read_args(iprot, TestTypedef_args)
      result = TestTypedef_result.new()
      result.success = @handler.testTypedef(args.thing)
      write_result(result, oprot, 'testTypedef', seqid)
    end

    def process_testMapMap(seqid, iprot, oprot)
      args = read_args(iprot, TestMapMap_args)
      result = TestMapMap_result.new()
      result.success = @handler.testMapMap(args.hello)
      write_result(result, oprot, 'testMapMap', seqid)
    end

    def process_testInsanity(seqid, iprot, oprot)
      args = read_args(iprot, TestInsanity_args)
      result = TestInsanity_result.new()
      result.success = @handler.testInsanity(args.argument)
      write_result(result, oprot, 'testInsanity', seqid)
    end

    def process_testMulti(seqid, iprot, oprot)
      args = read_args(iprot, TestMulti_args)
      result = TestMulti_result.new()
      result.success = @handler.testMulti(args.arg0, args.arg1, args.arg2, args.arg3, args.arg4, args.arg5)
      write_result(result, oprot, 'testMulti', seqid)
    end

    def process_testException(seqid, iprot, oprot)
      args = read_args(iprot, TestException_args)
      result = TestException_result.new()
      begin
        @handler.testException(args.arg)
      rescue Xception => err1
        result.err1 = err1
      end
      write_result(result, oprot, 'testException', seqid)
    end

    def process_testMultiException(seqid, iprot, oprot)
      args = read_args(iprot, TestMultiException_args)
      result = TestMultiException_result.new()
      begin
        result.success = @handler.testMultiException(args.arg0, args.arg1)
      rescue Xception => err1
        result.err1 = err1
      rescue Xception2 => err2
        result.err2 = err2
      end
      write_result(result, oprot, 'testMultiException', seqid)
    end

  end

  # HELPER FUNCTIONS AND STRUCTURES

  class TestVoid_args
    include ThriftStruct
    FIELDS = {

    }

end

  class TestVoid_result
    include ThriftStruct
    FIELDS = {

    }

end

  class TestString_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::STRING, :name => 'thing'}
    }

end

  class TestString_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::STRING, :name => 'success'}
    }

end

  class TestByte_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::BYTE, :name => 'thing'}
    }

end

  class TestByte_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::BYTE, :name => 'success'}
    }

end

  class TestI32_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::I32, :name => 'thing'}
    }

end

  class TestI32_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::I32, :name => 'success'}
    }

end

  class TestI64_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::I64, :name => 'thing'}
    }

end

  class TestI64_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::I64, :name => 'success'}
    }

end

  class TestDouble_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::DOUBLE, :name => 'thing'}
    }

end

  class TestDouble_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::DOUBLE, :name => 'success'}
    }

end

  class TestStruct_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::STRUCT, :name => 'thing', :class => Xtruct}
    }

end

  class TestStruct_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::STRUCT, :name => 'success', :class => Xtruct}
    }

end

  class TestNest_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::STRUCT, :name => 'thing', :class => Xtruct2}
    }

end

  class TestNest_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::STRUCT, :name => 'success', :class => Xtruct2}
    }

end

  class TestMap_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::MAP, :name => 'thing', :key => {:type => TType::I32}, :value => {:type => TType::I32}}
    }

end

  class TestMap_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::MAP, :name => 'success', :key => {:type => TType::I32}, :value => {:type => TType::I32}}
    }

end

  class TestSet_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::SET, :name => 'thing', :element => {:type => TType::I32}}
    }

end

  class TestSet_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::SET, :name => 'success', :element => {:type => TType::I32}}
    }

end

  class TestList_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::LIST, :name => 'thing', :element => {:type => TType::I32}}
    }

end

  class TestList_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::LIST, :name => 'success', :element => {:type => TType::I32}}
    }

end

  class TestEnum_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::I32, :name => 'thing'}
    }

end

  class TestEnum_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::I32, :name => 'success'}
    }

end

  class TestTypedef_args
    include ThriftStruct
    attr_accessor :thing
    FIELDS = {
      1 => {:type => TType::I64, :name => 'thing'}
    }

end

  class TestTypedef_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::I64, :name => 'success'}
    }

end

  class TestMapMap_args
    include ThriftStruct
    attr_accessor :hello
    FIELDS = {
      1 => {:type => TType::I32, :name => 'hello'}
    }

end

  class TestMapMap_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::MAP, :name => 'success', :key => {:type => TType::I32}, :value => {:type => TType::MAP, :key => {:type => TType::I32}, :value => {:type => TType::I32}}}
    }

end

  class TestInsanity_args
    include ThriftStruct
    attr_accessor :argument
    FIELDS = {
      1 => {:type => TType::STRUCT, :name => 'argument', :class => Insanity}
    }

end

  class TestInsanity_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::MAP, :name => 'success', :key => {:type => TType::I64}, :value => {:type => TType::MAP, :key => {:type => TType::I32}, :value => {:type => TType::STRUCT, :class => Insanity}}}
    }

end

  class TestMulti_args
    include ThriftStruct
    attr_accessor :arg0, :arg1, :arg2, :arg3, :arg4, :arg5
    FIELDS = {
      -1 => {:type => TType::BYTE, :name => 'arg0'},
      -2 => {:type => TType::I32, :name => 'arg1'},
      -3 => {:type => TType::I64, :name => 'arg2'},
      -4 => {:type => TType::MAP, :name => 'arg3', :key => {:type => TType::I16}, :value => {:type => TType::STRING}},
      -5 => {:type => TType::I32, :name => 'arg4'},
      -6 => {:type => TType::I64, :name => 'arg5'}
    }

end

  class TestMulti_result
    include ThriftStruct
    attr_accessor :success
    FIELDS = {
      0 => {:type => TType::STRUCT, :name => 'success', :class => Xtruct}
    }

end

  class TestException_args
    include ThriftStruct
    attr_accessor :arg
    FIELDS = {
      -1 => {:type => TType::STRING, :name => 'arg'}
    }

end

  class TestException_result
    include ThriftStruct
    attr_accessor :err1
    FIELDS = {
      -2 => {:type => TType::STRUCT, :name => 'err1'}
    }

end

  class TestMultiException_args
    include ThriftStruct
    attr_accessor :arg0, :arg1
    FIELDS = {
      -1 => {:type => TType::STRING, :name => 'arg0'},
      -2 => {:type => TType::STRING, :name => 'arg1'}
    }

end

  class TestMultiException_result
    include ThriftStruct
    attr_accessor :success, :err1, :err2
    FIELDS = {
      0 => {:type => TType::STRUCT, :name => 'success', :class => Xtruct},
      -3 => {:type => TType::STRUCT, :name => 'err1'},
      -4 => {:type => TType::STRUCT, :name => 'err2'}
    }

end

end