The codec package provides message encoding and decoding functionality. It handles protobuf message serialization, frame formatting, and buffer management.
This package is designed for controlled environments where:
- Message types are known at compile time (protobuf types)
- Route set is known (no dynamic type discovery needed)
- Message sizes are bounded (known producers)
- No need for complex validation (trusted environment)
- Frame format with magic number, sizes, header, and message
- Protobuf-based encoding/decoding
- Buffer pool for efficient memory management
- Support for known types and dynamic type resolution (primarily known types)
-
Frame Format:
- Current: [Magic][TotalSize][HeaderSize][Header][MessageSize][Message]
- Question: Should we support different frame formats?
- Question: Should we support frame compression?
-
Magic Numbers:
- Current: 0xFADABEDA, 0xCEBAFE4A
- Question: Should we support versioning via magic numbers?
- Question: How to handle magic number collisions?
-
Size Fields:
- Current: 32-bit size fields
- Question: Should we support variable-length size encoding?
- Question: How to handle size field overflow?
-
Protobuf Encoding:
- Current: Standard protobuf encoding
- Question: Should we support compression? (gzip, snappy)
- Question: Should we support different encoding options?
-
Header Encoding:
- Current: Protobuf header encoding
- Question: Should we support header compression?
- Question: Should we support optional header fields?
-
Type Resolution:
- Current: Known types map + dynamic resolution
- Question: Should we support type versioning?
- Question: How to handle type mismatches?
-
Buffer Pool:
- Current: Uses libp2p buffer pool
- Question: Should we tune pool size?
- Question: How to handle buffer leaks?
-
Buffer Lifecycle:
- Current: Get/Release pattern
- Question: Should we support buffer ownership transfer?
- Question: How to handle buffer cleanup?
-
Large Messages:
- Current: No special handling for large messages
- Question: Should we support message chunking?
- Question: How to handle memory limits?
-
Encoding Performance:
- Current: Standard protobuf encoding
- Question: Can we optimize encoding? Use code generation?
- Question: Should we support zero-copy encoding?
-
Decoding Performance:
- Current: Standard protobuf decoding
- Question: Can we optimize decoding? Cache reflection?
- Question: Should we support zero-copy decoding?
-
Memory Allocations:
- Current: Buffer pool reduces allocations
- Question: Can we reduce allocations further?
- Question: Should we pre-allocate buffers?
-
Malformed Messages:
- Current: Returns errors
- Question: Should we support error recovery?
- Question: How to handle partial messages?
-
Size Validation:
- Current: Basic size validation
- Question: Should we support size limits?
- Question: How to handle oversized messages?
-
Type Errors:
- Current: Returns errors for type mismatches
- Question: Should we support type conversion?
- Question: How to handle unknown types?
-
Codec Plugins:
- Current: Single codec implementation
- Question: Should we support codec plugins?
- Question: How to add new codec types?
-
Versioning:
- Current: No versioning support
- Question: Should we support codec versioning?
- Question: How to handle version compatibility?
-
Compression:
- Current: No compression
- Question: Should we support compression?
- Question: Which compression algorithms?
- Buffer Leaks: Buffers may not always be released
- Size Limits: Fixed 32-bit size fields may limit message size
- Type Resolution: Dynamic type resolution may be slow
- Error Recovery: No recovery from malformed messages
- Add Compression: Support for message compression
- Improve Buffer Management: Better buffer lifecycle management
- Optimize Encoding/Decoding: Use code generation or caching
- Add Versioning: Support for codec versioning
- Improve Error Handling: Better error messages and recovery
- Add Metrics: Track encoding/decoding performance
- Backward Compatibility: How to handle protocol changes?
- Message Size Limits: What should be the maximum message size?
- Type Evolution: How to handle protobuf schema evolution?
- Compression: When should compression be used?