Skip to content

Commit

Permalink
Add use_reflect_codec option
Browse files Browse the repository at this point in the history
Summary:
An option to tell Thrift-Go generator to use the new reflect codec (implemented downstream).

As is - the diff is no-op.

Reviewed By: leoleovich

Differential Revision: D63473895

fbshipit-source-id: 66d5d630b88b7cd68b4d075ed191fe136e2171cb
  • Loading branch information
echistyakov authored and facebook-github-bot committed Sep 27, 2024
1 parent 2e953f2 commit 36cfcd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions thrift/compiler/generate/t_mstch_go_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class mstch_go_program : public mstch_program {
{"program:gen_metadata?", &mstch_go_program::should_gen_metadata},
{"program:gen_default_get?",
&mstch_go_program::should_gen_default_get},
{"program:use_reflect_codec?",
&mstch_go_program::should_use_reflect_codec},
{"program:import_metadata_package?",
&mstch_go_program::should_import_metadata_package},
{"program:metadata_qualifier",
Expand Down Expand Up @@ -127,6 +129,7 @@ class mstch_go_program : public mstch_program {
}
mstch::node should_gen_metadata() { return data_.gen_metadata; }
mstch::node should_gen_default_get() { return data_.gen_default_get; }
mstch::node should_use_reflect_codec() { return data_.use_reflect_codec; }
mstch::node should_import_metadata_package() {
// We don't need to import the metadata package if we are
// generating metadata inside the metadata package itself. Duh.
Expand Down Expand Up @@ -804,6 +807,9 @@ void t_mstch_go_generator::generate_program() {
if (auto gen_default_get = get_option("gen_default_get")) {
data_.gen_default_get = (gen_default_get.value() == "true");
}
if (auto use_reflect_codec = get_option("use_reflect_codec")) {
data_.use_reflect_codec = (use_reflect_codec.value() == "true");
}

const auto& prog = cached_program(program);
auto package_dir = std::filesystem::path{
Expand Down
2 changes: 2 additions & 0 deletions thrift/compiler/lib/go/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class codegen_data {
bool gen_metadata = true;
// whether to generate DefaultGet method
bool gen_default_get = true;
// whether to use reflect codec
bool use_reflect_codec = false;

// Records field names for every struct in the program.
// This is needed to resolve some edge case name collisions.
Expand Down

0 comments on commit 36cfcd5

Please sign in to comment.