feat(c++): support customize c++ field meta#3088
Merged
chaokunyang merged 10 commits intoapache:mainfrom Dec 25, 2025
Merged
Conversation
pandalee99
approved these changes
Dec 24, 2025
Add additional macro expansion layers to ensure proper expansion of FORY_PP_NARG before concatenation on GCC. The difference in macro expansion ordering between GCC and Clang required adding DISPATCH helper macros for FORY_FT_MAKE_ENTRY and extra EXPAND/IMPL layers for FORY_FT_ENTRIES.
Use the standard indirect expansion pattern (I -> II -> ##) to ensure macro arguments are fully expanded before token concatenation. This pattern works correctly on both GCC and Clang by forcing macro rescanning at each indirection level. Key changes: - FORY_FT_MAKE_ENTRY: Use _I -> _II -> ##size chain - FORY_FT_ENTRIES: Use _I -> _II -> ##N chain - Remove unused FORY_FT_EXPAND, FORY_FT_DEFER, FORY_FT_EMPTY macros
GCC rejects 'template <> struct ::namespace::Class<T>' as 'global qualification of class name is invalid'. Remove the leading :: from the template specialization definition.
26 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Currently, Fory's C++ xlang serialization treats all struct fields uniformly:
These defaults ensure correctness but introduce unnecessary overhead when the developer has specific knowledge about their data model.
What does this PR do?
Implements
fory::field<>template for compile-time field metadata, enabling performance and space optimization:Core API
Type Rules
std::stringstd::optional<T>std::shared_ptr<T>nullable,not_null,refstd::unique_ptr<T>nullableonlyUsage Example
Compile-Time Validation
Files Changed
New Files:
cpp/fory/meta/field.h- Core field template and type traitscpp/fory/meta/field_test.cc- 22 unit testscpp/fory/serialization/field_serializer_test.cc- 20 serialization testsModified Files:
cpp/fory/meta/BUILD,CMakeLists.txt- Build targetscpp/fory/serialization/BUILD,CMakeLists.txt- Build targetscpp/fory/serialization/struct_serializer.h- Field metadata integrationcpp/fory/serialization/type_resolver.h- Field type unwrappingRelated issues
Closes #3003
Related: #2906, #1017
Does this PR introduce any user-facing change?
fory::field<>template for field metadatafory::nullable,fory::not_null,fory::refBenchmark
For a struct with 10 fields using
fory::field<>with non-nullable defaults: