diff --git a/thrift/compiler/test/fixtures/use_op_encode/cmd b/thrift/compiler/test/fixtures/use_op_encode/cmd new file mode 100644 index 00000000000..b4d8a3b1f67 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/cmd @@ -0,0 +1 @@ +cpp2: mstch_cpp2 src/module.thrift diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_clients.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_clients.h new file mode 100644 index 00000000000..63856004a06 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_clients.h @@ -0,0 +1,8 @@ +/** + * Autogenerated by Thrift for + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.cpp b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.cpp new file mode 100644 index 00000000000..afd1da1827e --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.cpp @@ -0,0 +1,25 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_constants.h" + +#include + + +namespace facebook::thrift::compiler::test { +namespace module_constants { + + +::std::string_view _fbthrift_schema_709b2525c0eb9689() { + return ""; +} +::folly::Range _fbthrift_schema_709b2525c0eb9689_includes() { + return {}; +} + +} // namespace module_constants +} // namespace facebook::thrift::compiler::test diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.h new file mode 100644 index 00000000000..648fb02dd78 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_constants.h @@ -0,0 +1,21 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.h" + +namespace facebook::thrift::compiler::test { +/** Glean {"file": "thrift/compiler/test/fixtures/use_op_encode/src/module.thrift"} */ +namespace module_constants { + + FOLLY_EXPORT ::std::string_view _fbthrift_schema_709b2525c0eb9689(); + FOLLY_EXPORT ::folly::Range _fbthrift_schema_709b2525c0eb9689_includes(); + +} // namespace module_constants +} // namespace facebook::thrift::compiler::test diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.cpp b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.cpp new file mode 100644 index 00000000000..2ee571471c9 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.cpp @@ -0,0 +1,69 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_data.h" + +#include + +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 { + +THRIFT_DATA_MEMBER const std::string_view TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::name = "MyStruct"; +THRIFT_DATA_MEMBER const std::array TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::fields_names = { { + "def_field"sv, + "opt_field"sv, + "req_field"sv, + "terse_field"sv, +}}; +THRIFT_DATA_MEMBER const std::array TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::fields_ids = { { + 1, + 2, + 3, + 4, +}}; +THRIFT_DATA_MEMBER const std::array TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::fields_types = { { + TType::T_I32, + TType::T_I32, + TType::T_I32, + TType::T_I32, +}}; +THRIFT_DATA_MEMBER const std::array TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::storage_names = { { + "__fbthrift_field_def_field"sv, + "__fbthrift_field_opt_field"sv, + "__fbthrift_field_req_field"sv, + "__fbthrift_field_terse_field"sv, +}}; +THRIFT_DATA_MEMBER const std::array TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>::isset_indexes = { { + 0, + 1, + -1, + -1, +}}; + +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.h new file mode 100644 index 00000000000..b844ab0e97d --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_data.h @@ -0,0 +1,31 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.h" + +namespace apache { namespace thrift { + +template <> struct TStructDataStorage<::facebook::thrift::compiler::test::MyStruct> { + static constexpr const std::size_t fields_size = 4; + static const std::string_view name; + static const std::array fields_names; + static const std::array fields_ids; + static const std::array 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 storage_names; + // -1 if the field has no isset. + static const std::array isset_indexes; +}; + +}} // apache::thrift diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_for_each_field.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_for_each_field.h new file mode 100644 index 00000000000..590b3b6d587 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_for_each_field.h @@ -0,0 +1,28 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_metadata.h" +#include + +namespace apache { +namespace thrift { +namespace detail { + +template <> +struct ForEachField<::facebook::thrift::compiler::test::MyStruct> { + template + void operator()([[maybe_unused]] F&& f, [[maybe_unused]] T&&... t) const { + f(0, static_cast(t).def_field_ref()...); + f(1, static_cast(t).opt_field_ref()...); + f(2, static_cast(t).req_field_ref()...); + f(3, static_cast(t).terse_field_ref()...); + } +}; +} // namespace detail +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_handlers.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_handlers.h new file mode 100644 index 00000000000..63856004a06 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_handlers.h @@ -0,0 +1,8 @@ +/** + * Autogenerated by Thrift for + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.cpp b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.cpp new file mode 100644 index 00000000000..3466472d4fe --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.cpp @@ -0,0 +1,56 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#include +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_metadata.h" + +// some of these functions can be so large that the compiler gives up optimizing +// them - and issues a warning which may be treated as an error! +// +// these functions are so rarely called that it is probably okay for them not to +// be optimized in practice +FOLLY_CLANG_DISABLE_WARNING("-Wignored-optimization-argument") + +namespace apache { +namespace thrift { +namespace detail { +namespace md { +using ThriftMetadata = ::apache::thrift::metadata::ThriftMetadata; +using ThriftPrimitiveType = ::apache::thrift::metadata::ThriftPrimitiveType; +using ThriftType = ::apache::thrift::metadata::ThriftType; +using ThriftService = ::apache::thrift::metadata::ThriftService; +using ThriftServiceContext = ::apache::thrift::metadata::ThriftServiceContext; +using ThriftFunctionGenerator = void (*)(ThriftMetadata&, ThriftService&); + + +const ::apache::thrift::metadata::ThriftStruct& +StructMetadata<::facebook::thrift::compiler::test::MyStruct>::gen(ThriftMetadata& metadata) { + auto res = metadata.structs()->emplace("module.MyStruct", ::apache::thrift::metadata::ThriftStruct{}); + if (!res.second) { + return res.first->second; + } + ::apache::thrift::metadata::ThriftStruct& module_MyStruct = res.first->second; + module_MyStruct.name() = "module.MyStruct"; + module_MyStruct.is_union() = false; + static const auto* const + module_MyStruct_fields = new std::array{ { + { 1, "def_field", false, std::make_unique(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector{ }}, { 2, "opt_field", true, std::make_unique(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector{ }}, { 3, "req_field", false, std::make_unique(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector{ }}, { 4, "terse_field", false, std::make_unique(ThriftPrimitiveType::THRIFT_I32_TYPE), std::vector{ *cvStruct("thrift.TerseWrite", { }).cv_struct_ref(), }}, }}; + for (const auto& f : *module_MyStruct_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_MyStruct.fields()->push_back(std::move(field)); + } + return res.first->second; +} + +} // namespace md +} // namespace detail +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.h new file mode 100644 index 00000000000..f0e49442694 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_metadata.h @@ -0,0 +1,28 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include + +#include +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.h" + + +namespace apache { +namespace thrift { +namespace detail { +namespace md { + +template <> +class StructMetadata<::facebook::thrift::compiler::test::MyStruct> { + public: + static const ::apache::thrift::metadata::ThriftStruct& gen(ThriftMetadata& metadata); +}; +} // namespace md +} // namespace detail +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.cpp b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.cpp new file mode 100644 index 00000000000..b27cb025ea2 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.cpp @@ -0,0 +1,145 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.h" +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.tcc" + +#include + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_data.h" +[[maybe_unused]] static constexpr std::string_view kModuleName = "module"; + + +namespace apache { +namespace thrift { +namespace detail { + +void TccStructTraits<::facebook::thrift::compiler::test::MyStruct>::translateFieldName( + std::string_view _fname, + int16_t& fid, + apache::thrift::protocol::TType& _ftype) noexcept { + using data = apache::thrift::TStructDataStorage<::facebook::thrift::compiler::test::MyStruct>; + static const st::translate_field_name_table table{ + data::fields_size, + data::fields_names.data(), + data::fields_ids.data(), + data::fields_types.data()}; + st::translate_field_name(_fname, fid, _ftype, table); +} + +} // namespace detail +} // namespace thrift +} // namespace apache + +namespace facebook::thrift::compiler::test { + +const char* MyStruct::__fbthrift_thrift_uri() { + return "facebook.com/thrift/compiler/test/MyStruct"; +} + +std::string_view MyStruct::__fbthrift_get_field_name(::apache::thrift::FieldOrdinal ord) { + if (ord == ::apache::thrift::FieldOrdinal{0}) { return {}; } + return apache::thrift::TStructDataStorage::fields_names[folly::to_underlying(ord) - 1]; +} +std::string_view MyStruct::__fbthrift_get_class_name() { + return apache::thrift::TStructDataStorage::name; +} + + +MyStruct::MyStruct(apache::thrift::FragileConstructor, ::std::int32_t def_field__arg, ::std::int32_t opt_field__arg, ::std::int32_t req_field__arg, ::std::int32_t terse_field__arg) : + __fbthrift_field_def_field(std::move(def_field__arg)), + __fbthrift_field_opt_field(std::move(opt_field__arg)), + __fbthrift_field_req_field(std::move(req_field__arg)), + __fbthrift_field_terse_field(std::move(terse_field__arg)) { + __isset.set(folly::index_constant<0>(), true); + __isset.set(folly::index_constant<1>(), true); +} + + +void MyStruct::__fbthrift_clear() { + // clear all fields + this->__fbthrift_field_def_field = ::std::int32_t(); + this->__fbthrift_field_opt_field = ::std::int32_t(); + this->__fbthrift_field_req_field = ::std::int32_t(); + this->__fbthrift_field_terse_field = ::std::int32_t(); + __isset = {}; +} + +void MyStruct::__fbthrift_clear_terse_fields() { + this->__fbthrift_field_terse_field = ::std::int32_t(); +} + +bool MyStruct::__fbthrift_is_empty() const { + return false; +} + +bool MyStruct::operator==([[maybe_unused]] const MyStruct& rhs) const { + return ::apache::thrift::op::detail::StructEquality{}(*this, rhs); +} + +bool MyStruct::operator<([[maybe_unused]] const MyStruct& rhs) const { + return ::apache::thrift::op::detail::StructLessThan{}(*this, rhs); +} + + +::std::int32_t MyStruct::get_def_field() const { + return __fbthrift_field_def_field; +} + +::std::int32_t& MyStruct::set_def_field(::std::int32_t def_field_) { + def_field_ref() = def_field_; + return __fbthrift_field_def_field; +} + +const ::std::int32_t* MyStruct::get_opt_field() const& { + return opt_field_ref().has_value() ? std::addressof(__fbthrift_field_opt_field) : nullptr; +} + +::std::int32_t* MyStruct::get_opt_field() & { + return opt_field_ref().has_value() ? std::addressof(__fbthrift_field_opt_field) : nullptr; +} + +::std::int32_t& MyStruct::set_opt_field(::std::int32_t opt_field_) { + opt_field_ref() = opt_field_; + return __fbthrift_field_opt_field; +} + +::std::int32_t MyStruct::get_req_field() const { + return __fbthrift_field_req_field; +} + +::std::int32_t& MyStruct::set_req_field(::std::int32_t req_field_) { + req_field_ref() = req_field_; + return __fbthrift_field_req_field; +} + +void swap([[maybe_unused]] MyStruct& a, [[maybe_unused]] MyStruct& b) { + using ::std::swap; + swap(a.__fbthrift_field_def_field, b.__fbthrift_field_def_field); + swap(a.__fbthrift_field_opt_field, b.__fbthrift_field_opt_field); + swap(a.__fbthrift_field_req_field, b.__fbthrift_field_req_field); + swap(a.__fbthrift_field_terse_field, b.__fbthrift_field_terse_field); + swap(a.__isset, b.__isset); +} + +template void MyStruct::readNoXfer<>(apache::thrift::BinaryProtocolReader*); +template uint32_t MyStruct::write<>(apache::thrift::BinaryProtocolWriter*) const; +template uint32_t MyStruct::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +template uint32_t MyStruct::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +template void MyStruct::readNoXfer<>(apache::thrift::CompactProtocolReader*); +template uint32_t MyStruct::write<>(apache::thrift::CompactProtocolWriter*) const; +template uint32_t MyStruct::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +template uint32_t MyStruct::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; + + +} // namespace facebook::thrift::compiler::test + +namespace facebook::thrift::compiler::test { namespace { +[[maybe_unused]] FOLLY_ERASE void validateAdapters() { +} +}} // namespace facebook::thrift::compiler::test +namespace apache::thrift::detail::annotation { +} diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.h new file mode 100644 index 00000000000..d2c6ec99e4f --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.h @@ -0,0 +1,409 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include + + + +namespace apache { +namespace thrift { +namespace ident { +struct def_field; +struct opt_field; +struct req_field; +struct terse_field; +} // namespace ident +namespace detail { +#ifndef APACHE_THRIFT_ACCESSOR_def_field +#define APACHE_THRIFT_ACCESSOR_def_field +APACHE_THRIFT_DEFINE_ACCESSOR(def_field); +#endif +#ifndef APACHE_THRIFT_ACCESSOR_opt_field +#define APACHE_THRIFT_ACCESSOR_opt_field +APACHE_THRIFT_DEFINE_ACCESSOR(opt_field); +#endif +#ifndef APACHE_THRIFT_ACCESSOR_req_field +#define APACHE_THRIFT_ACCESSOR_req_field +APACHE_THRIFT_DEFINE_ACCESSOR(req_field); +#endif +#ifndef APACHE_THRIFT_ACCESSOR_terse_field +#define APACHE_THRIFT_ACCESSOR_terse_field +APACHE_THRIFT_DEFINE_ACCESSOR(terse_field); +#endif +} // namespace detail +} // namespace thrift +} // namespace apache + +// BEGIN declare_enums + +// END declare_enums +// BEGIN forward_declare +namespace facebook::thrift::compiler::test { +class MyStruct; +} // namespace facebook::thrift::compiler::test +// END forward_declare +namespace apache::thrift::detail::annotation { +} // namespace apache::thrift::detail::annotation + +namespace apache::thrift::detail::qualifier { +} // namespace apache::thrift::detail::qualifier + +// BEGIN hash_and_equal_to +// END hash_and_equal_to +namespace facebook::thrift::compiler::test { +using ::apache::thrift::detail::operator!=; +using ::apache::thrift::detail::operator>; +using ::apache::thrift::detail::operator<=; +using ::apache::thrift::detail::operator>=; + + +/** Glean {"file": "thrift/compiler/test/fixtures/use_op_encode/src/module.thrift", "name": "MyStruct", "kind": "struct" } */ +class MyStruct final { + private: + friend struct ::apache::thrift::detail::st::struct_private_access; + template friend struct ::apache::thrift::detail::invoke_reffer; + + // used by a static_assert in the corresponding source + static constexpr bool __fbthrift_cpp2_gen_json = false; + static constexpr bool __fbthrift_cpp2_is_runtime_annotation = false; + static const char* __fbthrift_thrift_uri(); + static std::string_view __fbthrift_get_field_name(::apache::thrift::FieldOrdinal ord); + static std::string_view __fbthrift_get_class_name(); + template + FOLLY_ERASE static constexpr std::string_view __fbthrift_get_module_name() noexcept { + return "module"; + } + using __fbthrift_reflection_ident_list = folly::tag_t< + ::apache::thrift::ident::def_field, + ::apache::thrift::ident::opt_field, + ::apache::thrift::ident::req_field, + ::apache::thrift::ident::terse_field + >; + + static constexpr std::int16_t __fbthrift_reflection_field_id_list[] = {0,1,2,3,4}; + using __fbthrift_reflection_type_tags = folly::tag_t< + ::apache::thrift::type::i32_t, + ::apache::thrift::type::i32_t, + ::apache::thrift::type::i32_t, + ::apache::thrift::type::i32_t + >; + + static constexpr std::size_t __fbthrift_field_size_v = 4; + + template + using __fbthrift_id = ::apache::thrift::type::field_id<__fbthrift_reflection_field_id_list[folly::to_underlying(T::value)]>; + + template + using __fbthrift_type_tag = ::apache::thrift::detail::at<__fbthrift_reflection_type_tags, T::value>; + + template + using __fbthrift_ident = ::apache::thrift::detail::at<__fbthrift_reflection_ident_list, T::value>; + + template using __fbthrift_ordinal = ::apache::thrift::type::ordinal_tag< + ::apache::thrift::detail::getFieldOrdinal( + __fbthrift_reflection_field_id_list + ) + >; + void __fbthrift_clear(); + void __fbthrift_clear_terse_fields(); + bool __fbthrift_is_empty() const; + + public: + using __fbthrift_cpp2_type = MyStruct; + static constexpr bool __fbthrift_cpp2_is_union = + false; + static constexpr bool __fbthrift_cpp2_uses_op_encode = + true; + + + public: + + MyStruct() : + __fbthrift_field_def_field(), + __fbthrift_field_opt_field(), + __fbthrift_field_req_field(), + __fbthrift_field_terse_field() { + } + // FragileConstructor for use in initialization lists only. + [[deprecated("This constructor is deprecated")]] + MyStruct(apache::thrift::FragileConstructor, ::std::int32_t def_field__arg, ::std::int32_t opt_field__arg, ::std::int32_t req_field__arg, ::std::int32_t terse_field__arg); + + MyStruct(MyStruct&&) = default; + + MyStruct(const MyStruct&) = default; + + + MyStruct& operator=(MyStruct&&) = default; + + MyStruct& operator=(const MyStruct&) = default; + private: + ::std::int32_t __fbthrift_field_def_field; + private: + ::std::int32_t __fbthrift_field_opt_field; + private: + ::std::int32_t __fbthrift_field_req_field; + private: + ::std::int32_t __fbthrift_field_terse_field; + private: + apache::thrift::detail::isset_bitset<2, apache::thrift::detail::IssetBitsetOption::Unpacked> __isset; + + public: + + bool operator==(const MyStruct&) const; + bool operator<(const MyStruct&) const; + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field_ref() const& { + return {this->__fbthrift_field_def_field, __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field_ref() const&& { + return {static_cast(this->__fbthrift_field_def_field), __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field_ref() & { + return {this->__fbthrift_field_def_field, __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field_ref() && { + return {static_cast(this->__fbthrift_field_def_field), __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field() const& { + return {this->__fbthrift_field_def_field, __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field() const&& { + return {static_cast(this->__fbthrift_field_def_field), __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field() & { + return {this->__fbthrift_field_def_field, __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "def_field" } */ + template + FOLLY_ERASE ::apache::thrift::field_ref def_field() && { + return {static_cast(this->__fbthrift_field_def_field), __isset.at(0), __isset.bit(0)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field_ref() const& { + return {this->__fbthrift_field_opt_field, __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field_ref() const&& { + return {static_cast(this->__fbthrift_field_opt_field), __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field_ref() & { + return {this->__fbthrift_field_opt_field, __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field_ref() && { + return {static_cast(this->__fbthrift_field_opt_field), __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field() const& { + return {this->__fbthrift_field_opt_field, __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field() const&& { + return {static_cast(this->__fbthrift_field_opt_field), __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field() & { + return {this->__fbthrift_field_opt_field, __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "opt_field" } */ + template + FOLLY_ERASE ::apache::thrift::optional_field_ref opt_field() && { + return {static_cast(this->__fbthrift_field_opt_field), __isset.at(1), __isset.bit(1)}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field_ref() const& { + return ::apache::thrift::required_field_ref{this->__fbthrift_field_req_field}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field_ref() const&& { + return ::apache::thrift::required_field_ref{static_cast(this->__fbthrift_field_req_field)}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field_ref() & { + return ::apache::thrift::required_field_ref{this->__fbthrift_field_req_field}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field_ref() && { + return ::apache::thrift::required_field_ref{static_cast(this->__fbthrift_field_req_field)}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field() const& { + return ::apache::thrift::required_field_ref{this->__fbthrift_field_req_field}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field() const&& { + return ::apache::thrift::required_field_ref{static_cast(this->__fbthrift_field_req_field)}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field() & { + return ::apache::thrift::required_field_ref{this->__fbthrift_field_req_field}; + } + + /** Glean { "field": "req_field" } */ + template + FOLLY_ERASE ::apache::thrift::required_field_ref req_field() && { + return ::apache::thrift::required_field_ref{static_cast(this->__fbthrift_field_req_field)}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field_ref() const& { + return ::apache::thrift::terse_field_ref{this->__fbthrift_field_terse_field}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field_ref() const&& { + return ::apache::thrift::terse_field_ref{static_cast(this->__fbthrift_field_terse_field)}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field_ref() & { + return ::apache::thrift::terse_field_ref{this->__fbthrift_field_terse_field}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field_ref() && { + return ::apache::thrift::terse_field_ref{static_cast(this->__fbthrift_field_terse_field)}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field() const& { + return ::apache::thrift::terse_field_ref{this->__fbthrift_field_terse_field}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field() const&& { + return ::apache::thrift::terse_field_ref{static_cast(this->__fbthrift_field_terse_field)}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field() & { + return ::apache::thrift::terse_field_ref{this->__fbthrift_field_terse_field}; + } + + /** Glean { "field": "terse_field" } */ + template + FOLLY_ERASE ::apache::thrift::terse_field_ref terse_field() && { + return ::apache::thrift::terse_field_ref{static_cast(this->__fbthrift_field_terse_field)}; + } + + /** Glean { "field": "def_field" } */ + [[deprecated("Use `FOO.def_field().value();` instead of `FOO.get_def_field();`")]] + ::std::int32_t get_def_field() const; + + /** Glean { "field": "def_field" } */ + [[deprecated("Use `FOO.def_field() = BAR;` instead of `FOO.set_def_field(BAR);`")]] + ::std::int32_t& set_def_field(::std::int32_t def_field_); + + /** Glean { "field": "opt_field" } */ + [[deprecated("Use `FOO.opt_field().value();` instead of `FOO.get_opt_field();`")]] + const ::std::int32_t* get_opt_field() const&; + + /** Glean { "field": "opt_field" } */ + [[deprecated("Use `FOO.opt_field().value();` instead of `FOO.get_opt_field();`")]] + ::std::int32_t* get_opt_field() &; + + ::std::int32_t* get_opt_field() && = delete; + + /** Glean { "field": "opt_field" } */ + [[deprecated("Use `FOO.opt_field() = BAR;` instead of `FOO.set_opt_field(BAR);`")]] + ::std::int32_t& set_opt_field(::std::int32_t opt_field_); + + /** Glean { "field": "req_field" } */ + [[deprecated("Use `FOO.req_field().value();` instead of `FOO.get_req_field();`")]] + ::std::int32_t get_req_field() const; + + /** Glean { "field": "req_field" } */ + [[deprecated("Use `FOO.req_field() = BAR;` instead of `FOO.set_req_field(BAR);`")]] + ::std::int32_t& set_req_field(::std::int32_t req_field_); + + template + unsigned long read(Protocol_* iprot); + template + uint32_t serializedSize(Protocol_ const* prot_) const; + template + uint32_t serializedSizeZC(Protocol_ const* prot_) const; + template + uint32_t write(Protocol_* prot_) const; + + private: + template + void readNoXfer(Protocol_* iprot); + + friend class ::apache::thrift::Cpp2Ops; + friend void swap(MyStruct& a, MyStruct& b); +}; + +template +unsigned long MyStruct::read(Protocol_* iprot) { + auto _xferStart = iprot->getCursorPosition(); + readNoXfer(iprot); + return iprot->getCursorPosition() - _xferStart; +} + + +} // namespace facebook::thrift::compiler::test diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.tcc b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.tcc new file mode 100644 index 00000000000..3b8f3126f3f --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types.tcc @@ -0,0 +1,261 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.h" + +#include + + +namespace apache { +namespace thrift { +namespace detail { + +template <> +struct TccStructTraits<::facebook::thrift::compiler::test::MyStruct> { + static void translateFieldName( + std::string_view _fname, + int16_t& fid, + apache::thrift::protocol::TType& _ftype) noexcept; +}; + +} // namespace detail +} // namespace thrift +} // namespace apache + +namespace facebook::thrift::compiler::test { + +template +void MyStruct::readNoXfer(Protocol_* iprot) { + __fbthrift_clear_terse_fields(); + + apache::thrift::detail::ProtocolReaderStructReadState _readState; + + _readState.readStructBegin(iprot); + + using apache::thrift::TProtocolException; + + + if (UNLIKELY(!_readState.advanceToNextField( + iprot, + 0, + 1, + apache::thrift::protocol::T_I32))) { + goto _advance_failure; + } +_readField_def_field: + { + ::apache::thrift::op::decode<::apache::thrift::type::i32_t>(*iprot, this->__fbthrift_field_def_field); + } + this->__isset.set(0, true); + + if (UNLIKELY(!_readState.advanceToNextField( + iprot, + 1, + 2, + apache::thrift::protocol::T_I32))) { + goto _advance_failure; + } +_readField_opt_field: + { + ::apache::thrift::op::decode<::apache::thrift::type::i32_t>(*iprot, this->__fbthrift_field_opt_field); + } + this->__isset.set(1, true); + + if (UNLIKELY(!_readState.advanceToNextField( + iprot, + 2, + 3, + apache::thrift::protocol::T_I32))) { + goto _advance_failure; + } +_readField_req_field: + { + ::apache::thrift::op::decode<::apache::thrift::type::i32_t>(*iprot, this->__fbthrift_field_req_field); + } + + if (UNLIKELY(!_readState.advanceToNextField( + iprot, + 3, + 4, + apache::thrift::protocol::T_I32))) { + goto _advance_failure; + } +_readField_terse_field: + { + ::apache::thrift::op::decode<::apache::thrift::type::i32_t>(*iprot, this->__fbthrift_field_terse_field); + } + + if (UNLIKELY(!_readState.advanceToNextField( + iprot, + 4, + 0, + apache::thrift::protocol::T_STOP))) { + goto _advance_failure; + } + +_end: + _readState.readStructEnd(iprot); + + return; + + goto _advance_failure; // Avoid compiler warnings about unused labels. + _advance_failure: + _readState.afterAdvanceFailure(iprot); +_loop: + if (_readState.atStop()) { + goto _end; + } + if (iprot->kUsesFieldNames()) { + _readState.template fillFieldTraitsFromName>(); + } + + switch (_readState.fieldId) { + case 1: + { + if (LIKELY(_readState.isCompatibleWithType(iprot, apache::thrift::protocol::T_I32))) { + goto _readField_def_field; + } else { + goto _skip; + } + } + case 2: + { + if (LIKELY(_readState.isCompatibleWithType(iprot, apache::thrift::protocol::T_I32))) { + goto _readField_opt_field; + } else { + goto _skip; + } + } + case 3: + { + if (LIKELY(_readState.isCompatibleWithType(iprot, apache::thrift::protocol::T_I32))) { + goto _readField_req_field; + } else { + goto _skip; + } + } + case 4: + { + if (LIKELY(_readState.isCompatibleWithType(iprot, apache::thrift::protocol::T_I32))) { + goto _readField_terse_field; + } else { + goto _skip; + } + } + default: + { +_skip: + _readState.skip(iprot); + _readState.readFieldEnd(iprot); + _readState.readFieldBeginNoInline(iprot); + goto _loop; + } + } +} + +template +uint32_t MyStruct::serializedSize(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("MyStruct"); + { + xfer += prot_->serializedFieldSize("def_field", apache::thrift::protocol::T_I32, 1); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_def_field); + } + if (this->__isset.get(1)) { + xfer += prot_->serializedFieldSize("opt_field", apache::thrift::protocol::T_I32, 2); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_opt_field); + } + { + xfer += prot_->serializedFieldSize("req_field", apache::thrift::protocol::T_I32, 3); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_req_field); + } + if (!(::apache::thrift::op::isEmpty<::apache::thrift::type::i32_t>(this->__fbthrift_field_terse_field))) { + xfer += prot_->serializedFieldSize("terse_field", apache::thrift::protocol::T_I32, 4); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_terse_field); + } + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t MyStruct::serializedSizeZC(Protocol_ const* prot_) const { + uint32_t xfer = 0; + xfer += prot_->serializedStructSize("MyStruct"); + { + xfer += prot_->serializedFieldSize("def_field", apache::thrift::protocol::T_I32, 1); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_def_field); + } + if (this->__isset.get(1)) { + xfer += prot_->serializedFieldSize("opt_field", apache::thrift::protocol::T_I32, 2); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_opt_field); + } + { + xfer += prot_->serializedFieldSize("req_field", apache::thrift::protocol::T_I32, 3); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_req_field); + } + if (!(::apache::thrift::op::isEmpty<::apache::thrift::type::i32_t>(this->__fbthrift_field_terse_field))) { + xfer += prot_->serializedFieldSize("terse_field", apache::thrift::protocol::T_I32, 4); + xfer += ::apache::thrift::op::serialized_size(*prot_, this->__fbthrift_field_terse_field); + } + xfer += prot_->serializedSizeStop(); + return xfer; +} + +template +uint32_t MyStruct::write(Protocol_* prot_) const { + uint32_t xfer = 0; + xfer += prot_->writeStructBegin("MyStruct"); + bool previousFieldHasValue = true; + { + constexpr int16_t kPrevFieldId = 0; + xfer += ::apache::thrift::detail::writeFieldBegin(*prot_, "def_field", previousFieldHasValue); + previousFieldHasValue = true; + xfer += ::apache::thrift::op::encode<::apache::thrift::type::i32_t>(*prot_, this->__fbthrift_field_def_field); + xfer += prot_->writeFieldEnd(); + } + if (this->__isset.get(1)) { + constexpr int16_t kPrevFieldId = 1; + xfer += ::apache::thrift::detail::writeFieldBegin(*prot_, "opt_field", previousFieldHasValue); + previousFieldHasValue = true; + xfer += ::apache::thrift::op::encode<::apache::thrift::type::i32_t>(*prot_, this->__fbthrift_field_opt_field); + xfer += prot_->writeFieldEnd(); + } else { + previousFieldHasValue = false; + } + { + constexpr int16_t kPrevFieldId = 2; + xfer += ::apache::thrift::detail::writeFieldBegin(*prot_, "req_field", previousFieldHasValue); + previousFieldHasValue = true; + xfer += ::apache::thrift::op::encode<::apache::thrift::type::i32_t>(*prot_, this->__fbthrift_field_req_field); + xfer += prot_->writeFieldEnd(); + } + if (!(::apache::thrift::op::isEmpty<::apache::thrift::type::i32_t>(this->__fbthrift_field_terse_field))) { + constexpr int16_t kPrevFieldId = 3; + xfer += ::apache::thrift::detail::writeFieldBegin(*prot_, "terse_field", previousFieldHasValue); + previousFieldHasValue = true; + xfer += ::apache::thrift::op::encode<::apache::thrift::type::i32_t>(*prot_, this->__fbthrift_field_terse_field); + xfer += prot_->writeFieldEnd(); + } else { + previousFieldHasValue = false; + } + xfer += prot_->writeFieldStop(); + xfer += prot_->writeStructEnd(); + return xfer; +} + +extern template void MyStruct::readNoXfer<>(apache::thrift::BinaryProtocolReader*); +extern template uint32_t MyStruct::write<>(apache::thrift::BinaryProtocolWriter*) const; +extern template uint32_t MyStruct::serializedSize<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template uint32_t MyStruct::serializedSizeZC<>(apache::thrift::BinaryProtocolWriter const*) const; +extern template void MyStruct::readNoXfer<>(apache::thrift::CompactProtocolReader*); +extern template uint32_t MyStruct::write<>(apache::thrift::CompactProtocolWriter*) const; +extern template uint32_t MyStruct::serializedSize<>(apache::thrift::CompactProtocolWriter const*) const; +extern template uint32_t MyStruct::serializedSizeZC<>(apache::thrift::CompactProtocolWriter const*) const; + + +} // namespace facebook::thrift::compiler::test diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_custom_protocol.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_custom_protocol.h new file mode 100644 index 00000000000..02f1d83a88a --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_custom_protocol.h @@ -0,0 +1,18 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + + +/** + * This header file includes the tcc files of the corresponding header file + * and the header files of its dependent types. Include this header file + * only when you need to use custom protocols (e.g. DebugProtocol, + * VirtualProtocol) to read/write thrift structs. + */ + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_types.tcc" + diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_fwd.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_fwd.h new file mode 100644 index 00000000000..00908c69f00 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_types_fwd.h @@ -0,0 +1,13 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +// BEGIN forward_declare +namespace facebook::thrift::compiler::test { +class MyStruct; +} // namespace facebook::thrift::compiler::test +// END forward_declare diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_by_thrift_field_metadata.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_by_thrift_field_metadata.h new file mode 100644 index 00000000000..7d73637d0d4 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_by_thrift_field_metadata.h @@ -0,0 +1,36 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_metadata.h" + +namespace apache { +namespace thrift { +namespace detail { + +template <> +struct VisitByFieldId<::facebook::thrift::compiler::test::MyStruct> { + template + void operator()([[maybe_unused]] F&& f, int32_t fieldId, [[maybe_unused]] T&& t) const { + switch (fieldId) { + case 1: + return f(0, static_cast(t).def_field_ref()); + case 2: + return f(1, static_cast(t).opt_field_ref()); + case 3: + return f(2, static_cast(t).req_field_ref()); + case 4: + return f(3, static_cast(t).terse_field_ref()); + default: + throwInvalidThriftId(fieldId, "::facebook::thrift::compiler::test::MyStruct"); + } + } +}; +} // namespace detail +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_union.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_union.h new file mode 100644 index 00000000000..1111deeb9eb --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visit_union.h @@ -0,0 +1,18 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once + +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_metadata.h" +#include + +namespace apache { +namespace thrift { +namespace detail { + +} // namespace detail +} // namespace thrift +} // namespace apache diff --git a/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visitation.h b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visitation.h new file mode 100644 index 00000000000..18fd0971938 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/out/cpp2/gen-cpp2/module_visitation.h @@ -0,0 +1,10 @@ +/** + * Autogenerated by Thrift for thrift/compiler/test/fixtures/use_op_encode/src/module.thrift + * + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * @generated @nocommit + */ +#pragma once +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_for_each_field.h" +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_visit_union.h" +#include "thrift/compiler/test/fixtures/use_op_encode/gen-cpp2/module_visit_by_thrift_field_metadata.h" diff --git a/thrift/compiler/test/fixtures/use_op_encode/src/module.thrift b/thrift/compiler/test/fixtures/use_op_encode/src/module.thrift new file mode 100644 index 00000000000..c1c57009336 --- /dev/null +++ b/thrift/compiler/test/fixtures/use_op_encode/src/module.thrift @@ -0,0 +1,29 @@ +/* + * 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. + */ + +include "thrift/annotation/cpp.thrift" +include "thrift/annotation/thrift.thrift" + +@cpp.UseOpEncode +package "facebook.com/thrift/compiler/test" + +struct MyStruct { + 1: i32 def_field; + 2: optional i32 opt_field; + 3: required i32 req_field; + @thrift.TerseWrite + 4: i32 terse_field; +}