-
Notifications
You must be signed in to change notification settings - Fork 358
feat(c++): implement fory cpp object graph serialization framework #2908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chaokunyang
merged 27 commits into
apache:main
from
chaokunyang:cpp_serializer_framework
Nov 10, 2025
Merged
feat(c++): implement fory cpp object graph serialization framework #2908
chaokunyang
merged 27 commits into
apache:main
from
chaokunyang:cpp_serializer_framework
Nov 10, 2025
Conversation
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
Contributor
|
It's amazing! |
pandalee99
approved these changes
Nov 10, 2025
Contributor
pandalee99
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
86aef65 to
f32df58
Compare
802f2e6 to
d965618
Compare
d965618 to
72ae168
Compare
This was referenced Nov 26, 2025
chaokunyang
added a commit
that referenced
this pull request
Nov 26, 2025
## Why? #2908 implemented c++ serialization framework, but don't fully implement xlang spec, and don't align with java/rust. ## What does this PR do? - implement xlang serialization for c++ - align with java/rust type system - implement meta string encoding for c++ - add write_type_info/read_type_info - align collection/map serialization with java/rust - add xlang serialization tests ## Related issues #2906 Closes #2909 Closes #1543 ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary. Delete section if not applicable. --> - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. Delete section if not applicable. -->
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?
This PR addresses the gap in Fory C++ by implementing a complete xlang serialization framework with full polymorphism support, bringing C++ to feature parity with Rust, Java, and Python implementations. Currently, C++ only supports row format serialization, which limits its ability to:
This implementation enables C++ developers to leverage Fory's full cross-language serialization capabilities in high-performance applications like microservices, game engines, and distributed systems.
What does this PR do?
This PR implements a complete xlang serialization framework for C++ consisting of 26 new files (~12K lines):
Core Framework
fory.h: Main entry point with builder pattern API for Fory instance configurationtype_resolver.h/cc: Comprehensive type system with registration and resolution for all supported typescontext.h/cc: Read/write contexts for serialization with buffer management and depth trackingref_resolver.h: Reference tracking for handling shared and circular referencesconfig.h: Configuration options (compatible mode, ref tracking, etc.)Polymorphism Support
serializer_traits.h: Type traits system including:is_polymorphic<T>trait for compile-time polymorphism detectionget_concrete_type_id()for runtime type identification using RTTIcontext.h/cc: Type info encoding/decoding:write_any_typeinfo(): Writes polymorphic type information (type_id, meta_index, or namespace+typename)read_any_typeinfo(): Reads and resolves polymorphic type informationsmart_ptr_serializers.hforstd::unique_ptr,std::shared_ptrmap_serializer.hSerializer Implementations
basic_serializer.h: Primitives (integers, floats, bool, char), stringscollection_serializer.h:std::vector,std::set,std::unordered_setmap_serializer.h:std::map,std::unordered_mapwith polymorphic key/value supportarray_serializer.h:std::arraysmart_ptr_serializers.h: Smart pointers with full polymorphismstruct_serializer.h: User-defined structs with reflection, compatible mode with field compressionenum_serializer.h: Scoped and unscoped enumstemporal_serializers.h:std::chrono::durationand time pointsskip.h/cc: Utilities for skipping unknown types during deserializationTesting
serialization_test.cc: Basic types and collections (26 tests)struct_test.cc: Struct serialization (27 tests)struct_compatible_test.cc: Schema evolution (12 tests)map_serializer_test.cc: Map polymorphism (17 tests)smart_ptr_serializer_test.cc: Smart pointer polymorphism (6 tests)Key Features Implemented
constexpr iffor compile-time polymorphism checksResult<T, Error>pattern withFORY_TRYmacroImplementation Highlights
Polymorphic Type Encoding (mirrors Rust implementation):
Thread-Safe Type Resolver:
Field Ordering Optimization:
Related issues
Closes #2907
#2906
Related to discussion on C++ xlang serialization support. This implementation follows the same architecture and protocol as the Rust implementation to ensure cross-language compatibility.
Does this PR introduce any user-facing change?
Does this PR introduce any public API change?
fory::serializationnamespace with complete xlang serialization APIFory,ForyBuilder,WriteContext,ReadContext,TypeResolver,RefResolverSerializer<T>,is_polymorphic<T>,SerializationMeta<T>Config, reference tracking modes, compatible modesDoes this PR introduce any binary protocol compatibility change?
API Example
Build and Test
Documentation
Will be provided in following-up PR
Performance Considerations
constexpr ifeliminates runtime overhead for non-polymorphic typesCross-Language Compatibility
Wire format should to be compatible with Rust implementation (primary reference)
This enables seamless data exchange between C++ and other Fory language implementations in polyglot systems.