Commit 88a8b5b
committed
feat: implement trait-based serialization for distributed actors
Add comprehensive serialization system for joerl enabling message
serialization for network transmission, persistence, and distributed
actor communication.
Core Components:
- SerializableMessage trait with message_type_id(), as_any(), and serialize()
- MessageRegistry for mapping type IDs to deserializer functions
- SerializableEnvelope for wire format transmission with to_bytes()/from_bytes()
- SerializationError for comprehensive error handling
- impl_serializable! macro to reduce boilerplate
Wire Format:
- Simple binary format: [type_id_len][type_id][data_len][data]
- Length-prefixed fields for safety
- Little-endian encoding for cross-platform compatibility
Integration:
- Seamlessly works with existing Message (Box<dyn Any + Send>)
- Thread-safe MessageRegistry using Arc<RwLock<HashMap>>
- Can be shared across actors for distributed communication
Documentation:
- Comprehensive SERIALIZATION.md with usage guide and patterns
- Complete example in examples/serialization_example.rs
- Extensive rustdoc comments with examples
Testing:
- 11 unit tests covering all serialization scenarios
- All existing tests pass (61 unit tests, 31 integration tests)
- No clippy warnings
Design Notes:
- Renamed trait method to message_type_id() to avoid collision with Any::type_id()
- Uses custom serialization for flexibility and performance
- Supports dynamic message types with runtime type registry
- Overhead: 8 bytes + type_id length per message1 parent e8d84e3 commit 88a8b5b
4 files changed
Lines changed: 1429 additions & 0 deletions
0 commit comments