ChunkCodec
Splits an arbitrarily-sized payload into 1..N BYTES chunks and reassembles them.
Wire header (8 bytes, big-endian)
[msgId: Int (4 bytes)] [chunkIndex: UShort (2 bytes)] [chunkCount: UShort (2 bytes)] [payload bytes...]A ≤MAX_CHUNK_PAYLOAD-byte message is a single chunk (chunkIndex=0, chunkCount=1). An empty payload is encoded as one chunk with zero payload bytes.
Thread-safety: encode and decodeChunk are stateless and safe to call concurrently. Reassembler is NOT thread-safe — callers must synchronise (or use one instance per coroutine / per-endpoint).
Types
Per-endpoint reassembler. Feed decoded chunks in arrival order; feed returns the complete payload once all chunks for a message have arrived.
Properties
Byte size of the fixed chunk header.
Default maximum bytes of message payload per chunk (header excluded). Approximates ConnectionsClient.MAX_BYTES_DATA_SIZE (≈32 768) minus the header. The real cap is injected by the Android binding at construction time.
Functions
Decode the header fields and payload slice from a raw received chunk. Returns null if bytes is shorter than HEADER_SIZE or the header is internally inconsistent (e.g. chunkIndex ≥ chunkCount, chunkCount = 0).