Codec

interface Codec<T> : Encoder<T> , Decoder<T> , FrameDetector

Complete codec: encodes, decodes, and detects frame boundaries.

Implementors override exactly two methods — the context-aware versions:

The context-free overloads inherited from Encoder and Decoder delegate to the context versions with DecodeContext.Empty / EncodeContext.Empty, so callers that don't need context work transparently.

Simple codecs that don't use context just ignore the context parameter.

Functions

Link copied to clipboard
open override fun decode(buffer: ReadBuffer): T

Decodes a value from buffer at the current position.

abstract fun decode(buffer: ReadBuffer, context: DecodeContext): T

Decodes a value from buffer with runtime context.

Link copied to clipboard
open override fun encode(buffer: WriteBuffer, value: T)

Encodes value to buffer at the current position.

abstract fun encode(buffer: WriteBuffer, value: T, context: EncodeContext)

Encodes value to buffer with runtime context.

Link copied to clipboard
fun <T> Codec<T>.encodeToBuffer(value: T, factory: BufferFactory = BufferFactory.Default, context: EncodeContext = EncodeContext.Empty): ReadBuffer
Link copied to clipboard
open override fun peekFrameSize(stream: StreamProcessor, baseOffset: Int): PeekResult
Link copied to clipboard
open override fun sizeOf(value: T): SizeEstimate

Estimates the encoded size of value for buffer pre-allocation.

Link copied to clipboard
fun <T> Codec<T>.testRoundTrip(value: T, expectedBytes: ByteArray? = null, factory: BufferFactory = BufferFactory.Default, decodeContext: DecodeContext = DecodeContext.Empty, encodeContext: EncodeContext = EncodeContext.Empty): T

Testing utility: encodes value, optionally verifies the wire bytes match expectedBytes, then decodes and returns the result. Intended for use in test suites to validate codec correctness.