/**
 * Autogenerated by Thrift Compiler (0.9.2)
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated
 */
#include "ServiceDiscoveryService.h"

namespace CarreraServiceDiscovery {


ServiceDiscoveryService_discoverProducerService_args::~ServiceDiscoveryService_discoverProducerService_args() throw() {
}


uint32_t ServiceDiscoveryService_discoverProducerService_args::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->topic);
          this->__isset.topic = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->meta.read(iprot);
          this->__isset.meta = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ServiceDiscoveryService_discoverProducerService_args::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  oprot->incrementRecursionDepth();
  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverProducerService_args");

  xfer += oprot->writeFieldBegin("topic", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->topic);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("meta", ::apache::thrift::protocol::T_STRUCT, 2);
  xfer += this->meta.write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  oprot->decrementRecursionDepth();
  return xfer;
}


ServiceDiscoveryService_discoverProducerService_pargs::~ServiceDiscoveryService_discoverProducerService_pargs() throw() {
}


uint32_t ServiceDiscoveryService_discoverProducerService_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  oprot->incrementRecursionDepth();
  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverProducerService_pargs");

  xfer += oprot->writeFieldBegin("topic", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString((*(this->topic)));
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("meta", ::apache::thrift::protocol::T_STRUCT, 2);
  xfer += (*(this->meta)).write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  oprot->decrementRecursionDepth();
  return xfer;
}


ServiceDiscoveryService_discoverProducerService_result::~ServiceDiscoveryService_discoverProducerService_result() throw() {
}


uint32_t ServiceDiscoveryService_discoverProducerService_result::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 0:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->success.read(iprot);
          this->__isset.success = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ServiceDiscoveryService_discoverProducerService_result::write(::apache::thrift::protocol::TProtocol* oprot) const {

  uint32_t xfer = 0;

  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverProducerService_result");

  if (this->__isset.success) {
    xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRUCT, 0);
    xfer += this->success.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}


ServiceDiscoveryService_discoverProducerService_presult::~ServiceDiscoveryService_discoverProducerService_presult() throw() {
}


uint32_t ServiceDiscoveryService_discoverProducerService_presult::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 0:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += (*(this->success)).read(iprot);
          this->__isset.success = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}


ServiceDiscoveryService_discoverConsumerService_args::~ServiceDiscoveryService_discoverConsumerService_args() throw() {
}


uint32_t ServiceDiscoveryService_discoverConsumerService_args::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 1:
        if (ftype == ::apache::thrift::protocol::T_STRING) {
          xfer += iprot->readString(this->group);
          this->__isset.group = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      case 2:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->meta.read(iprot);
          this->__isset.meta = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ServiceDiscoveryService_discoverConsumerService_args::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  oprot->incrementRecursionDepth();
  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverConsumerService_args");

  xfer += oprot->writeFieldBegin("group", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString(this->group);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("meta", ::apache::thrift::protocol::T_STRUCT, 2);
  xfer += this->meta.write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  oprot->decrementRecursionDepth();
  return xfer;
}


ServiceDiscoveryService_discoverConsumerService_pargs::~ServiceDiscoveryService_discoverConsumerService_pargs() throw() {
}


uint32_t ServiceDiscoveryService_discoverConsumerService_pargs::write(::apache::thrift::protocol::TProtocol* oprot) const {
  uint32_t xfer = 0;
  oprot->incrementRecursionDepth();
  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverConsumerService_pargs");

  xfer += oprot->writeFieldBegin("group", ::apache::thrift::protocol::T_STRING, 1);
  xfer += oprot->writeString((*(this->group)));
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldBegin("meta", ::apache::thrift::protocol::T_STRUCT, 2);
  xfer += (*(this->meta)).write(oprot);
  xfer += oprot->writeFieldEnd();

  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  oprot->decrementRecursionDepth();
  return xfer;
}


ServiceDiscoveryService_discoverConsumerService_result::~ServiceDiscoveryService_discoverConsumerService_result() throw() {
}


uint32_t ServiceDiscoveryService_discoverConsumerService_result::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 0:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += this->success.read(iprot);
          this->__isset.success = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

uint32_t ServiceDiscoveryService_discoverConsumerService_result::write(::apache::thrift::protocol::TProtocol* oprot) const {

  uint32_t xfer = 0;

  xfer += oprot->writeStructBegin("ServiceDiscoveryService_discoverConsumerService_result");

  if (this->__isset.success) {
    xfer += oprot->writeFieldBegin("success", ::apache::thrift::protocol::T_STRUCT, 0);
    xfer += this->success.write(oprot);
    xfer += oprot->writeFieldEnd();
  }
  xfer += oprot->writeFieldStop();
  xfer += oprot->writeStructEnd();
  return xfer;
}


ServiceDiscoveryService_discoverConsumerService_presult::~ServiceDiscoveryService_discoverConsumerService_presult() throw() {
}


uint32_t ServiceDiscoveryService_discoverConsumerService_presult::read(::apache::thrift::protocol::TProtocol* iprot) {

  uint32_t xfer = 0;
  std::string fname;
  ::apache::thrift::protocol::TType ftype;
  int16_t fid;

  xfer += iprot->readStructBegin(fname);

  using ::apache::thrift::protocol::TProtocolException;


  while (true)
  {
    xfer += iprot->readFieldBegin(fname, ftype, fid);
    if (ftype == ::apache::thrift::protocol::T_STOP) {
      break;
    }
    switch (fid)
    {
      case 0:
        if (ftype == ::apache::thrift::protocol::T_STRUCT) {
          xfer += (*(this->success)).read(iprot);
          this->__isset.success = true;
        } else {
          xfer += iprot->skip(ftype);
        }
        break;
      default:
        xfer += iprot->skip(ftype);
        break;
    }
    xfer += iprot->readFieldEnd();
  }

  xfer += iprot->readStructEnd();

  return xfer;
}

void ServiceDiscoveryServiceClient::discoverProducerService(ServiceMeta& _return, const std::string& topic, const ClientMeta& meta)
{
  send_discoverProducerService(topic, meta);
  recv_discoverProducerService(_return);
}

void ServiceDiscoveryServiceClient::send_discoverProducerService(const std::string& topic, const ClientMeta& meta)
{
  int32_t cseqid = 0;
  oprot_->writeMessageBegin("discoverProducerService", ::apache::thrift::protocol::T_CALL, cseqid);

  ServiceDiscoveryService_discoverProducerService_pargs args;
  args.topic = &topic;
  args.meta = &meta;
  args.write(oprot_);

  oprot_->writeMessageEnd();
  oprot_->getTransport()->writeEnd();
  oprot_->getTransport()->flush();
}

void ServiceDiscoveryServiceClient::recv_discoverProducerService(ServiceMeta& _return)
{

  int32_t rseqid = 0;
  std::string fname;
  ::apache::thrift::protocol::TMessageType mtype;

  iprot_->readMessageBegin(fname, mtype, rseqid);
  if (mtype == ::apache::thrift::protocol::T_EXCEPTION) {
    ::apache::thrift::TApplicationException x;
    x.read(iprot_);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
    throw x;
  }
  if (mtype != ::apache::thrift::protocol::T_REPLY) {
    iprot_->skip(::apache::thrift::protocol::T_STRUCT);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
  }
  if (fname.compare("discoverProducerService") != 0) {
    iprot_->skip(::apache::thrift::protocol::T_STRUCT);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
  }
  ServiceDiscoveryService_discoverProducerService_presult result;
  result.success = &_return;
  result.read(iprot_);
  iprot_->readMessageEnd();
  iprot_->getTransport()->readEnd();

  if (result.__isset.success) {
    // _return pointer has now been filled
    return;
  }
  throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "discoverProducerService failed: unknown result");
}

void ServiceDiscoveryServiceClient::discoverConsumerService(ServiceMeta& _return, const std::string& group, const ClientMeta& meta)
{
  send_discoverConsumerService(group, meta);
  recv_discoverConsumerService(_return);
}

void ServiceDiscoveryServiceClient::send_discoverConsumerService(const std::string& group, const ClientMeta& meta)
{
  int32_t cseqid = 0;
  oprot_->writeMessageBegin("discoverConsumerService", ::apache::thrift::protocol::T_CALL, cseqid);

  ServiceDiscoveryService_discoverConsumerService_pargs args;
  args.group = &group;
  args.meta = &meta;
  args.write(oprot_);

  oprot_->writeMessageEnd();
  oprot_->getTransport()->writeEnd();
  oprot_->getTransport()->flush();
}

void ServiceDiscoveryServiceClient::recv_discoverConsumerService(ServiceMeta& _return)
{

  int32_t rseqid = 0;
  std::string fname;
  ::apache::thrift::protocol::TMessageType mtype;

  iprot_->readMessageBegin(fname, mtype, rseqid);
  if (mtype == ::apache::thrift::protocol::T_EXCEPTION) {
    ::apache::thrift::TApplicationException x;
    x.read(iprot_);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
    throw x;
  }
  if (mtype != ::apache::thrift::protocol::T_REPLY) {
    iprot_->skip(::apache::thrift::protocol::T_STRUCT);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
  }
  if (fname.compare("discoverConsumerService") != 0) {
    iprot_->skip(::apache::thrift::protocol::T_STRUCT);
    iprot_->readMessageEnd();
    iprot_->getTransport()->readEnd();
  }
  ServiceDiscoveryService_discoverConsumerService_presult result;
  result.success = &_return;
  result.read(iprot_);
  iprot_->readMessageEnd();
  iprot_->getTransport()->readEnd();

  if (result.__isset.success) {
    // _return pointer has now been filled
    return;
  }
  throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "discoverConsumerService failed: unknown result");
}

bool ServiceDiscoveryServiceProcessor::dispatchCall(::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, const std::string& fname, int32_t seqid, void* callContext) {
  ProcessMap::iterator pfn;
  pfn = processMap_.find(fname);
  if (pfn == processMap_.end()) {
    iprot->skip(::apache::thrift::protocol::T_STRUCT);
    iprot->readMessageEnd();
    iprot->getTransport()->readEnd();
    ::apache::thrift::TApplicationException x(::apache::thrift::TApplicationException::UNKNOWN_METHOD, "Invalid method name: '"+fname+"'");
    oprot->writeMessageBegin(fname, ::apache::thrift::protocol::T_EXCEPTION, seqid);
    x.write(oprot);
    oprot->writeMessageEnd();
    oprot->getTransport()->writeEnd();
    oprot->getTransport()->flush();
    return true;
  }
  (this->*(pfn->second))(seqid, iprot, oprot, callContext);
  return true;
}

void ServiceDiscoveryServiceProcessor::process_discoverProducerService(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext)
{
  void* ctx = NULL;
  if (this->eventHandler_.get() != NULL) {
    ctx = this->eventHandler_->getContext("ServiceDiscoveryService.discoverProducerService", callContext);
  }
  ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "ServiceDiscoveryService.discoverProducerService");

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->preRead(ctx, "ServiceDiscoveryService.discoverProducerService");
  }

  ServiceDiscoveryService_discoverProducerService_args args;
  args.read(iprot);
  iprot->readMessageEnd();
  uint32_t bytes = iprot->getTransport()->readEnd();

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->postRead(ctx, "ServiceDiscoveryService.discoverProducerService", bytes);
  }

  ServiceDiscoveryService_discoverProducerService_result result;
  try {
    iface_->discoverProducerService(result.success, args.topic, args.meta);
    result.__isset.success = true;
  } catch (const std::exception& e) {
    if (this->eventHandler_.get() != NULL) {
      this->eventHandler_->handlerError(ctx, "ServiceDiscoveryService.discoverProducerService");
    }

    ::apache::thrift::TApplicationException x(e.what());
    oprot->writeMessageBegin("discoverProducerService", ::apache::thrift::protocol::T_EXCEPTION, seqid);
    x.write(oprot);
    oprot->writeMessageEnd();
    oprot->getTransport()->writeEnd();
    oprot->getTransport()->flush();
    return;
  }

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->preWrite(ctx, "ServiceDiscoveryService.discoverProducerService");
  }

  oprot->writeMessageBegin("discoverProducerService", ::apache::thrift::protocol::T_REPLY, seqid);
  result.write(oprot);
  oprot->writeMessageEnd();
  bytes = oprot->getTransport()->writeEnd();
  oprot->getTransport()->flush();

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->postWrite(ctx, "ServiceDiscoveryService.discoverProducerService", bytes);
  }
}

void ServiceDiscoveryServiceProcessor::process_discoverConsumerService(int32_t seqid, ::apache::thrift::protocol::TProtocol* iprot, ::apache::thrift::protocol::TProtocol* oprot, void* callContext)
{
  void* ctx = NULL;
  if (this->eventHandler_.get() != NULL) {
    ctx = this->eventHandler_->getContext("ServiceDiscoveryService.discoverConsumerService", callContext);
  }
  ::apache::thrift::TProcessorContextFreer freer(this->eventHandler_.get(), ctx, "ServiceDiscoveryService.discoverConsumerService");

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->preRead(ctx, "ServiceDiscoveryService.discoverConsumerService");
  }

  ServiceDiscoveryService_discoverConsumerService_args args;
  args.read(iprot);
  iprot->readMessageEnd();
  uint32_t bytes = iprot->getTransport()->readEnd();

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->postRead(ctx, "ServiceDiscoveryService.discoverConsumerService", bytes);
  }

  ServiceDiscoveryService_discoverConsumerService_result result;
  try {
    iface_->discoverConsumerService(result.success, args.group, args.meta);
    result.__isset.success = true;
  } catch (const std::exception& e) {
    if (this->eventHandler_.get() != NULL) {
      this->eventHandler_->handlerError(ctx, "ServiceDiscoveryService.discoverConsumerService");
    }

    ::apache::thrift::TApplicationException x(e.what());
    oprot->writeMessageBegin("discoverConsumerService", ::apache::thrift::protocol::T_EXCEPTION, seqid);
    x.write(oprot);
    oprot->writeMessageEnd();
    oprot->getTransport()->writeEnd();
    oprot->getTransport()->flush();
    return;
  }

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->preWrite(ctx, "ServiceDiscoveryService.discoverConsumerService");
  }

  oprot->writeMessageBegin("discoverConsumerService", ::apache::thrift::protocol::T_REPLY, seqid);
  result.write(oprot);
  oprot->writeMessageEnd();
  bytes = oprot->getTransport()->writeEnd();
  oprot->getTransport()->flush();

  if (this->eventHandler_.get() != NULL) {
    this->eventHandler_->postWrite(ctx, "ServiceDiscoveryService.discoverConsumerService", bytes);
  }
}

::boost::shared_ptr< ::apache::thrift::TProcessor > ServiceDiscoveryServiceProcessorFactory::getProcessor(const ::apache::thrift::TConnectionInfo& connInfo) {
  ::apache::thrift::ReleaseHandler< ServiceDiscoveryServiceIfFactory > cleanup(handlerFactory_);
  ::boost::shared_ptr< ServiceDiscoveryServiceIf > handler(handlerFactory_->getHandler(connInfo), cleanup);
  ::boost::shared_ptr< ::apache::thrift::TProcessor > processor(new ServiceDiscoveryServiceProcessor(handler));
  return processor;
}
} // namespace

