nim-chat-sdk/README.segmentation.md

33 lines
1.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Message Segmentation
Split large payloads into Waku-sized segments with optional ReedSolomon parity for robust reconstruction. Inbound segmented messages are reassembled and persisted until complete.
## Features
- **Segmentation**: Outbound payloads over the configured size are split into segments; smaller payloads pass through unchanged.
- **Reconstruction**: Inbound segments can be processed out of order and reassembled into the original message.
- **Erasure coding**: Adds parity segments at 12.5% of data segments (≤ SegmentsReedsolomonMaxCount), enabling recovery with ~87.5% of segments.
- **Persistence**: Segments and completion state are stored (SQLite) and survive restarts.
- **API simplicity**: Main parameter is the maximum segment size; inject your persistence object.
## Essential API
- **Types**: `SegmentationHander`, `Chunk`, `Message`
- **Outbound**: `segmentMessage(handler, chunk: Chunk): Result[seq[Chunk], string]`
- **Inbound**: `handleSegmentationLayer(handler, message: var Message): Result[void, string]`
- **Helpers**: `isParityMessage(segment: SegmentMessage): bool`
- **Parameters**: `segmentSize` (bytes); provide `SegmentationPersistence` instance
Notes
- Parity rate is 12.5% (`SegmentsParityRate = 0.125`).
## Wire format
Segments are protobuf-encoded (`segment_message.proto`):
## Tests
See `tests/test_segmentation.nim` for examples covering in-order/out-of-order and parity recovery paths.