Decoder

interface Decoder<out T>

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-owned PlatformBuffer.

  • buffer.toNativeData() → platform decoder → typed value (e.g. Bitmap wrapping PlatformBitmap) — zero-copy into a typed handle.

See buffer-codec/CLAUDE.md "Canonical decode patterns" for worked examples of each.

Inheritors

Functions

Link copied to clipboard
abstract fun decode(buffer: ReadBuffer, context: DecodeContext): T