--
-- Autogenerated by Thrift
--
-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
-- @generated
--


require 'Thrift'
require 'DCMA_ttypes'

ReceiverClient = __TObject.new(__TClient, {
  __type = 'ReceiverClient'
})

function ReceiverClient:GetSupportedOperations(query)
  self:send_GetSupportedOperations(query)
  return self:recv_GetSupportedOperations(query)
end

function ReceiverClient:send_GetSupportedOperations(query)
  self.oprot:writeMessageBegin('GetSupportedOperations', TMessageType.CALL, self._seqid)
  local args = GetSupportedOperations_args:new{}
  args.query = query
  args:write(self.oprot)
  self.oprot:writeMessageEnd()
  self.oprot.trans:flush()
end

function ReceiverClient:recv_GetSupportedOperations(query)
  local fname, mtype, rseqid = self.iprot:readMessageBegin()
  if mtype == TMessageType.EXCEPTION then
    local x = TApplicationException:new{}
    x:read(self.iprot)
    self.iprot:readMessageEnd()
    error(x)
  end
  local result = GetSupportedOperations_result:new{}
  result:read(self.iprot)
  self.iprot:readMessageEnd()
  if result.success ~= nil then
    return result.success
  end
  error(TApplicationException:new{errorCode = TApplicationException.MISSING_RESULT})
end

function ReceiverClient:LoadFiles(server_filenames)
  self:send_LoadFiles(server_filenames)
  return self:recv_LoadFiles(server_filenames)
end

function ReceiverClient:send_LoadFiles(server_filenames)
  self.oprot:writeMessageBegin('LoadFiles', TMessageType.CALL, self._seqid)
  local args = LoadFiles_args:new{}
  args.server_filenames = server_filenames
  args:write(self.oprot)
  self.oprot:writeMessageEnd()
  self.oprot.trans:flush()
end

function ReceiverClient:recv_LoadFiles(server_filenames)
  local fname, mtype, rseqid = self.iprot:readMessageBegin()
  if mtype == TMessageType.EXCEPTION then
    local x = TApplicationException:new{}
    x:read(self.iprot)
    self.iprot:readMessageEnd()
    error(x)
  end
  local result = LoadFiles_result:new{}
  result:read(self.iprot)
  self.iprot:readMessageEnd()
  if result.success ~= nil then
    return result.success
  end
  error(TApplicationException:new{errorCode = TApplicationException.MISSING_RESULT})
end

function ReceiverClient:ExecuteScript(query, script)
  self:send_ExecuteScript(query, script)
  return self:recv_ExecuteScript(query, script)
end

function ReceiverClient:send_ExecuteScript(query, script)
  self.oprot:writeMessageBegin('ExecuteScript', TMessageType.CALL, self._seqid)
  local args = ExecuteScript_args:new{}
  args.query = query
  args.script = script
  args:write(self.oprot)
  self.oprot:writeMessageEnd()
  self.oprot.trans:flush()
end

function ReceiverClient:recv_ExecuteScript(query, script)
  local fname, mtype, rseqid = self.iprot:readMessageBegin()
  if mtype == TMessageType.EXCEPTION then
    local x = TApplicationException:new{}
    x:read(self.iprot)
    self.iprot:readMessageEnd()
    error(x)
  end
  local result = ExecuteScript_result:new{}
  result:read(self.iprot)
  self.iprot:readMessageEnd()
  if result.success ~= nil then
    return result.success
  end
  error(TApplicationException:new{errorCode = TApplicationException.MISSING_RESULT})
end
ReceiverIface = __TObject:new{
  __type = 'ReceiverIface'
}


ReceiverProcessor = __TObject.new(__TProcessor
, {
 __type = 'ReceiverProcessor'
})

function ReceiverProcessor:process(iprot, oprot, server_ctx)
  local name, mtype, seqid = iprot:readMessageBegin()
  local func_name = 'process_' .. name
  if not self[func_name] or ttype(self[func_name]) ~= 'function' then
    if oprot ~= nil then
      iprot:skip(TType.STRUCT)
      iprot:readMessageEnd()
      x = TApplicationException:new{
        errorCode = TApplicationException.UNKNOWN_METHOD
      }
      oprot:writeMessageBegin(name, TMessageType.EXCEPTION, seqid)
      x:write(oprot)
      oprot:writeMessageEnd()
      oprot.trans:flush()
    end
    return false, 'Unknown function '..name
  else
    return self[func_name](self, seqid, iprot, oprot, server_ctx)
  end
end

function ReceiverProcessor:process_GetSupportedOperations(seqid, iprot, oprot, server_ctx)
  local args = GetSupportedOperations_args:new{}
  local reply_type = TMessageType.REPLY
  args:read(iprot)
  iprot:readMessageEnd()
  local result = GetSupportedOperations_result:new{}
  local status, res = pcall(self.handler.GetSupportedOperations, self.handler, args.query)
  if not status then
    reply_type = TMessageType.EXCEPTION
    result = TApplicationException:new{message = res}
  else
    result.success = res
  end
  oprot:writeMessageBegin('GetSupportedOperations', reply_type, seqid)
  result:write(oprot)
  oprot:writeMessageEnd()
  oprot.trans:flush()
  return status, res
end

function ReceiverProcessor:process_LoadFiles(seqid, iprot, oprot, server_ctx)
  local args = LoadFiles_args:new{}
  local reply_type = TMessageType.REPLY
  args:read(iprot)
  iprot:readMessageEnd()
  local result = LoadFiles_result:new{}
  local status, res = pcall(self.handler.LoadFiles, self.handler, args.server_filenames)
  if not status then
    reply_type = TMessageType.EXCEPTION
    result = TApplicationException:new{message = res}
  else
    result.success = res
  end
  oprot:writeMessageBegin('LoadFiles', reply_type, seqid)
  result:write(oprot)
  oprot:writeMessageEnd()
  oprot.trans:flush()
  return status, res
end

function ReceiverProcessor:process_ExecuteScript(seqid, iprot, oprot, server_ctx)
  local args = ExecuteScript_args:new{}
  local reply_type = TMessageType.REPLY
  args:read(iprot)
  iprot:readMessageEnd()
  local result = ExecuteScript_result:new{}
  local status, res = pcall(self.handler.ExecuteScript, self.handler, args.query, args.script)
  if not status then
    reply_type = TMessageType.EXCEPTION
    result = TApplicationException:new{message = res}
  else
    result.success = res
  end
  oprot:writeMessageBegin('ExecuteScript', reply_type, seqid)
  result:write(oprot)
  oprot:writeMessageEnd()
  oprot.trans:flush()
  return status, res
end

-- HELPER FUNCTIONS AND STRUCTURES

GetSupportedOperations_args = __TObject:new{
  query
}

function GetSupportedOperations_args:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 1 then
      if ftype == TType.STRUCT then
        self.query = OperationsQuery:new{}
        self.query:read(iprot)
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function GetSupportedOperations_args:write(oprot)
  oprot:writeStructBegin('GetSupportedOperations_args')
  if self.query ~= nil then
    oprot:writeFieldBegin('query', TType.STRUCT, 1)
    self.query:write(oprot)
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end

GetSupportedOperations_result = __TObject:new{
  success
}

function GetSupportedOperations_result:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 0 then
      if ftype == TType.LIST then
        self.success = {}
        local _etype271, _size268 = iprot:readListBegin()
        for _i=1,_size268 do
          local _elem272 = KnownOperation:new{}
          _elem272:read(iprot)
          table.insert(self.success, _elem272)
        end
        iprot:readListEnd()
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function GetSupportedOperations_result:write(oprot)
  oprot:writeStructBegin('GetSupportedOperations_result')
  if self.success ~= nil then
    oprot:writeFieldBegin('success', TType.LIST, 0)
    oprot:writeListBegin(TType.STRUCT, #self.success)
    for _,iter273 in ipairs(self.success) do
      iter273:write(oprot)
    end
    oprot:writeListEnd()
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end

LoadFiles_args = __TObject:new{
  server_filenames
}

function LoadFiles_args:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 1 then
      if ftype == TType.LIST then
        self.server_filenames = {}
        local _etype277, _size274 = iprot:readListBegin()
        for _i=1,_size274 do
          local _elem278 = LoadFilesQuery:new{}
          _elem278:read(iprot)
          table.insert(self.server_filenames, _elem278)
        end
        iprot:readListEnd()
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function LoadFiles_args:write(oprot)
  oprot:writeStructBegin('LoadFiles_args')
  if self.server_filenames ~= nil then
    oprot:writeFieldBegin('server_filenames', TType.LIST, 1)
    oprot:writeListBegin(TType.STRUCT, #self.server_filenames)
    for _,iter279 in ipairs(self.server_filenames) do
      iter279:write(oprot)
    end
    oprot:writeListEnd()
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end

LoadFiles_result = __TObject:new{
  success
}

function LoadFiles_result:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 0 then
      if ftype == TType.STRUCT then
        self.success = LoadFilesResponse:new{}
        self.success:read(iprot)
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function LoadFiles_result:write(oprot)
  oprot:writeStructBegin('LoadFiles_result')
  if self.success ~= nil then
    oprot:writeFieldBegin('success', TType.STRUCT, 0)
    self.success:write(oprot)
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end

ExecuteScript_args = __TObject:new{
  query,
  script
}

function ExecuteScript_args:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 1 then
      if ftype == TType.STRUCT then
        self.query = ExecuteScriptQuery:new{}
        self.query:read(iprot)
      else
        iprot:skip(ftype)
      end
    elseif fid == 2 then
      if ftype == TType.STRING then
        self.script = iprot:readString()
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function ExecuteScript_args:write(oprot)
  oprot:writeStructBegin('ExecuteScript_args')
  if self.query ~= nil then
    oprot:writeFieldBegin('query', TType.STRUCT, 1)
    self.query:write(oprot)
    oprot:writeFieldEnd()
  end
  if self.script ~= nil then
    oprot:writeFieldBegin('script', TType.STRING, 2)
    oprot:writeString(self.script)
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end

ExecuteScript_result = __TObject:new{
  success
}

function ExecuteScript_result:read(iprot)
  iprot:readStructBegin()
  while true do
    local fname, ftype, fid = iprot:readFieldBegin()
    if ftype == TType.STOP then
      break
    elseif fid == 0 then
      if ftype == TType.STRUCT then
        self.success = ExecuteScriptResponse:new{}
        self.success:read(iprot)
      else
        iprot:skip(ftype)
      end
    else
      iprot:skip(ftype)
    end
    iprot:readFieldEnd()
  end
  iprot:readStructEnd()
end

function ExecuteScript_result:write(oprot)
  oprot:writeStructBegin('ExecuteScript_result')
  if self.success ~= nil then
    oprot:writeFieldBegin('success', TType.STRUCT, 0)
    self.success:write(oprot)
    oprot:writeFieldEnd()
  end
  oprot:writeFieldStop()
  oprot:writeStructEnd()
end