Decoder
Reads T synchronously from a pre-bounded ReadBuffer.
Codecs must not retain the buffer/slice past return. The framework releases the slice on normal exit or exception via lexical slice().use { } / withBuffer { } semantics. To produce a value that outlives the decode scope, the codec copies bytes out at the boundary:
ReadBuffer.copyToByteArray — fresh heap
ByteArray, safe to retain.factory.allocate(remaining).also { it.write(buffer); it.resetForRead() }— consumer-ownedPlatformBuffer.buffer.toNativeData()→ platform decoder → typed value (e.g.BitmapwrappingPlatformBitmap) — zero-copy into a typed handle.
See buffer-codec/CLAUDE.md "Canonical decode patterns" for worked examples of each.