
/**
 * Autogenerated by Thrift
 *
 * DO NOT EDIT
 *  @generated
 *
 */

#include <folly/python/import.h>
#include <thrift/lib/python/capi/iobuf.h>
#include <thrift/lib/python/types.h>

#include <thrift/compiler/test/fixtures/adapter/gen-python-capi/module/thrift_types_api.h>
#include <thrift/compiler/test/fixtures/adapter/gen-python-capi/module/thrift_types_capi.h>


namespace apache {
namespace thrift {
namespace python {
namespace capi {
namespace {
bool ensure_module_imported() {
  static ::folly::python::import_cache_nocapture import((
      ::import_facebook__thrift__test__module__thrift_types_capi));
  return import();
}
  static constexpr std::int16_t _fbthrift__MyAnnotation__tuple_pos[2] = {
    1, 2
  };
  static constexpr std::int16_t _fbthrift__DirectlyAdapted__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__IndependentDirectlyAdapted__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__Config__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__AdaptTemplatedNestedTestStruct__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__AdaptedStruct__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__DirectlyAdaptedStruct__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__CircularAdaptee__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__RenamedStruct__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__SameNamespaceStruct__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__Person__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__Person2__tuple_pos[1] = {
    1
  };
} // namespace

ExtractorResult<::facebook::thrift::test::MyAnnotation>
Extractor<::facebook::thrift::test::MyAnnotation>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a MyAnnotation");
      }
      return extractorError<::facebook::thrift::test::MyAnnotation>(
          "Marshal error: MyAnnotation");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::MyAnnotation>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::MyAnnotation>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::MyAnnotation>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::MyAnnotation cpp;
  std::optional<std::string_view> error;
  Extractor<Bytes>{}.extractInto(
      cpp.signature_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__MyAnnotation__tuple_pos[0]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::Color>>{}.extractInto(
      cpp.color_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__MyAnnotation__tuple_pos[1]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::MyAnnotation>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__MyAnnotation(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: MyAnnotation");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::MyAnnotation>::operator()(
    const ::facebook::thrift::test::MyAnnotation& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::MyAnnotation>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__MyAnnotation(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::MyAnnotation>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::MyAnnotation& val) {
  StrongRef fbthrift_data(createStructTuple(2));
  StrongRef _fbthrift__signature(
    Constructor<Bytes>{}
    .constructFrom(val.signature_ref()));
  if (!_fbthrift__signature ||
      setStructField(
          *fbthrift_data,
          _fbthrift__MyAnnotation__tuple_pos[0],
          *_fbthrift__signature) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__color(
    Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::Color>>{}
    .constructFrom(val.color_ref()));
  if (!_fbthrift__color ||
      setStructField(
          *fbthrift_data,
          _fbthrift__MyAnnotation__tuple_pos[1],
          *_fbthrift__color) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::Foo>
Extractor<::facebook::thrift::test::Foo>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Foo>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__Foo(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::Foo>(
        "Thrift serialize error: Foo");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::Foo>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::Foo>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Foo>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Foo>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__Foo(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::Foo>(
          "Init from fbthrift error: Foo");
  }
  return Extractor<::facebook::thrift::test::Foo>{}(*obj);
}

int Extractor<::facebook::thrift::test::Foo>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Foo(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Foo");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Foo>::operator()(
    const ::facebook::thrift::test::Foo& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__Foo(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Foo>>::operator()(
    const ::facebook::thrift::test::Foo& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::Foo>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::Baz>
Extractor<::facebook::thrift::test::Baz>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Baz>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__Baz(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::Baz>(
        "Thrift serialize error: Baz");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::Baz>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::Baz>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Baz>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Baz>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__Baz(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::Baz>(
          "Init from fbthrift error: Baz");
  }
  return Extractor<::facebook::thrift::test::Baz>{}(*obj);
}

int Extractor<::facebook::thrift::test::Baz>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Baz(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Baz");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Baz>::operator()(
    const ::facebook::thrift::test::Baz& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__Baz(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Baz>>::operator()(
    const ::facebook::thrift::test::Baz& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::Baz>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::Bar>
Extractor<::facebook::thrift::test::Bar>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Bar>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__Bar(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::Bar>(
        "Thrift serialize error: Bar");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::Bar>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::Bar>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Bar>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Bar>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__Bar(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::Bar>(
          "Init from fbthrift error: Bar");
  }
  return Extractor<::facebook::thrift::test::Bar>{}(*obj);
}

int Extractor<::facebook::thrift::test::Bar>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Bar(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Bar");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Bar>::operator()(
    const ::facebook::thrift::test::Bar& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__Bar(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Bar>>::operator()(
    const ::facebook::thrift::test::Bar& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::Bar>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::detail::DirectlyAdapted>
Extractor<::facebook::thrift::test::detail::DirectlyAdapted>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a DirectlyAdapted");
      }
      return extractorError<::facebook::thrift::test::detail::DirectlyAdapted>(
          "Marshal error: DirectlyAdapted");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::detail::DirectlyAdapted>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::detail::DirectlyAdapted>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::DirectlyAdapted>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::DirectlyAdapted cpp;
  std::optional<std::string_view> error;
  Extractor<int32_t>{}.extractInto(
      cpp.field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__DirectlyAdapted__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::DirectlyAdapted>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__DirectlyAdapted(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: DirectlyAdapted");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::DirectlyAdapted>::operator()(
    const ::facebook::thrift::test::detail::DirectlyAdapted& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DirectlyAdapted>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__DirectlyAdapted(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DirectlyAdapted>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::DirectlyAdapted& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__field(
    Constructor<int32_t>{}
    .constructFrom(val.field_ref()));
  if (!_fbthrift__field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__DirectlyAdapted__tuple_pos[0],
          *_fbthrift__field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::detail::IndependentDirectlyAdapted>
Extractor<::facebook::thrift::test::detail::IndependentDirectlyAdapted>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a IndependentDirectlyAdapted");
      }
      return extractorError<::facebook::thrift::test::detail::IndependentDirectlyAdapted>(
          "Marshal error: IndependentDirectlyAdapted");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::detail::IndependentDirectlyAdapted>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::detail::IndependentDirectlyAdapted>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::IndependentDirectlyAdapted>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::IndependentDirectlyAdapted cpp;
  std::optional<std::string_view> error;
  Extractor<int32_t>{}.extractInto(
      cpp.field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__IndependentDirectlyAdapted__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::IndependentDirectlyAdapted>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__IndependentDirectlyAdapted(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: IndependentDirectlyAdapted");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::IndependentDirectlyAdapted>::operator()(
    const ::facebook::thrift::test::detail::IndependentDirectlyAdapted& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::IndependentDirectlyAdapted>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__IndependentDirectlyAdapted(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::IndependentDirectlyAdapted>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::IndependentDirectlyAdapted& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__field(
    Constructor<int32_t>{}
    .constructFrom(val.field_ref()));
  if (!_fbthrift__field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__IndependentDirectlyAdapted__tuple_pos[0],
          *_fbthrift__field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::StructWithFieldAdapter>
Extractor<::facebook::thrift::test::StructWithFieldAdapter>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::StructWithFieldAdapter>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__StructWithFieldAdapter(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::StructWithFieldAdapter>(
        "Thrift serialize error: StructWithFieldAdapter");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::StructWithFieldAdapter>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::StructWithFieldAdapter>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::StructWithFieldAdapter>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::StructWithFieldAdapter>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__StructWithFieldAdapter(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::StructWithFieldAdapter>(
          "Init from fbthrift error: StructWithFieldAdapter");
  }
  return Extractor<::facebook::thrift::test::StructWithFieldAdapter>{}(*obj);
}

int Extractor<::facebook::thrift::test::StructWithFieldAdapter>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__StructWithFieldAdapter(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: StructWithFieldAdapter");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::StructWithFieldAdapter>::operator()(
    const ::facebook::thrift::test::StructWithFieldAdapter& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__StructWithFieldAdapter(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::StructWithFieldAdapter>>::operator()(
    const ::facebook::thrift::test::StructWithFieldAdapter& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::StructWithFieldAdapter>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::TerseAdaptedFields>
Extractor<::facebook::thrift::test::TerseAdaptedFields>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::TerseAdaptedFields>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__TerseAdaptedFields(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::TerseAdaptedFields>(
        "Thrift serialize error: TerseAdaptedFields");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::TerseAdaptedFields>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::TerseAdaptedFields>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::TerseAdaptedFields>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::TerseAdaptedFields>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__TerseAdaptedFields(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::TerseAdaptedFields>(
          "Init from fbthrift error: TerseAdaptedFields");
  }
  return Extractor<::facebook::thrift::test::TerseAdaptedFields>{}(*obj);
}

int Extractor<::facebook::thrift::test::TerseAdaptedFields>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__TerseAdaptedFields(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: TerseAdaptedFields");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::TerseAdaptedFields>::operator()(
    const ::facebook::thrift::test::TerseAdaptedFields& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__TerseAdaptedFields(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::TerseAdaptedFields>>::operator()(
    const ::facebook::thrift::test::TerseAdaptedFields& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::TerseAdaptedFields>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::B>
Extractor<::facebook::thrift::test::B>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::B>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__B(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::B>(
        "Thrift serialize error: B");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::B>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::B>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::B>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::B>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__B(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::B>(
          "Init from fbthrift error: B");
  }
  return Extractor<::facebook::thrift::test::B>{}(*obj);
}

int Extractor<::facebook::thrift::test::B>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__B(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: B");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::B>::operator()(
    const ::facebook::thrift::test::B& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__B(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::B>>::operator()(
    const ::facebook::thrift::test::B& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::B>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::A>
Extractor<::facebook::thrift::test::A>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a A");
      }
      return extractorError<::facebook::thrift::test::A>(
          "Marshal error: A");
  }
  return ::facebook::thrift::test::A{};
}

ExtractorResult<::facebook::thrift::test::A>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::A>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::A cpp;
  (void)fbThriftData;
  return cpp;
}


int Extractor<::facebook::thrift::test::A>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__A(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: A");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::A>::operator()(
    const ::facebook::thrift::test::A& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::A>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__A(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::A>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::A& val) {
  StrongRef fbthrift_data(createStructTuple(0));
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::Config>
Extractor<::facebook::thrift::test::Config>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a Config");
      }
      return extractorError<::facebook::thrift::test::Config>(
          "Marshal error: Config");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::Config>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::Config>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Config>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::Config cpp;
  std::optional<std::string_view> error;
  Extractor<Bytes>{}.extractInto(
      cpp.path_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__Config__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::Config>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Config(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Config");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Config>::operator()(
    const ::facebook::thrift::test::Config& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Config>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__Config(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Config>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::Config& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__path(
    Constructor<Bytes>{}
    .constructFrom(val.path_ref()));
  if (!_fbthrift__path ||
      setStructField(
          *fbthrift_data,
          _fbthrift__Config__tuple_pos[0],
          *_fbthrift__path) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::MyStruct>
Extractor<::facebook::thrift::test::MyStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::MyStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__MyStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::MyStruct>(
        "Thrift serialize error: MyStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::MyStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::MyStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::MyStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::MyStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__MyStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::MyStruct>(
          "Init from fbthrift error: MyStruct");
  }
  return Extractor<::facebook::thrift::test::MyStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::MyStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__MyStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: MyStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::MyStruct>::operator()(
    const ::facebook::thrift::test::MyStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__MyStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::MyStruct>>::operator()(
    const ::facebook::thrift::test::MyStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::MyStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::AdaptTestStruct>
Extractor<::facebook::thrift::test::AdaptTestStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AdaptTestStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__AdaptTestStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::AdaptTestStruct>(
        "Thrift serialize error: AdaptTestStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::AdaptTestStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::AdaptTestStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::AdaptTestStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AdaptTestStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__AdaptTestStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::AdaptTestStruct>(
          "Init from fbthrift error: AdaptTestStruct");
  }
  return Extractor<::facebook::thrift::test::AdaptTestStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::AdaptTestStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AdaptTestStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AdaptTestStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::AdaptTestStruct>::operator()(
    const ::facebook::thrift::test::AdaptTestStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__AdaptTestStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::AdaptTestStruct>>::operator()(
    const ::facebook::thrift::test::AdaptTestStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::AdaptTestStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::AdaptTemplatedTestStruct>
Extractor<::facebook::thrift::test::AdaptTemplatedTestStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AdaptTemplatedTestStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__AdaptTemplatedTestStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::AdaptTemplatedTestStruct>(
        "Thrift serialize error: AdaptTemplatedTestStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::AdaptTemplatedTestStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::AdaptTemplatedTestStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::AdaptTemplatedTestStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AdaptTemplatedTestStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__AdaptTemplatedTestStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::AdaptTemplatedTestStruct>(
          "Init from fbthrift error: AdaptTemplatedTestStruct");
  }
  return Extractor<::facebook::thrift::test::AdaptTemplatedTestStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::AdaptTemplatedTestStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AdaptTemplatedTestStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AdaptTemplatedTestStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::AdaptTemplatedTestStruct>::operator()(
    const ::facebook::thrift::test::AdaptTemplatedTestStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__AdaptTemplatedTestStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::AdaptTemplatedTestStruct>>::operator()(
    const ::facebook::thrift::test::AdaptTemplatedTestStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::AdaptTemplatedTestStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>
Extractor<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a AdaptTemplatedNestedTestStruct");
      }
      return extractorError<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>(
          "Marshal error: AdaptTemplatedNestedTestStruct");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::AdaptTemplatedNestedTestStruct>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::AdaptTemplatedNestedTestStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::AdaptTemplatedNestedTestStruct cpp;
  std::optional<std::string_view> error;
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::AdaptTemplatedTestStruct>>{}.extractInto(
      cpp.adaptedStruct_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__AdaptTemplatedNestedTestStruct__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AdaptTemplatedNestedTestStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AdaptTemplatedNestedTestStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::AdaptTemplatedNestedTestStruct>::operator()(
    const ::facebook::thrift::test::AdaptTemplatedNestedTestStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::AdaptTemplatedNestedTestStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__AdaptTemplatedNestedTestStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::AdaptTemplatedNestedTestStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::AdaptTemplatedNestedTestStruct& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__adaptedStruct(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::AdaptTemplatedTestStruct>>{}
    .constructFrom(val.adaptedStruct_ref()));
  if (!_fbthrift__adaptedStruct ||
      setStructField(
          *fbthrift_data,
          _fbthrift__AdaptTemplatedNestedTestStruct__tuple_pos[0],
          *_fbthrift__adaptedStruct) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::ThriftAdaptTestUnion>
Extractor<::facebook::thrift::test::ThriftAdaptTestUnion>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::ThriftAdaptTestUnion>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__AdaptTestUnion(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::ThriftAdaptTestUnion>(
        "Thrift serialize error: AdaptTestUnion");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::ThriftAdaptTestUnion>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::ThriftAdaptTestUnion>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::ThriftAdaptTestUnion>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::ThriftAdaptTestUnion>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__AdaptTestUnion(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::ThriftAdaptTestUnion>(
          "Init from fbthrift error: AdaptTestUnion");
  }
  return Extractor<::facebook::thrift::test::ThriftAdaptTestUnion>{}(*obj);
}

int Extractor<::facebook::thrift::test::ThriftAdaptTestUnion>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AdaptTestUnion(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AdaptTestUnion");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::ThriftAdaptTestUnion>::operator()(
    const ::facebook::thrift::test::ThriftAdaptTestUnion& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__AdaptTestUnion(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ThriftAdaptTestUnion>>::operator()(
    const ::facebook::thrift::test::ThriftAdaptTestUnion& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::ThriftAdaptTestUnion>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::ThriftAdaptedStruct>
Extractor<::facebook::thrift::test::ThriftAdaptedStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a AdaptedStruct");
      }
      return extractorError<::facebook::thrift::test::ThriftAdaptedStruct>(
          "Marshal error: AdaptedStruct");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::ThriftAdaptedStruct>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::ThriftAdaptedStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::ThriftAdaptedStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::ThriftAdaptedStruct cpp;
  std::optional<std::string_view> error;
  Extractor<int64_t>{}.extractInto(
      cpp.data_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__AdaptedStruct__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::ThriftAdaptedStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AdaptedStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AdaptedStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::ThriftAdaptedStruct>::operator()(
    const ::facebook::thrift::test::ThriftAdaptedStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ThriftAdaptedStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__AdaptedStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ThriftAdaptedStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::ThriftAdaptedStruct& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__data(
    Constructor<int64_t>{}
    .constructFrom(val.data_ref()));
  if (!_fbthrift__data ||
      setStructField(
          *fbthrift_data,
          _fbthrift__AdaptedStruct__tuple_pos[0],
          *_fbthrift__data) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::detail::DirectlyAdaptedStruct>
Extractor<::facebook::thrift::test::detail::DirectlyAdaptedStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a DirectlyAdaptedStruct");
      }
      return extractorError<::facebook::thrift::test::detail::DirectlyAdaptedStruct>(
          "Marshal error: DirectlyAdaptedStruct");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::detail::DirectlyAdaptedStruct>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::detail::DirectlyAdaptedStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::DirectlyAdaptedStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::DirectlyAdaptedStruct cpp;
  std::optional<std::string_view> error;
  Extractor<int64_t>{}.extractInto(
      cpp.data_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__DirectlyAdaptedStruct__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::DirectlyAdaptedStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__DirectlyAdaptedStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: DirectlyAdaptedStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::DirectlyAdaptedStruct>::operator()(
    const ::facebook::thrift::test::detail::DirectlyAdaptedStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DirectlyAdaptedStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__DirectlyAdaptedStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DirectlyAdaptedStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::DirectlyAdaptedStruct& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__data(
    Constructor<int64_t>{}
    .constructFrom(val.data_ref()));
  if (!_fbthrift__data ||
      setStructField(
          *fbthrift_data,
          _fbthrift__DirectlyAdaptedStruct__tuple_pos[0],
          *_fbthrift__data) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::StructFieldAdaptedStruct>
Extractor<::facebook::thrift::test::StructFieldAdaptedStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::StructFieldAdaptedStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__StructFieldAdaptedStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::StructFieldAdaptedStruct>(
        "Thrift serialize error: StructFieldAdaptedStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::StructFieldAdaptedStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::StructFieldAdaptedStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::StructFieldAdaptedStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::StructFieldAdaptedStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__StructFieldAdaptedStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::StructFieldAdaptedStruct>(
          "Init from fbthrift error: StructFieldAdaptedStruct");
  }
  return Extractor<::facebook::thrift::test::StructFieldAdaptedStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::StructFieldAdaptedStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__StructFieldAdaptedStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: StructFieldAdaptedStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::StructFieldAdaptedStruct>::operator()(
    const ::facebook::thrift::test::StructFieldAdaptedStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__StructFieldAdaptedStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::StructFieldAdaptedStruct>>::operator()(
    const ::facebook::thrift::test::StructFieldAdaptedStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::StructFieldAdaptedStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::CircularAdaptee>
Extractor<::facebook::thrift::test::CircularAdaptee>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a CircularAdaptee");
      }
      return extractorError<::facebook::thrift::test::CircularAdaptee>(
          "Marshal error: CircularAdaptee");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::CircularAdaptee>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::CircularAdaptee>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::CircularAdaptee>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::CircularAdaptee cpp;
  std::optional<std::string_view> error;
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::CircularStruct>>{}.extractInto(
      cpp.field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__CircularAdaptee__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::CircularAdaptee>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__CircularAdaptee(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: CircularAdaptee");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::CircularAdaptee>::operator()(
    const ::facebook::thrift::test::CircularAdaptee& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::CircularAdaptee>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__CircularAdaptee(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::CircularAdaptee>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::CircularAdaptee& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::CircularStruct>>{}
    .constructFrom(val.field_ref()));
  if (!_fbthrift__field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__CircularAdaptee__tuple_pos[0],
          *_fbthrift__field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::CircularStruct>
Extractor<::facebook::thrift::test::CircularStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::CircularStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__CircularStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::CircularStruct>(
        "Thrift serialize error: CircularStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::CircularStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::CircularStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::CircularStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::CircularStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__CircularStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::CircularStruct>(
          "Init from fbthrift error: CircularStruct");
  }
  return Extractor<::facebook::thrift::test::CircularStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::CircularStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__CircularStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: CircularStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::CircularStruct>::operator()(
    const ::facebook::thrift::test::CircularStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__CircularStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::CircularStruct>>::operator()(
    const ::facebook::thrift::test::CircularStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::CircularStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::ReorderedStruct>
Extractor<::facebook::thrift::test::ReorderedStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::ReorderedStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__ReorderedStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::ReorderedStruct>(
        "Thrift serialize error: ReorderedStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::ReorderedStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::ReorderedStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::ReorderedStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::ReorderedStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__ReorderedStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::ReorderedStruct>(
          "Init from fbthrift error: ReorderedStruct");
  }
  return Extractor<::facebook::thrift::test::ReorderedStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::ReorderedStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__ReorderedStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: ReorderedStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::ReorderedStruct>::operator()(
    const ::facebook::thrift::test::ReorderedStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__ReorderedStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ReorderedStruct>>::operator()(
    const ::facebook::thrift::test::ReorderedStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::ReorderedStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::detail::DeclaredAfterStruct>
Extractor<::facebook::thrift::test::detail::DeclaredAfterStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a DeclaredAfterStruct");
      }
      return extractorError<::facebook::thrift::test::detail::DeclaredAfterStruct>(
          "Marshal error: DeclaredAfterStruct");
  }
  return ::facebook::thrift::test::detail::DeclaredAfterStruct{};
}

ExtractorResult<::facebook::thrift::test::detail::DeclaredAfterStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::DeclaredAfterStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::DeclaredAfterStruct cpp;
  (void)fbThriftData;
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::DeclaredAfterStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__DeclaredAfterStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: DeclaredAfterStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::DeclaredAfterStruct>::operator()(
    const ::facebook::thrift::test::detail::DeclaredAfterStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DeclaredAfterStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__DeclaredAfterStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::DeclaredAfterStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::DeclaredAfterStruct& val) {
  StrongRef fbthrift_data(createStructTuple(0));
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::UnderlyingRenamedStruct>
Extractor<::facebook::thrift::test::UnderlyingRenamedStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a RenamedStruct");
      }
      return extractorError<::facebook::thrift::test::UnderlyingRenamedStruct>(
          "Marshal error: RenamedStruct");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::UnderlyingRenamedStruct>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::UnderlyingRenamedStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::UnderlyingRenamedStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::UnderlyingRenamedStruct cpp;
  std::optional<std::string_view> error;
  Extractor<int64_t>{}.extractInto(
      cpp.data_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__RenamedStruct__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::UnderlyingRenamedStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__RenamedStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: RenamedStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::UnderlyingRenamedStruct>::operator()(
    const ::facebook::thrift::test::UnderlyingRenamedStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::UnderlyingRenamedStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__RenamedStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::UnderlyingRenamedStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::UnderlyingRenamedStruct& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__data(
    Constructor<int64_t>{}
    .constructFrom(val.data_ref()));
  if (!_fbthrift__data ||
      setStructField(
          *fbthrift_data,
          _fbthrift__RenamedStruct__tuple_pos[0],
          *_fbthrift__data) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::UnderlyingSameNamespaceStruct>
Extractor<::facebook::thrift::test::UnderlyingSameNamespaceStruct>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a SameNamespaceStruct");
      }
      return extractorError<::facebook::thrift::test::UnderlyingSameNamespaceStruct>(
          "Marshal error: SameNamespaceStruct");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::UnderlyingSameNamespaceStruct>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::UnderlyingSameNamespaceStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::UnderlyingSameNamespaceStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::UnderlyingSameNamespaceStruct cpp;
  std::optional<std::string_view> error;
  Extractor<int64_t>{}.extractInto(
      cpp.data_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__SameNamespaceStruct__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::UnderlyingSameNamespaceStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__SameNamespaceStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: SameNamespaceStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::UnderlyingSameNamespaceStruct>::operator()(
    const ::facebook::thrift::test::UnderlyingSameNamespaceStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::UnderlyingSameNamespaceStruct>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__SameNamespaceStruct(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::UnderlyingSameNamespaceStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::UnderlyingSameNamespaceStruct& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__data(
    Constructor<int64_t>{}
    .constructFrom(val.data_ref()));
  if (!_fbthrift__data ||
      setStructField(
          *fbthrift_data,
          _fbthrift__SameNamespaceStruct__tuple_pos[0],
          *_fbthrift__data) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::detail::HeapAllocated>
Extractor<::facebook::thrift::test::detail::HeapAllocated>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a HeapAllocated");
      }
      return extractorError<::facebook::thrift::test::detail::HeapAllocated>(
          "Marshal error: HeapAllocated");
  }
  return ::facebook::thrift::test::detail::HeapAllocated{};
}

ExtractorResult<::facebook::thrift::test::detail::HeapAllocated>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::HeapAllocated>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::HeapAllocated cpp;
  (void)fbThriftData;
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::HeapAllocated>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__HeapAllocated(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: HeapAllocated");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::HeapAllocated>::operator()(
    const ::facebook::thrift::test::detail::HeapAllocated& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::HeapAllocated>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__HeapAllocated(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::HeapAllocated>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::HeapAllocated& val) {
  StrongRef fbthrift_data(createStructTuple(0));
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::MoveOnly>
Extractor<::facebook::thrift::test::MoveOnly>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::MoveOnly>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__MoveOnly(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::MoveOnly>(
        "Thrift serialize error: MoveOnly");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::MoveOnly>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::MoveOnly>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::MoveOnly>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::MoveOnly>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__MoveOnly(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::MoveOnly>(
          "Init from fbthrift error: MoveOnly");
  }
  return Extractor<::facebook::thrift::test::MoveOnly>{}(*obj);
}

int Extractor<::facebook::thrift::test::MoveOnly>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__MoveOnly(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: MoveOnly");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::MoveOnly>::operator()(
    const ::facebook::thrift::test::MoveOnly& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__MoveOnly(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::MoveOnly>>::operator()(
    const ::facebook::thrift::test::MoveOnly& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::MoveOnly>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::AlsoMoveOnly>
Extractor<::facebook::thrift::test::AlsoMoveOnly>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AlsoMoveOnly>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__AlsoMoveOnly(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::AlsoMoveOnly>(
        "Thrift serialize error: AlsoMoveOnly");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::AlsoMoveOnly>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::AlsoMoveOnly>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::AlsoMoveOnly>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::AlsoMoveOnly>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__AlsoMoveOnly(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::AlsoMoveOnly>(
          "Init from fbthrift error: AlsoMoveOnly");
  }
  return Extractor<::facebook::thrift::test::AlsoMoveOnly>{}(*obj);
}

int Extractor<::facebook::thrift::test::AlsoMoveOnly>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__AlsoMoveOnly(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: AlsoMoveOnly");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::AlsoMoveOnly>::operator()(
    const ::facebook::thrift::test::AlsoMoveOnly& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__AlsoMoveOnly(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::AlsoMoveOnly>>::operator()(
    const ::facebook::thrift::test::AlsoMoveOnly& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::AlsoMoveOnly>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::ApplyAdapter>
Extractor<::facebook::thrift::test::ApplyAdapter>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a ApplyAdapter");
      }
      return extractorError<::facebook::thrift::test::ApplyAdapter>(
          "Marshal error: ApplyAdapter");
  }
  return ::facebook::thrift::test::ApplyAdapter{};
}

ExtractorResult<::facebook::thrift::test::ApplyAdapter>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::ApplyAdapter>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::ApplyAdapter cpp;
  (void)fbThriftData;
  return cpp;
}


int Extractor<::facebook::thrift::test::ApplyAdapter>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__ApplyAdapter(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: ApplyAdapter");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::ApplyAdapter>::operator()(
    const ::facebook::thrift::test::ApplyAdapter& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ApplyAdapter>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__ApplyAdapter(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::ApplyAdapter>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::ApplyAdapter& val) {
  StrongRef fbthrift_data(createStructTuple(0));
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::detail::TransitiveAdapted>
Extractor<::facebook::thrift::test::detail::TransitiveAdapted>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a TransitiveAdapted");
      }
      return extractorError<::facebook::thrift::test::detail::TransitiveAdapted>(
          "Marshal error: TransitiveAdapted");
  }
  return ::facebook::thrift::test::detail::TransitiveAdapted{};
}

ExtractorResult<::facebook::thrift::test::detail::TransitiveAdapted>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::detail::TransitiveAdapted>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::detail::TransitiveAdapted cpp;
  (void)fbThriftData;
  return cpp;
}


int Extractor<::facebook::thrift::test::detail::TransitiveAdapted>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__TransitiveAdapted(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: TransitiveAdapted");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::detail::TransitiveAdapted>::operator()(
    const ::facebook::thrift::test::detail::TransitiveAdapted& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::TransitiveAdapted>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__TransitiveAdapted(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::detail::TransitiveAdapted>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::detail::TransitiveAdapted& val) {
  StrongRef fbthrift_data(createStructTuple(0));
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::CountingStruct>
Extractor<::facebook::thrift::test::CountingStruct>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::CountingStruct>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__CountingStruct(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::CountingStruct>(
        "Thrift serialize error: CountingStruct");
  }
  return detail::deserialize_iobuf<::facebook::thrift::test::CountingStruct>(std::move(val));
}


ExtractorResult<::facebook::thrift::test::CountingStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::CountingStruct>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::CountingStruct>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__CountingStruct(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::CountingStruct>(
          "Init from fbthrift error: CountingStruct");
  }
  return Extractor<::facebook::thrift::test::CountingStruct>{}(*obj);
}

int Extractor<::facebook::thrift::test::CountingStruct>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__CountingStruct(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: CountingStruct");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::CountingStruct>::operator()(
    const ::facebook::thrift::test::CountingStruct& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_to_iobuf(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__CountingStruct(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::CountingStruct>>::operator()(
    const ::facebook::thrift::test::CountingStruct& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::CountingStruct>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::Person>
Extractor<::facebook::thrift::test::Person>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a Person");
      }
      return extractorError<::facebook::thrift::test::Person>(
          "Marshal error: Person");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::Person>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::Person>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Person>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::Person cpp;
  std::optional<std::string_view> error;
  Extractor<Bytes>{}.extractInto(
      cpp.name_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__Person__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::Person>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Person(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Person");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Person>::operator()(
    const ::facebook::thrift::test::Person& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Person>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__Person(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Person>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::Person& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__name(
    Constructor<Bytes>{}
    .constructFrom(val.name_ref()));
  if (!_fbthrift__name ||
      setStructField(
          *fbthrift_data,
          _fbthrift__Person__tuple_pos[0],
          *_fbthrift__name) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::Person2>
Extractor<::facebook::thrift::test::Person2>::operator()(PyObject* obj) {
  int tCheckResult = typeCheck(obj);
  if (tCheckResult != 1) {
      if (tCheckResult == 0) {
        PyErr_SetString(PyExc_TypeError, "Not a Person2");
      }
      return extractorError<::facebook::thrift::test::Person2>(
          "Marshal error: Person2");
  }
  StrongRef fbThriftData(getThriftData(obj));
  return Extractor<::apache::thrift::python::capi::ComposedStruct<
      ::facebook::thrift::test::Person2>>{}(*fbThriftData);
}

ExtractorResult<::facebook::thrift::test::Person2>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Person2>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::Person2 cpp;
  std::optional<std::string_view> error;
  Extractor<Bytes>{}.extractInto(
      cpp.name_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__Person2__tuple_pos[0]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


int Extractor<::facebook::thrift::test::Person2>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Person2(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Person2");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Person2>::operator()(
    const ::facebook::thrift::test::Person2& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Person2>> ctor;
  StrongRef fbthrift_data(ctor(val));
  if (!fbthrift_data) {
    return nullptr;
  }
  return init__facebook__thrift__test__module__Person2(*fbthrift_data);
}

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Person2>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::Person2& val) {
  StrongRef fbthrift_data(createStructTuple(1));
  StrongRef _fbthrift__name(
    Constructor<Bytes>{}
    .constructFrom(val.name_ref()));
  if (!_fbthrift__name ||
      setStructField(
          *fbthrift_data,
          _fbthrift__Person2__tuple_pos[0],
          *_fbthrift__name) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


ExtractorResult<::facebook::thrift::test::Renamed>
Extractor<::facebook::thrift::test::Renamed>::operator()(PyObject* obj) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Renamed>(
      "Module facebook.thrift.test.module import error");
  }
  std::unique_ptr<folly::IOBuf> val(
      extract__facebook__thrift__test__module__RenamedStructWithStructAdapterAndFieldAdapter(obj));
  if (!val) {
    CHECK(PyErr_Occurred());
    return extractorError<::facebook::thrift::test::Renamed>(
        "Thrift serialize error: RenamedStructWithStructAdapterAndFieldAdapter");
  }
  return detail::deserialize_iobuf_to_adapted<
      ::facebook::thrift::test::Renamed, ::apache::thrift::test::StructAdapter
    >(std::move(val));
}


ExtractorResult<::facebook::thrift::test::Renamed>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::Renamed>>::operator()(PyObject* fbthrift_data) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return extractorError<::facebook::thrift::test::Renamed>(
      "Module facebook.thrift.test.module import error");
  }
  auto obj = StrongRef(init__facebook__thrift__test__module__RenamedStructWithStructAdapterAndFieldAdapter(fbthrift_data));
  if (!obj) {
      return extractorError<::facebook::thrift::test::Renamed>(
          "Init from fbthrift error: RenamedStructWithStructAdapterAndFieldAdapter");
  }
  return Extractor<::facebook::thrift::test::Renamed>{}(*obj);
}

int Extractor<::facebook::thrift::test::Renamed>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__RenamedStructWithStructAdapterAndFieldAdapter(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: RenamedStructWithStructAdapterAndFieldAdapter");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Renamed>::operator()(
    const ::facebook::thrift::test::Renamed& val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  ::std::unique_ptr<::folly::IOBuf> serialized;
  try {
    serialized = detail::serialize_adapted_to_iobuf<::apache::thrift::test::StructAdapter>(val);
  } catch (const apache::thrift::TProtocolException& e) {
    detail::handle_protocol_error(e);
    return nullptr;
  }
  DCHECK(serialized);
  auto ptr = construct__facebook__thrift__test__module__RenamedStructWithStructAdapterAndFieldAdapter(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::Renamed>>::operator()(
    const ::facebook::thrift::test::Renamed& val) {
  auto obj = StrongRef(Constructor<::facebook::thrift::test::Renamed>{}(val));
  if (!obj) {
    return nullptr;
  }
  return getThriftData(*obj);
}

ExtractorResult<::facebook::thrift::test::Color>
Extractor<::facebook::thrift::test::Color>::operator()(PyObject* obj) {
  long val = PyLong_AsLong(obj);
  if (val == -1 && PyErr_Occurred()) {
    return extractorError<::facebook::thrift::test::Color>(
        "Error getting python int value: Color");
  }
  return static_cast<::facebook::thrift::test::Color>(val);
}

int Extractor<::facebook::thrift::test::Color>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__Color(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: Color");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::Color>::operator()(
    ::facebook::thrift::test::Color val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  auto ptr = construct__facebook__thrift__test__module__Color(
      static_cast<int64_t>(val));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}

ExtractorResult<::facebook::thrift::test::ThriftAdaptedEnum>
Extractor<::facebook::thrift::test::ThriftAdaptedEnum>::operator()(PyObject* obj) {
  long val = PyLong_AsLong(obj);
  if (val == -1 && PyErr_Occurred()) {
    return extractorError<::facebook::thrift::test::ThriftAdaptedEnum>(
        "Error getting python int value: ThriftAdaptedEnum");
  }
  return static_cast<::facebook::thrift::test::ThriftAdaptedEnum>(val);
}

int Extractor<::facebook::thrift::test::ThriftAdaptedEnum>::typeCheck(PyObject* obj) {
  if (!ensure_module_imported()) {
    ::folly::python::handlePythonError(
      "Module facebook.thrift.test.module import error");
  }
  int result =
      can_extract__facebook__thrift__test__module__ThriftAdaptedEnum(obj);
  if (result < 0) {
    ::folly::python::handlePythonError(
      "Unexpected type check error: ThriftAdaptedEnum");
  }
  return result;
}


PyObject* Constructor<::facebook::thrift::test::ThriftAdaptedEnum>::operator()(
    ::facebook::thrift::test::ThriftAdaptedEnum val) {
  if (!ensure_module_imported()) {
    DCHECK(PyErr_Occurred() != nullptr);
    return nullptr;
  }
  auto ptr = construct__facebook__thrift__test__module__ThriftAdaptedEnum(
      static_cast<int64_t>(val));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}

} // namespace capi
} // namespace python
} // namespace thrift
} // namespace apache
