Skip to content

Commit

Permalink
Add API to get thrift class name
Browse files Browse the repository at this point in the history
Summary:
This is needed for using RecursiveEncode with DebugProtocol (otherwise we can't print struct name).

It will be used in the next diff.

Reviewed By: iahs

Differential Revision: D44326880

fbshipit-source-id: 0c46b33f94b0c3d15aa693a05fac6cc88996ba88
  • Loading branch information
TJ Yin authored and facebook-github-bot committed Mar 24, 2023
1 parent 35eb7fb commit bbae002
Show file tree
Hide file tree
Showing 263 changed files with 2,258 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace apache {
namespace thrift {
<%#program:structs%>
THRIFT_DATA_MEMBER const folly::StringPiece TStructDataStorage<<%struct:cpp_fullname%>>::name = "<%struct:name%>";
THRIFT_DATA_MEMBER const std::array<folly::StringPiece, <%struct:fields_size%>> TStructDataStorage<<%struct:cpp_fullname%>>::fields_names = {{
<%#struct:fields%>
"<%field:name%>",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ template <> struct TEnumDataStorage<<%struct:cpp_fullname%>::Type> {

template <> struct TStructDataStorage<<%struct:cpp_fullname%>> {
static constexpr const std::size_t fields_size = <%struct:fields_size%>;
static const folly::StringPiece name;
static const std::array<folly::StringPiece, fields_size> fields_names;
static const std::array<int16_t, fields_size> fields_ids;
static const std::array<protocol::TType, fields_size> fields_types;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const folly::StringPiece <%struct:cpp_underlying_name%>::__fbthrift_get_field_na
if (ord == ::apache::thrift::FieldOrdinal{0}) { return {}; }
return apache::thrift::TStructDataStorage<<%struct:cpp_underlying_name%>>::fields_names[folly::to_underlying(ord) - 1];
}
const folly::StringPiece <%struct:cpp_underlying_name%>::__fbthrift_get_class_name() {
return apache::thrift::TStructDataStorage<<%struct:cpp_underlying_name%>>::name;
}

<%^struct:union?%>
<%^struct:cpp_noncopyable%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class <%#struct:exception?%>FOLLY_EXPORT <%/struct:exception?%><%struct:cpp_unde
using __fbthrift_patch_struct = <%struct:cpp_underlying_name%>PatchStruct;
<%/struct:patch?%>
static const folly::StringPiece __fbthrift_get_field_name(::apache::thrift::FieldOrdinal ord);
static const folly::StringPiece __fbthrift_get_class_name();
<% > module_types_h/reflection%>
void __fbthrift_clear();
Expand Down
33 changes: 33 additions & 0 deletions thrift/compiler/test/fixtures/adapter/gen-cpp2/module_data.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bbae002

Please sign in to comment.