Skip to content

Commit

Permalink
Add Containers to the complex-struct fixture
Browse files Browse the repository at this point in the history
Summary: Add `Containers` to complex-struct fixture to sample the cases where container elements are structs, unions or other containers.

Reviewed By: iahs, vitaut

Differential Revision: D67674109

fbshipit-source-id: 7124fa99dd9316c21c263ad30887f1d782a3060c
  • Loading branch information
yoney authored and facebook-github-bot committed Dec 27, 2024
1 parent adbfa28 commit 350c183
Show file tree
Hide file tree
Showing 27 changed files with 7,437 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ ::cpp2::MyUnion const& constEnumUnion() {
}


::std::string_view _fbthrift_schema_711abdb343f078bf() {
::std::string_view _fbthrift_schema_26752209a8354ec6() {
return "";
}
::folly::Range<const ::std::string_view*> _fbthrift_schema_711abdb343f078bf_includes() {
::folly::Range<const ::std::string_view*> _fbthrift_schema_26752209a8354ec6_includes() {
return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace module_constants {
/** Glean {"constant": "constEnumUnion"} */
::cpp2::MyUnion const& constEnumUnion();

FOLLY_EXPORT ::std::string_view _fbthrift_schema_711abdb343f078bf();
FOLLY_EXPORT ::folly::Range<const ::std::string_view*> _fbthrift_schema_711abdb343f078bf_includes();
FOLLY_EXPORT ::std::string_view _fbthrift_schema_26752209a8354ec6();
FOLLY_EXPORT ::folly::Range<const ::std::string_view*> _fbthrift_schema_26752209a8354ec6_includes();

} // namespace module_constants
} // namespace cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -758,5 +758,107 @@ THRIFT_DATA_MEMBER const std::array<int, 6> TStructDataStorage<::cpp2::complexEx
5,
}};

THRIFT_DATA_MEMBER const std::string_view TStructDataStorage<::cpp2::Containers>::name = "Containers";
THRIFT_DATA_MEMBER const std::array<std::string_view, 18> TStructDataStorage<::cpp2::Containers>::fields_names = { {
"struct_list"sv,
"union_list"sv,
"enum_list"sv,
"struct_set"sv,
"union_set"sv,
"enum_set"sv,
"struct_map"sv,
"union_map"sv,
"enum_map"sv,
"struct_map_2"sv,
"union_map_2"sv,
"enum_map_2"sv,
"list_map"sv,
"list_map_2"sv,
"set_map"sv,
"set_map_2"sv,
"map_map"sv,
"map_map_2"sv,
}};
THRIFT_DATA_MEMBER const std::array<int16_t, 18> TStructDataStorage<::cpp2::Containers>::fields_ids = { {
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
}};
THRIFT_DATA_MEMBER const std::array<protocol::TType, 18> TStructDataStorage<::cpp2::Containers>::fields_types = { {
TType::T_LIST,
TType::T_LIST,
TType::T_LIST,
TType::T_SET,
TType::T_SET,
TType::T_SET,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
TType::T_MAP,
}};
THRIFT_DATA_MEMBER const std::array<std::string_view, 18> TStructDataStorage<::cpp2::Containers>::storage_names = { {
"__fbthrift_field_struct_list"sv,
"__fbthrift_field_union_list"sv,
"__fbthrift_field_enum_list"sv,
"__fbthrift_field_struct_set"sv,
"__fbthrift_field_union_set"sv,
"__fbthrift_field_enum_set"sv,
"__fbthrift_field_struct_map"sv,
"__fbthrift_field_union_map"sv,
"__fbthrift_field_enum_map"sv,
"__fbthrift_field_struct_map_2"sv,
"__fbthrift_field_union_map_2"sv,
"__fbthrift_field_enum_map_2"sv,
"__fbthrift_field_list_map"sv,
"__fbthrift_field_list_map_2"sv,
"__fbthrift_field_set_map"sv,
"__fbthrift_field_set_map_2"sv,
"__fbthrift_field_map_map"sv,
"__fbthrift_field_map_map_2"sv,
}};
THRIFT_DATA_MEMBER const std::array<int, 18> TStructDataStorage<::cpp2::Containers>::isset_indexes = { {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
}};

} // namespace thrift
} // namespace apache
Original file line number Diff line number Diff line change
Expand Up @@ -309,4 +309,20 @@ template <> struct TStructDataStorage<::cpp2::complexException> {
static const std::array<int, fields_size> isset_indexes;
};

template <> struct TStructDataStorage<::cpp2::Containers> {
static constexpr const std::size_t fields_size = 18;
static const std::string_view name;
static const std::array<std::string_view, fields_size> fields_names;
static const std::array<int16_t, fields_size> fields_ids;
static const std::array<protocol::TType, fields_size> fields_types;

private:
// The following fields describe internal storage metadata, and are private to
// prevent user logic from accessing them, but they can be inspected by
// debuggers.
static const std::array<std::string_view, fields_size> storage_names;
// -1 if the field has no isset.
static const std::array<int, fields_size> isset_indexes;
};

}} // apache::thrift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,31 @@ struct ForEachField<::cpp2::complexException> {
f(5, static_cast<T&&>(t).lsMap_ref()...);
}
};

template <>
struct ForEachField<::cpp2::Containers> {
template <typename F, typename... T>
void operator()([[maybe_unused]] F&& f, [[maybe_unused]] T&&... t) const {
f(0, static_cast<T&&>(t).struct_list_ref()...);
f(1, static_cast<T&&>(t).union_list_ref()...);
f(2, static_cast<T&&>(t).enum_list_ref()...);
f(3, static_cast<T&&>(t).struct_set_ref()...);
f(4, static_cast<T&&>(t).union_set_ref()...);
f(5, static_cast<T&&>(t).enum_set_ref()...);
f(6, static_cast<T&&>(t).struct_map_ref()...);
f(7, static_cast<T&&>(t).union_map_ref()...);
f(8, static_cast<T&&>(t).enum_map_ref()...);
f(9, static_cast<T&&>(t).struct_map_2_ref()...);
f(10, static_cast<T&&>(t).union_map_2_ref()...);
f(11, static_cast<T&&>(t).enum_map_2_ref()...);
f(12, static_cast<T&&>(t).list_map_ref()...);
f(13, static_cast<T&&>(t).list_map_2_ref()...);
f(14, static_cast<T&&>(t).set_map_ref()...);
f(15, static_cast<T&&>(t).set_map_2_ref()...);
f(16, static_cast<T&&>(t).map_map_ref()...);
f(17, static_cast<T&&>(t).map_map_2_ref()...);
}
};
} // namespace detail
} // namespace thrift
} // namespace apache
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,29 @@ StructMetadata<::cpp2::complexException>::gen(ThriftMetadata& metadata) {
}
return res.first->second;
}
const ::apache::thrift::metadata::ThriftStruct&
StructMetadata<::cpp2::Containers>::gen(ThriftMetadata& metadata) {
auto res = metadata.structs()->emplace("module.Containers", ::apache::thrift::metadata::ThriftStruct{});
if (!res.second) {
return res.first->second;
}
::apache::thrift::metadata::ThriftStruct& module_Containers = res.first->second;
module_Containers.name() = "module.Containers";
module_Containers.is_union() = false;
static const auto* const
module_Containers_fields = new std::array<EncodedThriftField, 18>{ {
{ 1, "struct_list", false, std::make_unique<List>(std::make_unique<Struct<::cpp2::MyStruct>>("module.MyStruct")), std::vector<ThriftConstStruct>{ }}, { 2, "union_list", false, std::make_unique<List>(std::make_unique<Union<::cpp2::MyUnion>>("module.MyUnion")), std::vector<ThriftConstStruct>{ }}, { 3, "enum_list", false, std::make_unique<List>(std::make_unique<Enum<::cpp2::MyEnum>>("module.MyEnum")), std::vector<ThriftConstStruct>{ }}, { 4, "struct_set", false, std::make_unique<Set>(std::make_unique<Struct<::cpp2::MyStruct>>("module.MyStruct")), std::vector<ThriftConstStruct>{ }}, { 5, "union_set", false, std::make_unique<Set>(std::make_unique<Union<::cpp2::MyUnion>>("module.MyUnion")), std::vector<ThriftConstStruct>{ }}, { 6, "enum_set", false, std::make_unique<Set>(std::make_unique<Enum<::cpp2::MyEnum>>("module.MyEnum")), std::vector<ThriftConstStruct>{ }}, { 7, "struct_map", false, std::make_unique<Map>(std::make_unique<Struct<::cpp2::MyStruct>>("module.MyStruct"), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I64_TYPE)), std::vector<ThriftConstStruct>{ }}, { 8, "union_map", false, std::make_unique<Map>(std::make_unique<Union<::cpp2::MyUnion>>("module.MyUnion"), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I64_TYPE)), std::vector<ThriftConstStruct>{ }}, { 9, "enum_map", false, std::make_unique<Map>(std::make_unique<Enum<::cpp2::MyEnum>>("module.MyEnum"), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I64_TYPE)), std::vector<ThriftConstStruct>{ }}, { 10, "struct_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Struct<::cpp2::MyStruct>>("module.MyStruct")), std::vector<ThriftConstStruct>{ }}, { 11, "union_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Union<::cpp2::MyUnion>>("module.MyUnion")), std::vector<ThriftConstStruct>{ }}, { 12, "enum_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Enum<::cpp2::MyEnum>>("module.MyEnum")), std::vector<ThriftConstStruct>{ }}, { 13, "list_map", false, std::make_unique<Map>(std::make_unique<List>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::vector<ThriftConstStruct>{ }}, { 14, "list_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<List>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE))), std::vector<ThriftConstStruct>{ }}, { 15, "set_map", false, std::make_unique<Map>(std::make_unique<Set>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::vector<ThriftConstStruct>{ }}, { 16, "set_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Set>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE))), std::vector<ThriftConstStruct>{ }}, { 17, "map_map", false, std::make_unique<Map>(std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE)), std::vector<ThriftConstStruct>{ }}, { 18, "map_map_2", false, std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Map>(std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE), std::make_unique<Primitive>(ThriftPrimitiveType::THRIFT_I32_TYPE))), std::vector<ThriftConstStruct>{ }}, }};
for (const auto& f : *module_Containers_fields) {
::apache::thrift::metadata::ThriftField field;
field.id() = f.id;
field.name() = f.name;
field.is_optional() = f.is_optional;
f.metadata_type_interface->writeAndGenType(*field.type(), metadata);
field.structured_annotations() = f.structured_annotations;
module_Containers.fields()->push_back(std::move(field));
}
return res.first->second;
}

void ExceptionMetadata<::cpp2::emptyXcep>::gen(ThriftMetadata& metadata) {
auto res = metadata.exceptions()->emplace("module.emptyXcep", ::apache::thrift::metadata::ThriftException{});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class StructMetadata<::cpp2::complexException> {
static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata);
};
template <>
class StructMetadata<::cpp2::Containers> {
public:
static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata);
};
template <>
class ExceptionMetadata<::cpp2::emptyXcep> {
public:
static void gen(ThriftMetadata& metadata);
Expand Down
Loading

0 comments on commit 350c183

Please sign in to comment.