Codec
Defined in: packages/codecs/src/types.ts:39
Core codec interface.
Example
Section titled “Example”// Simple object codecconst jsonCodec: Codec<MyData> = { name: 'json', serialize: (data) => Buffer.from(JSON.stringify(data)), deserialize: (buf) => JSON.parse(buf.toString()),};
// Zero-copy raw codecconst rawCodec: Codec<Buffer[], Buffer[]> = { name: 'raw-chunks', serialize: (chunks) => Buffer.concat(chunks), deserialize: (buf) => [buf], deserializeChunks: (chunks) => [...chunks], // Zero-copy!};Type Parameters
Section titled “Type Parameters”TInput
Section titled “TInput”TInput = unknown
Type accepted by serialize()
TOutput
Section titled “TOutput”TOutput = TInput
Type returned by deserialize() (defaults to TInput)
Properties
Section titled “Properties”
readonlyname:string
Defined in: packages/codecs/src/types.ts:73
Human-readable codec name for debugging/logging.
Methods
Section titled “Methods”deserialize()
Section titled “deserialize()”deserialize(
buffer):TOutput
Defined in: packages/codecs/src/types.ts:57
Deserialize from a single merged buffer.
⚠️ WARNING: If called for large payloads, this implies a memory copy happened earlier (chunks were merged).
Parameters
Section titled “Parameters”buffer
Section titled “buffer”Buffer
Binary data to deserialize
Returns
Section titled “Returns”TOutput
Deserialized data
deserializeChunks()?
Section titled “deserializeChunks()?”
optionaldeserializeChunks(chunks):TOutput
Defined in: packages/codecs/src/types.ts:68
Deserialize from raw chunks (Zero-Copy potential).
Implement this to process data without merging buffers.
If not implemented, framework defaults to deserialize(Buffer.concat(chunks)).
Parameters
Section titled “Parameters”chunks
Section titled “chunks”readonly Buffer<ArrayBufferLike>[]
Array of buffer chunks from FrameBuffer
Returns
Section titled “Returns”TOutput
Deserialized data
serialize()
Section titled “serialize()”serialize(
data):Buffer
Defined in: packages/codecs/src/types.ts:46
Serialize data to binary format.
Parameters
Section titled “Parameters”TInput
Data to serialize
Returns
Section titled “Returns”Buffer
Binary representation as Buffer