/**
 * Autogenerated by Thrift for thrift/compiler/test/fixtures/client-methods/src/module.thrift
 *
 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
 *  @generated @nocommit
 */
#include <thrift/lib/cpp2/gen/module_metadata_cpp.h>
#include "thrift/compiler/test/fixtures/client-methods/gen-cpp2/module_metadata.h"

// some of these functions can be so large that the compiler gives up optimizing
// them - and issues a warning which may be treated as an error!
//
// these functions are so rarely called that it is probably okay for them not to
// be optimized in practice
FOLLY_CLANG_DISABLE_WARNING("-Wignored-optimization-argument")

namespace apache {
namespace thrift {
namespace detail {
namespace md {
using ThriftMetadata = ::apache::thrift::metadata::ThriftMetadata;
using ThriftPrimitiveType = ::apache::thrift::metadata::ThriftPrimitiveType;
using ThriftType = ::apache::thrift::metadata::ThriftType;
using ThriftService = ::apache::thrift::metadata::ThriftService;
using ThriftServiceContext = ::apache::thrift::metadata::ThriftServiceContext;
using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&);


const ::apache::thrift::metadata::ThriftStruct&
StructMetadata<::cpp2::EchoRequest>::gen(ThriftMetadata& metadata) {
  auto res = metadata.structs()->emplace("module.EchoRequest", ::apache::thrift::metadata::ThriftStruct{});
  if (!res.second) {
    return res.first->second;
  }
  ::apache::thrift::metadata::ThriftStruct& module_EchoRequest = res.first->second;
  module_EchoRequest.name() = "module.EchoRequest";
  module_EchoRequest.is_union() = false;
  static const auto* const
  module_EchoRequest_fields = new std::array<EncodedThriftField, 1>{ {
    { 1, "text", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }},  }};
  for (const auto& f : *module_EchoRequest_fields) {
    ::apache::thrift::metadata::ThriftField field;
    field.id() = f.id;
    field.name() = f.name;
    field.is_optional() = f.is_optional;
    f.metadata_type_interface->writeAndGenType(*field.type(), metadata);
    field.structured_annotations() = f.structured_annotations;
    module_EchoRequest.fields()->push_back(std::move(field));
  }
  return res.first->second;
}
const ::apache::thrift::metadata::ThriftStruct&
StructMetadata<::cpp2::EchoResponse>::gen(ThriftMetadata& metadata) {
  auto res = metadata.structs()->emplace("module.EchoResponse", ::apache::thrift::metadata::ThriftStruct{});
  if (!res.second) {
    return res.first->second;
  }
  ::apache::thrift::metadata::ThriftStruct& module_EchoResponse = res.first->second;
  module_EchoResponse.name() = "module.EchoResponse";
  module_EchoResponse.is_union() = false;
  static const auto* const
  module_EchoResponse_fields = new std::array<EncodedThriftField, 1>{ {
    { 1, "text", false, std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_STRING_TYPE), std::vector<ThriftConstStruct>{ }},  }};
  for (const auto& f : *module_EchoResponse_fields) {
    ::apache::thrift::metadata::ThriftField field;
    field.id() = f.id;
    field.name() = f.name;
    field.is_optional() = f.is_optional;
    f.metadata_type_interface->writeAndGenType(*field.type(), metadata);
    field.structured_annotations() = f.structured_annotations;
    module_EchoResponse.fields()->push_back(std::move(field));
  }
  return res.first->second;
}

void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::gen_echo([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {
  ::apache::thrift::metadata::ThriftFunction func;
  func.name() = "echo";
  auto func_ret_type = std::make_unique<Struct<::cpp2::EchoResponse>>("module.EchoResponse");
  func_ret_type->writeAndGenType(*func.return_type(), metadata);
  ::apache::thrift::metadata::ThriftField module_HeaderClientMethodsAnnotationOnService_echo_request_1;
  module_HeaderClientMethodsAnnotationOnService_echo_request_1.id() = 1;
  module_HeaderClientMethodsAnnotationOnService_echo_request_1.name() = "request";
  module_HeaderClientMethodsAnnotationOnService_echo_request_1.is_optional() = false;
  auto module_HeaderClientMethodsAnnotationOnService_echo_request_1_type = std::make_unique<Struct<::cpp2::EchoRequest>>("module.EchoRequest");
  module_HeaderClientMethodsAnnotationOnService_echo_request_1_type->writeAndGenType(*module_HeaderClientMethodsAnnotationOnService_echo_request_1.type(), metadata);
  func.arguments()->push_back(std::move(module_HeaderClientMethodsAnnotationOnService_echo_request_1));
  func.is_oneway() = false;
  service.functions()->push_back(std::move(func));
}
void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::gen_echo_2([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {
  ::apache::thrift::metadata::ThriftFunction func;
  func.name() = "echo_2";
  auto func_ret_type = std::make_unique<Struct<::cpp2::EchoResponse>>("module.EchoResponse");
  func_ret_type->writeAndGenType(*func.return_type(), metadata);
  ::apache::thrift::metadata::ThriftField module_HeaderClientMethodsAnnotationOnService_echo_2_request_1;
  module_HeaderClientMethodsAnnotationOnService_echo_2_request_1.id() = 1;
  module_HeaderClientMethodsAnnotationOnService_echo_2_request_1.name() = "request";
  module_HeaderClientMethodsAnnotationOnService_echo_2_request_1.is_optional() = false;
  auto module_HeaderClientMethodsAnnotationOnService_echo_2_request_1_type = std::make_unique<Struct<::cpp2::EchoRequest>>("module.EchoRequest");
  module_HeaderClientMethodsAnnotationOnService_echo_2_request_1_type->writeAndGenType(*module_HeaderClientMethodsAnnotationOnService_echo_2_request_1.type(), metadata);
  func.arguments()->push_back(std::move(module_HeaderClientMethodsAnnotationOnService_echo_2_request_1));
  func.is_oneway() = false;
  service.functions()->push_back(std::move(func));
}

void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::gen(::apache::thrift::metadata::ThriftServiceMetadataResponse& response) {
  const ::apache::thrift::metadata::ThriftServiceContextRef* self = genRecurse(*response.metadata(), *response.services());
  DCHECK(self != nullptr);
  // TODO(praihan): Remove ThriftServiceContext from response. But in the meantime, we need to fill the field with the result of looking up in ThriftMetadata.
  ::apache::thrift::metadata::ThriftServiceContext context;
  context.module() = *self->module();
  context.service_info() = response.metadata()->services()->at(*self->service_name());
  response.context() = std::move(context);
}

const ThriftServiceContextRef* ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::genRecurse([[maybe_unused]] ThriftMetadata& metadata, std::vector<ThriftServiceContextRef>& services) {
  ::apache::thrift::metadata::ThriftService module_HeaderClientMethodsAnnotationOnService;
  module_HeaderClientMethodsAnnotationOnService.name() = "module.HeaderClientMethodsAnnotationOnService";
  static const ThriftFunctionGenerator functions[] = {
    ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::gen_echo,
    ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnService>>::gen_echo_2,
  };
  for (auto& function_gen : functions) {
    function_gen(metadata, module_HeaderClientMethodsAnnotationOnService);
  }
  // We need to keep the index around because a reference or iterator could be invalidated.
  auto selfIndex = services.size();
  services.emplace_back();
  module_HeaderClientMethodsAnnotationOnService.structured_annotations()->push_back(*cvStruct("cpp.GenerateDeprecatedHeaderClientMethods", {  }).cv_struct_ref());
  ThriftServiceContextRef& context = services[selfIndex];
  metadata.services()->emplace("module.HeaderClientMethodsAnnotationOnService", std::move(module_HeaderClientMethodsAnnotationOnService));
  context.service_name() = "module.HeaderClientMethodsAnnotationOnService";
  ::apache::thrift::metadata::ThriftModuleContext module;
  module.name() = "module";
  context.module() = std::move(module);
  return &context;
}
void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::gen_echo([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {
  ::apache::thrift::metadata::ThriftFunction func;
  func.name() = "echo";
  auto func_ret_type = std::make_unique<Struct<::cpp2::EchoResponse>>("module.EchoResponse");
  func_ret_type->writeAndGenType(*func.return_type(), metadata);
  ::apache::thrift::metadata::ThriftField module_HeaderClientMethodsAnnotationOnFunction_echo_request_1;
  module_HeaderClientMethodsAnnotationOnFunction_echo_request_1.id() = 1;
  module_HeaderClientMethodsAnnotationOnFunction_echo_request_1.name() = "request";
  module_HeaderClientMethodsAnnotationOnFunction_echo_request_1.is_optional() = false;
  auto module_HeaderClientMethodsAnnotationOnFunction_echo_request_1_type = std::make_unique<Struct<::cpp2::EchoRequest>>("module.EchoRequest");
  module_HeaderClientMethodsAnnotationOnFunction_echo_request_1_type->writeAndGenType(*module_HeaderClientMethodsAnnotationOnFunction_echo_request_1.type(), metadata);
  func.arguments()->push_back(std::move(module_HeaderClientMethodsAnnotationOnFunction_echo_request_1));
  func.is_oneway() = false;
  func.structured_annotations()->push_back(*cvStruct("cpp.GenerateDeprecatedHeaderClientMethods", {  }).cv_struct_ref());
  service.functions()->push_back(std::move(func));
}
void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::gen_echo_2([[maybe_unused]] ThriftMetadata& metadata, ThriftService& service) {
  ::apache::thrift::metadata::ThriftFunction func;
  func.name() = "echo_2";
  auto func_ret_type = std::make_unique<Struct<::cpp2::EchoResponse>>("module.EchoResponse");
  func_ret_type->writeAndGenType(*func.return_type(), metadata);
  ::apache::thrift::metadata::ThriftField module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1;
  module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1.id() = 1;
  module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1.name() = "request";
  module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1.is_optional() = false;
  auto module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1_type = std::make_unique<Struct<::cpp2::EchoRequest>>("module.EchoRequest");
  module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1_type->writeAndGenType(*module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1.type(), metadata);
  func.arguments()->push_back(std::move(module_HeaderClientMethodsAnnotationOnFunction_echo_2_request_1));
  func.is_oneway() = false;
  service.functions()->push_back(std::move(func));
}

void ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::gen(::apache::thrift::metadata::ThriftServiceMetadataResponse& response) {
  const ::apache::thrift::metadata::ThriftServiceContextRef* self = genRecurse(*response.metadata(), *response.services());
  DCHECK(self != nullptr);
  // TODO(praihan): Remove ThriftServiceContext from response. But in the meantime, we need to fill the field with the result of looking up in ThriftMetadata.
  ::apache::thrift::metadata::ThriftServiceContext context;
  context.module() = *self->module();
  context.service_info() = response.metadata()->services()->at(*self->service_name());
  response.context() = std::move(context);
}

const ThriftServiceContextRef* ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::genRecurse([[maybe_unused]] ThriftMetadata& metadata, std::vector<ThriftServiceContextRef>& services) {
  ::apache::thrift::metadata::ThriftService module_HeaderClientMethodsAnnotationOnFunction;
  module_HeaderClientMethodsAnnotationOnFunction.name() = "module.HeaderClientMethodsAnnotationOnFunction";
  static const ThriftFunctionGenerator functions[] = {
    ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::gen_echo,
    ServiceMetadata<::apache::thrift::ServiceHandler<::cpp2::HeaderClientMethodsAnnotationOnFunction>>::gen_echo_2,
  };
  for (auto& function_gen : functions) {
    function_gen(metadata, module_HeaderClientMethodsAnnotationOnFunction);
  }
  // We need to keep the index around because a reference or iterator could be invalidated.
  auto selfIndex = services.size();
  services.emplace_back();
  ThriftServiceContextRef& context = services[selfIndex];
  metadata.services()->emplace("module.HeaderClientMethodsAnnotationOnFunction", std::move(module_HeaderClientMethodsAnnotationOnFunction));
  context.service_name() = "module.HeaderClientMethodsAnnotationOnFunction";
  ::apache::thrift::metadata::ThriftModuleContext module;
  module.name() = "module";
  context.module() = std::move(module);
  return &context;
}
} // namespace md
} // namespace detail
} // namespace thrift
} // namespace apache
