
/**
 * 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/terse_write/gen-python-capi/terse_write/thrift_types_api.h>
#include <thrift/compiler/test/fixtures/terse_write/gen-python-capi/terse_write/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__terse_write__thrift_types_capi));
  return import();
}
  static constexpr std::int16_t _fbthrift__MyStructWithCustomDefault__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__StructLevelTerseStruct__tuple_pos[15] = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
  };
  static constexpr std::int16_t _fbthrift__FieldLevelTerseStruct__tuple_pos[30] = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 29, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 30
  };
  static constexpr std::int16_t _fbthrift__TerseStructWithCustomDefault__tuple_pos[14] = {
    1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
  };
  static constexpr std::int16_t _fbthrift__WrappedFields__tuple_pos[1] = {
    1
  };
  static constexpr std::int16_t _fbthrift__TerseException__tuple_pos[1] = {
    1
  };
} // namespace

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

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


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


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

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


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

ExtractorResult<::facebook::thrift::test::terse_write::MyUnion>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::terse_write::MyUnion>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::terse_write::MyUnion cpp;
  std::optional<std::string_view> error;
  auto type_tag = Extractor<int64_t>{}(PyTuple_GET_ITEM(fbThriftData, 0));
  if (type_tag.hasError()) {
    return folly::makeUnexpected(type_tag.error());
  }
  switch (*type_tag) {
    case 0:
      break; // union is unset
    case 1:
      Extractor<bool>{}.extractInto(
          cpp.bool_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 2:
      Extractor<int8_t>{}.extractInto(
          cpp.byte_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 3:
      Extractor<int16_t>{}.extractInto(
          cpp.short_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 4:
      Extractor<int32_t>{}.extractInto(
          cpp.int_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 5:
      Extractor<int64_t>{}.extractInto(
          cpp.long_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 6:
      Extractor<float>{}.extractInto(
          cpp.float_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 7:
      Extractor<double>{}.extractInto(
          cpp.double_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 8:
      Extractor<Bytes>{}.extractInto(
          cpp.string_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 9:
      Extractor<Bytes>{}.extractInto(
          cpp.binary_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 10:
      Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}.extractInto(
          cpp.enum_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 11:
      Extractor<list<int16_t>>{}.extractInto(
          cpp.list_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 12:
      Extractor<set<int16_t>>{}.extractInto(
          cpp.set_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 13:
      Extractor<map<int16_t, int16_t>>{}.extractInto(
          cpp.map_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
    case 14:
      Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}.extractInto(
          cpp.struct_field_ref(), PyTuple_GET_ITEM(fbThriftData, 1), error);
      break;
  }
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


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


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

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::terse_write::MyUnion>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::terse_write::MyUnion& val) {
  int64_t type_key = static_cast<int64_t>(val.getType());
  StrongRef py_val;
  switch (type_key) {
    case 0:
      Py_INCREF(Py_None);
      py_val = StrongRef(Py_None);
      break;
    case 1:
      py_val = StrongRef(
          Constructor<bool>{}
          .constructFrom(val.bool_field_ref()));
      break;
    case 2:
      py_val = StrongRef(
          Constructor<int8_t>{}
          .constructFrom(val.byte_field_ref()));
      break;
    case 3:
      py_val = StrongRef(
          Constructor<int16_t>{}
          .constructFrom(val.short_field_ref()));
      break;
    case 4:
      py_val = StrongRef(
          Constructor<int32_t>{}
          .constructFrom(val.int_field_ref()));
      break;
    case 5:
      py_val = StrongRef(
          Constructor<int64_t>{}
          .constructFrom(val.long_field_ref()));
      break;
    case 6:
      py_val = StrongRef(
          Constructor<float>{}
          .constructFrom(val.float_field_ref()));
      break;
    case 7:
      py_val = StrongRef(
          Constructor<double>{}
          .constructFrom(val.double_field_ref()));
      break;
    case 8:
      py_val = StrongRef(
          Constructor<Bytes>{}
          .constructFrom(val.string_field_ref()));
      break;
    case 9:
      py_val = StrongRef(
          Constructor<Bytes>{}
          .constructFrom(val.binary_field_ref()));
      break;
    case 10:
      py_val = StrongRef(
          Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}
          .constructFrom(val.enum_field_ref()));
      break;
    case 11:
      py_val = StrongRef(
          Constructor<list<int16_t>>{}
          .constructFrom(val.list_field_ref()));
      break;
    case 12:
      py_val = StrongRef(
          Constructor<set<int16_t>>{}
          .constructFrom(val.set_field_ref()));
      break;
    case 13:
      py_val = StrongRef(
          Constructor<map<int16_t, int16_t>>{}
          .constructFrom(val.map_field_ref()));
      break;
    case 14:
      py_val = StrongRef(
          Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}
          .constructFrom(val.struct_field_ref()));
      break;
  }
  if (!py_val) {
    return nullptr;
  }
  return unionTupleFromValue(type_key, *py_val);
}


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

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


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


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

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


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

ExtractorResult<::facebook::thrift::test::terse_write::StructLevelTerseStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::terse_write::StructLevelTerseStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::terse_write::StructLevelTerseStruct cpp;
  std::optional<std::string_view> error;
  Extractor<bool>{}.extractInto(
      cpp.bool_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[0]),
      error);
  Extractor<int8_t>{}.extractInto(
      cpp.byte_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[1]),
      error);
  Extractor<int16_t>{}.extractInto(
      cpp.short_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[2]),
      error);
  Extractor<int32_t>{}.extractInto(
      cpp.int_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[3]),
      error);
  Extractor<int64_t>{}.extractInto(
      cpp.long_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[4]),
      error);
  Extractor<float>{}.extractInto(
      cpp.float_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[5]),
      error);
  Extractor<double>{}.extractInto(
      cpp.double_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[6]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.string_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[7]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.binary_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[8]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}.extractInto(
      cpp.enum_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[9]),
      error);
  Extractor<list<int16_t>>{}.extractInto(
      cpp.list_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[10]),
      error);
  Extractor<set<int16_t>>{}.extractInto(
      cpp.set_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[11]),
      error);
  Extractor<map<int16_t, int16_t>>{}.extractInto(
      cpp.map_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[12]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}.extractInto(
      cpp.struct_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[13]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}.extractInto(
      cpp.union_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__StructLevelTerseStruct__tuple_pos[14]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


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


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

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::terse_write::StructLevelTerseStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::terse_write::StructLevelTerseStruct& val) {
  StrongRef fbthrift_data(createStructTuple(15));
  StrongRef _fbthrift__bool_field(
    Constructor<bool>{}
    .constructFrom(val.bool_field_ref()));
  if (!_fbthrift__bool_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[0],
          *_fbthrift__bool_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__byte_field(
    Constructor<int8_t>{}
    .constructFrom(val.byte_field_ref()));
  if (!_fbthrift__byte_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[1],
          *_fbthrift__byte_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__short_field(
    Constructor<int16_t>{}
    .constructFrom(val.short_field_ref()));
  if (!_fbthrift__short_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[2],
          *_fbthrift__short_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__int_field(
    Constructor<int32_t>{}
    .constructFrom(val.int_field_ref()));
  if (!_fbthrift__int_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[3],
          *_fbthrift__int_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__long_field(
    Constructor<int64_t>{}
    .constructFrom(val.long_field_ref()));
  if (!_fbthrift__long_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[4],
          *_fbthrift__long_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__float_field(
    Constructor<float>{}
    .constructFrom(val.float_field_ref()));
  if (!_fbthrift__float_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[5],
          *_fbthrift__float_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__double_field(
    Constructor<double>{}
    .constructFrom(val.double_field_ref()));
  if (!_fbthrift__double_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[6],
          *_fbthrift__double_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__string_field(
    Constructor<Bytes>{}
    .constructFrom(val.string_field_ref()));
  if (!_fbthrift__string_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[7],
          *_fbthrift__string_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__binary_field(
    Constructor<Bytes>{}
    .constructFrom(val.binary_field_ref()));
  if (!_fbthrift__binary_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[8],
          *_fbthrift__binary_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__enum_field(
    Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}
    .constructFrom(val.enum_field_ref()));
  if (!_fbthrift__enum_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[9],
          *_fbthrift__enum_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__list_field(
    Constructor<list<int16_t>>{}
    .constructFrom(val.list_field_ref()));
  if (!_fbthrift__list_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[10],
          *_fbthrift__list_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__set_field(
    Constructor<set<int16_t>>{}
    .constructFrom(val.set_field_ref()));
  if (!_fbthrift__set_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[11],
          *_fbthrift__set_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__map_field(
    Constructor<map<int16_t, int16_t>>{}
    .constructFrom(val.map_field_ref()));
  if (!_fbthrift__map_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[12],
          *_fbthrift__map_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__struct_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}
    .constructFrom(val.struct_field_ref()));
  if (!_fbthrift__struct_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[13],
          *_fbthrift__struct_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__union_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}
    .constructFrom(val.union_field_ref()));
  if (!_fbthrift__union_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__StructLevelTerseStruct__tuple_pos[14],
          *_fbthrift__union_field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


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

ExtractorResult<::facebook::thrift::test::terse_write::FieldLevelTerseStruct>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::terse_write::FieldLevelTerseStruct>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::terse_write::FieldLevelTerseStruct cpp;
  std::optional<std::string_view> error;
  Extractor<bool>{}.extractInto(
      cpp.terse_bool_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[0]),
      error);
  Extractor<int8_t>{}.extractInto(
      cpp.terse_byte_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[1]),
      error);
  Extractor<int16_t>{}.extractInto(
      cpp.terse_short_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[2]),
      error);
  Extractor<int32_t>{}.extractInto(
      cpp.terse_int_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[3]),
      error);
  Extractor<int64_t>{}.extractInto(
      cpp.terse_long_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[4]),
      error);
  Extractor<float>{}.extractInto(
      cpp.terse_float_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[5]),
      error);
  Extractor<double>{}.extractInto(
      cpp.terse_double_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[6]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.terse_string_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[7]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.terse_binary_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[8]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}.extractInto(
      cpp.terse_enum_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[9]),
      error);
  Extractor<list<int16_t>>{}.extractInto(
      cpp.terse_list_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[10]),
      error);
  Extractor<set<int16_t>>{}.extractInto(
      cpp.terse_set_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[11]),
      error);
  Extractor<map<int16_t, int16_t>>{}.extractInto(
      cpp.terse_map_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[12]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}.extractInto(
      cpp.terse_struct_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[13]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}.extractInto(
      cpp.terse_union_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[14]),
      error);
  Extractor<bool>{}.extractInto(
      cpp.bool_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[15]),
      error);
  Extractor<int8_t>{}.extractInto(
      cpp.byte_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[16]),
      error);
  Extractor<int16_t>{}.extractInto(
      cpp.short_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[17]),
      error);
  Extractor<int32_t>{}.extractInto(
      cpp.int_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[18]),
      error);
  Extractor<int64_t>{}.extractInto(
      cpp.long_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[19]),
      error);
  Extractor<float>{}.extractInto(
      cpp.float_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[20]),
      error);
  Extractor<double>{}.extractInto(
      cpp.double_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[21]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.string_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[22]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.binary_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[23]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}.extractInto(
      cpp.enum_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[24]),
      error);
  Extractor<list<int16_t>>{}.extractInto(
      cpp.list_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[25]),
      error);
  Extractor<set<int16_t>>{}.extractInto(
      cpp.set_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[26]),
      error);
  Extractor<map<int16_t, int16_t>>{}.extractInto(
      cpp.map_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[27]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}.extractInto(
      cpp.struct_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[28]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}.extractInto(
      cpp.union_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__FieldLevelTerseStruct__tuple_pos[29]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


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


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

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::terse_write::FieldLevelTerseStruct>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::terse_write::FieldLevelTerseStruct& val) {
  StrongRef fbthrift_data(createStructTuple(30));
  StrongRef _fbthrift__terse_bool_field(
    Constructor<bool>{}
    .constructFrom(val.terse_bool_field_ref()));
  if (!_fbthrift__terse_bool_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[0],
          *_fbthrift__terse_bool_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_byte_field(
    Constructor<int8_t>{}
    .constructFrom(val.terse_byte_field_ref()));
  if (!_fbthrift__terse_byte_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[1],
          *_fbthrift__terse_byte_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_short_field(
    Constructor<int16_t>{}
    .constructFrom(val.terse_short_field_ref()));
  if (!_fbthrift__terse_short_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[2],
          *_fbthrift__terse_short_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_int_field(
    Constructor<int32_t>{}
    .constructFrom(val.terse_int_field_ref()));
  if (!_fbthrift__terse_int_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[3],
          *_fbthrift__terse_int_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_long_field(
    Constructor<int64_t>{}
    .constructFrom(val.terse_long_field_ref()));
  if (!_fbthrift__terse_long_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[4],
          *_fbthrift__terse_long_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_float_field(
    Constructor<float>{}
    .constructFrom(val.terse_float_field_ref()));
  if (!_fbthrift__terse_float_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[5],
          *_fbthrift__terse_float_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_double_field(
    Constructor<double>{}
    .constructFrom(val.terse_double_field_ref()));
  if (!_fbthrift__terse_double_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[6],
          *_fbthrift__terse_double_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_string_field(
    Constructor<Bytes>{}
    .constructFrom(val.terse_string_field_ref()));
  if (!_fbthrift__terse_string_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[7],
          *_fbthrift__terse_string_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_binary_field(
    Constructor<Bytes>{}
    .constructFrom(val.terse_binary_field_ref()));
  if (!_fbthrift__terse_binary_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[8],
          *_fbthrift__terse_binary_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_enum_field(
    Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}
    .constructFrom(val.terse_enum_field_ref()));
  if (!_fbthrift__terse_enum_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[9],
          *_fbthrift__terse_enum_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_list_field(
    Constructor<list<int16_t>>{}
    .constructFrom(val.terse_list_field_ref()));
  if (!_fbthrift__terse_list_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[10],
          *_fbthrift__terse_list_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_set_field(
    Constructor<set<int16_t>>{}
    .constructFrom(val.terse_set_field_ref()));
  if (!_fbthrift__terse_set_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[11],
          *_fbthrift__terse_set_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_map_field(
    Constructor<map<int16_t, int16_t>>{}
    .constructFrom(val.terse_map_field_ref()));
  if (!_fbthrift__terse_map_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[12],
          *_fbthrift__terse_map_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_struct_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}
    .constructFrom(val.terse_struct_field_ref()));
  if (!_fbthrift__terse_struct_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[13],
          *_fbthrift__terse_struct_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__terse_union_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}
    .constructFrom(val.terse_union_field_ref()));
  if (!_fbthrift__terse_union_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[14],
          *_fbthrift__terse_union_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__bool_field(
    Constructor<bool>{}
    .constructFrom(val.bool_field_ref()));
  if (!_fbthrift__bool_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[15],
          *_fbthrift__bool_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__byte_field(
    Constructor<int8_t>{}
    .constructFrom(val.byte_field_ref()));
  if (!_fbthrift__byte_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[16],
          *_fbthrift__byte_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__short_field(
    Constructor<int16_t>{}
    .constructFrom(val.short_field_ref()));
  if (!_fbthrift__short_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[17],
          *_fbthrift__short_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__int_field(
    Constructor<int32_t>{}
    .constructFrom(val.int_field_ref()));
  if (!_fbthrift__int_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[18],
          *_fbthrift__int_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__long_field(
    Constructor<int64_t>{}
    .constructFrom(val.long_field_ref()));
  if (!_fbthrift__long_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[19],
          *_fbthrift__long_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__float_field(
    Constructor<float>{}
    .constructFrom(val.float_field_ref()));
  if (!_fbthrift__float_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[20],
          *_fbthrift__float_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__double_field(
    Constructor<double>{}
    .constructFrom(val.double_field_ref()));
  if (!_fbthrift__double_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[21],
          *_fbthrift__double_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__string_field(
    Constructor<Bytes>{}
    .constructFrom(val.string_field_ref()));
  if (!_fbthrift__string_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[22],
          *_fbthrift__string_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__binary_field(
    Constructor<Bytes>{}
    .constructFrom(val.binary_field_ref()));
  if (!_fbthrift__binary_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[23],
          *_fbthrift__binary_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__enum_field(
    Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}
    .constructFrom(val.enum_field_ref()));
  if (!_fbthrift__enum_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[24],
          *_fbthrift__enum_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__list_field(
    Constructor<list<int16_t>>{}
    .constructFrom(val.list_field_ref()));
  if (!_fbthrift__list_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[25],
          *_fbthrift__list_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__set_field(
    Constructor<set<int16_t>>{}
    .constructFrom(val.set_field_ref()));
  if (!_fbthrift__set_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[26],
          *_fbthrift__set_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__map_field(
    Constructor<map<int16_t, int16_t>>{}
    .constructFrom(val.map_field_ref()));
  if (!_fbthrift__map_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[27],
          *_fbthrift__map_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__struct_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStruct>>{}
    .constructFrom(val.struct_field_ref()));
  if (!_fbthrift__struct_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[28],
          *_fbthrift__struct_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__union_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyUnion>>{}
    .constructFrom(val.union_field_ref()));
  if (!_fbthrift__union_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__FieldLevelTerseStruct__tuple_pos[29],
          *_fbthrift__union_field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


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

ExtractorResult<::facebook::thrift::test::terse_write::TerseStructWithCustomDefault>
Extractor<::apache::thrift::python::capi::ComposedStruct<
    ::facebook::thrift::test::terse_write::TerseStructWithCustomDefault>>::operator()(PyObject* fbThriftData) {
  ::facebook::thrift::test::terse_write::TerseStructWithCustomDefault cpp;
  std::optional<std::string_view> error;
  Extractor<bool>{}.extractInto(
      cpp.bool_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[0]),
      error);
  Extractor<int8_t>{}.extractInto(
      cpp.byte_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[1]),
      error);
  Extractor<int16_t>{}.extractInto(
      cpp.short_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[2]),
      error);
  Extractor<int32_t>{}.extractInto(
      cpp.int_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[3]),
      error);
  Extractor<int64_t>{}.extractInto(
      cpp.long_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[4]),
      error);
  Extractor<float>{}.extractInto(
      cpp.float_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[5]),
      error);
  Extractor<double>{}.extractInto(
      cpp.double_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[6]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.string_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[7]),
      error);
  Extractor<Bytes>{}.extractInto(
      cpp.binary_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[8]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}.extractInto(
      cpp.enum_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[9]),
      error);
  Extractor<list<int16_t>>{}.extractInto(
      cpp.list_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[10]),
      error);
  Extractor<set<int16_t>>{}.extractInto(
      cpp.set_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[11]),
      error);
  Extractor<map<int16_t, int16_t>>{}.extractInto(
      cpp.map_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[12]),
      error);
  Extractor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStructWithCustomDefault>>{}.extractInto(
      cpp.struct_field_ref(),
      PyTuple_GET_ITEM(fbThriftData, _fbthrift__TerseStructWithCustomDefault__tuple_pos[13]),
      error);
  if (error) {
    return folly::makeUnexpected(*error);
  }
  return cpp;
}


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


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

PyObject* Constructor<::apache::thrift::python::capi::ComposedStruct<
        ::facebook::thrift::test::terse_write::TerseStructWithCustomDefault>>::operator()(
    [[maybe_unused]] const ::facebook::thrift::test::terse_write::TerseStructWithCustomDefault& val) {
  StrongRef fbthrift_data(createStructTuple(14));
  StrongRef _fbthrift__bool_field(
    Constructor<bool>{}
    .constructFrom(val.bool_field_ref()));
  if (!_fbthrift__bool_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[0],
          *_fbthrift__bool_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__byte_field(
    Constructor<int8_t>{}
    .constructFrom(val.byte_field_ref()));
  if (!_fbthrift__byte_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[1],
          *_fbthrift__byte_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__short_field(
    Constructor<int16_t>{}
    .constructFrom(val.short_field_ref()));
  if (!_fbthrift__short_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[2],
          *_fbthrift__short_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__int_field(
    Constructor<int32_t>{}
    .constructFrom(val.int_field_ref()));
  if (!_fbthrift__int_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[3],
          *_fbthrift__int_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__long_field(
    Constructor<int64_t>{}
    .constructFrom(val.long_field_ref()));
  if (!_fbthrift__long_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[4],
          *_fbthrift__long_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__float_field(
    Constructor<float>{}
    .constructFrom(val.float_field_ref()));
  if (!_fbthrift__float_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[5],
          *_fbthrift__float_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__double_field(
    Constructor<double>{}
    .constructFrom(val.double_field_ref()));
  if (!_fbthrift__double_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[6],
          *_fbthrift__double_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__string_field(
    Constructor<Bytes>{}
    .constructFrom(val.string_field_ref()));
  if (!_fbthrift__string_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[7],
          *_fbthrift__string_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__binary_field(
    Constructor<Bytes>{}
    .constructFrom(val.binary_field_ref()));
  if (!_fbthrift__binary_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[8],
          *_fbthrift__binary_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__enum_field(
    Constructor<::apache::thrift::python::capi::ComposedEnum<::facebook::thrift::test::terse_write::MyEnum>>{}
    .constructFrom(val.enum_field_ref()));
  if (!_fbthrift__enum_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[9],
          *_fbthrift__enum_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__list_field(
    Constructor<list<int16_t>>{}
    .constructFrom(val.list_field_ref()));
  if (!_fbthrift__list_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[10],
          *_fbthrift__list_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__set_field(
    Constructor<set<int16_t>>{}
    .constructFrom(val.set_field_ref()));
  if (!_fbthrift__set_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[11],
          *_fbthrift__set_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__map_field(
    Constructor<map<int16_t, int16_t>>{}
    .constructFrom(val.map_field_ref()));
  if (!_fbthrift__map_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[12],
          *_fbthrift__map_field) == -1) {
    return nullptr;
  }
  StrongRef _fbthrift__struct_field(
    Constructor<::apache::thrift::python::capi::ComposedStruct<::facebook::thrift::test::terse_write::MyStructWithCustomDefault>>{}
    .constructFrom(val.struct_field_ref()));
  if (!_fbthrift__struct_field ||
      setStructField(
          *fbthrift_data,
          _fbthrift__TerseStructWithCustomDefault__tuple_pos[13],
          *_fbthrift__struct_field) == -1) {
    return nullptr;
  }
  return std::move(fbthrift_data).release();
}


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


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

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


PyObject* Constructor<::facebook::thrift::test::terse_write::AdaptedFields>::operator()(
    const ::facebook::thrift::test::terse_write::AdaptedFields& 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__terse_write__AdaptedFields(std::move(serialized));
  if (!ptr) {
    CHECK(PyErr_Occurred());
  }
  return ptr;
}


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

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

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


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


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

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


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

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


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


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

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


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

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


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

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