export type JsonCodec = { encode(value: T): Uint8Array; decode(data: Uint8Array): T; }; export function createJsonCodec(): JsonCodec { const encoder = new TextEncoder(); const decoder = new TextDecoder(); return { encode(value: T): Uint8Array { return encoder.encode(JSON.stringify(value)); }, decode(data: Uint8Array): T { return JSON.parse(decoder.decode(data)) as T; }, }; }