{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}
{{ > Autogen}}

#include "{{program:include_prefix}}{{program:name}}_data.h"

#include <thrift/lib/cpp2/gen/module_data_cpp.h>

FOLLY_CLANG_DISABLE_WARNING("-Wunused-macros")

#if defined(__GNUC__) && defined(__linux__) && !FOLLY_MOBILE
// These attributes are applied to the static data members to ensure that they
// are not stripped from the compiled binary, in order to keep them available
// for use by debuggers at runtime.
//
// The "used" attribute is required to ensure the compiler always emits unused
// data.
//
// The "section" attribute is required to stop the linker from stripping used
// data. It works by forcing all of the data members (both used and unused ones)
// into the same section. As the linker strips data on a per-section basis, it
// is then unable to remove unused data without also removing used data.
// This has a similar effect to the "retain" attribute, but works with older
// toolchains.
#define THRIFT_DATA_MEMBER [[gnu::used]] [[gnu::section(".rodata.thrift.data")]]
#else
#define THRIFT_DATA_MEMBER
#endif

namespace apache {
namespace thrift {
{{#program:structs}}

THRIFT_DATA_MEMBER const std::string_view TStructDataStorage<{{struct:cpp_fullname}}>::name = "{{struct:name}}";
THRIFT_DATA_MEMBER const std::array<std::string_view, {{struct:fields_size}}> TStructDataStorage<{{struct:cpp_fullname}}>::fields_names = { {
  {{#struct:fields}}
  "{{field:name}}"sv,
  {{/struct:fields}}
}};
THRIFT_DATA_MEMBER const std::array<int16_t, {{struct:fields_size}}> TStructDataStorage<{{struct:cpp_fullname}}>::fields_ids = { {
  {{#struct:fields}}
  {{field:key}},
  {{/struct:fields}}
}};
THRIFT_DATA_MEMBER const std::array<protocol::TType, {{struct:fields_size}}> TStructDataStorage<{{struct:cpp_fullname}}>::fields_types = { {
  {{#struct:fields}}{{#field:type}}
  TType::{{ > module_types_tcc/struct_type}},
  {{/field:type}}{{/struct:fields}}
}};
THRIFT_DATA_MEMBER const std::array<std::string_view, {{struct:fields_size}}> TStructDataStorage<{{struct:cpp_fullname}}>::storage_names = { {
  {{#struct:fields}}
  "{{field:cpp_storage_name}}"sv,
  {{/struct:fields}}
}};
THRIFT_DATA_MEMBER const std::array<int, {{struct:fields_size}}> TStructDataStorage<{{struct:cpp_fullname}}>::isset_indexes = { {
  {{#struct:fields}}
  {{#field:has_isset?}}{{field:isset_index}}{{/field:has_isset?}}{{^field:has_isset?}}-1{{/field:has_isset?}},
  {{/struct:fields}}
}};
{{/program:structs}}

} // namespace thrift
} // namespace apache
