-
Notifications
You must be signed in to change notification settings - Fork 358
Closed
Labels
Description
Feature Request
Implement xlang serialization framework for C++ with full polymorphism support
Is your feature request related to a problem? Please describe
Currently, Fory C++ lacks a complete xlang serialization implementation that provides the same level of functionality as Rust, Java, and Python implementations. Specifically:
- No Cross-Language Object Serialization: C++ cannot serialize arbitrary objects in a way that's compatible with other Fory language implementations
- Missing Polymorphism Support: No ability to serialize/deserialize polymorphic types (virtual base classes, smart pointers to derived types)
- Limited Type System: Existing C++ implementation focuses on row format, lacking the rich type system needed for object graph serialization
- Schema Evolution Gap: No support for schema-compatible struct serialization with field name compression (meta sharing)
- Reference Tracking Absent: Cannot handle shared references and circular references in object graphs
This limits C++'s interoperability in multi-language Fory deployments and prevents C++ developers from leveraging Fory's full cross-language serialization capabilities.
Describe the solution you'd like
A complete C++ xlang serialization framework that mirrors the Rust implementation's feature set:
Core Serialization Framework:
- Full xlang serialization protocol implementation following the xlang specification
- Type resolver with comprehensive type system (primitives, collections, structs, enums, temporal types)
- Reference resolver for handling shared and circular references
- Configurable serialization modes (compatible vs. non-compatible)
Polymorphism Support:
- Runtime type identification using C++ RTTI (
std::type_index) - Polymorphic serialization for smart pointers (
std::unique_ptr,std::shared_ptr,std::weak_ptr) - Type traits system (
is_polymorphic<T>) for compile-time polymorphism detection - Wire format compatibility with Rust/Java polymorphic types
- Type info encoding/decoding (
write_any_typeinfo,read_any_typeinfo)
Type System:
- Comprehensive serializers for all C++ standard types:
- Primitives (integers, floats, bool, char)
- Strings (
std::string,std::string_view) - Collections (
std::vector,std::map,std::unordered_map,std::set,std::unordered_set) - Smart pointers (
std::unique_ptr,std::shared_ptr,std::weak_ptr) - Optional types (
std::optional) - Temporal types (
std::chrono::duration, time points) - Arrays (
std::array) - Enums (both scoped and unscoped)
- User-defined structs with compile-time reflection
Schema Evolution:
- Compatible struct serialization with field name compression
- Meta string sharing for efficient type name encoding
- Support for adding/removing struct fields without breaking compatibility
- Field ordering optimization (sort by fory xlang fields sort spec)
API Design:
- Builder pattern for Fory instance configuration
- Type-safe serialization/deserialization APIs using
Result<T, Error> - Support for custom serializers via trait specialization
- Zero-copy where possible using buffer views
- Thread-safe type resolver (immutable design)
Testing:
- Comprehensive unit tests
Describe alternatives you've considered
/
Additional context
Performance Considerations:
- Uses C++17 features for type traits and
constexpr iffor zero-overhead polymorphism checks - Buffer-based I/O with minimal allocations
- Type resolver uses immutable design to avoid locking overhead
- Compile-time type detection for optimal codegen
Cross-Language Compatibility:
- Wire format 100% compatible with Rust implementation
- Follows exact same protocol for type encoding/decoding
Use Cases:
- High-performance microservices needing cross-language RPC
- Game engines serializing complex object hierarchies
- Scientific computing with Python/C++ interop
- Data pipelines mixing C++/Rust/Java components
- Distributed systems requiring polymorphic message passing