Serializers
JsonSerializer, MsgpackSerializer, CborSerializer, and the Serializer interface.
JsonSerializer, MsgpackSerializer, CborSerializer, and the Serializer interface.
import { Queue, JsonSerializer, MsgpackSerializer } from "@byteveda/flexiq";
import type { Serializer } from "@byteveda/flexiq";| Class | Description |
|---|---|
JsonSerializer | Default. Human-readable JSON bytes. |
MsgpackSerializer | Compact binary (msgpack). |
CborSerializer | Binary (CBOR, RFC 8949), tagged with the 0x02 wire-envelope byte — the default format for tasks produced or consumed by another FlexiQ SDK. Integers beyond Number.MAX_SAFE_INTEGER round-trip as BigInt. |
SignedSerializer | Wraps another codec with an HMAC-SHA256 tag; rejects tampered payloads. |
EncryptedSerializer | Wraps another codec with AES-256-GCM; encrypts + authenticates. |
new Queue({ dbPath: "flexiq.db", serializer: new MsgpackSerializer() });import { Queue, CborSerializer } from "@byteveda/flexiq";
new Queue({ dbPath: "flexiq.db", serializer: new CborSerializer() });SignedSerializer(secret, inner?) prefixes each payload with a 32-byte HMAC tag
and verifies it (timing-safe) on read — authentication, not encryption.
EncryptedSerializer(secret, inner?) goes further: AES-256-GCM gives
confidentiality and integrity. Both derive their key from secret, so
producers and workers must share it.
new Queue({
dbPath: "flexiq.db",
serializer: new EncryptedSerializer(process.env.FLEXIQ_SECRET!),
});A PayloadCodec is a reversible byte transform layered around a serializer
— compression, encryption, signing — rather than a replacement for it. Codecs
compose: a chain encodes in list order on the producer and decodes in reverse
on the worker. Wire formats are part of the cross-SDK contract, so a
codec-framed payload decodes from any FlexiQ SDK.
interface PayloadCodec {
encode(data: Uint8Array): Uint8Array;
decode(data: Uint8Array): Uint8Array;
}| Class | Wire format | Description |
|---|---|---|
GzipCodec(maxDecompressedBytes?) | standard gzip stream | Compresses; decompression capped at 64 MiB by default (zip-bomb guard). |
HmacCodec(key) | [32-byte mac][body] | HMAC-SHA256 signs; rejects tampered or wrong-key payloads. |
AesGcmCodec(key) | [12-byte IV][ciphertext || 16-byte tag] | AES-128/192/256-GCM (by key length); confidentiality + integrity. |
Apply a chain queue-wide with QueueOptions.codec (wraps the serializer,
covers every payload and result), or register named codecs via
QueueOptions.codecs and opt individual tasks in with TaskOptions.codecs
(payload only — results still use the plain serializer):
import { Queue, GzipCodec, HmacCodec } from "@byteveda/flexiq";
const queue = new Queue({
dbPath: "flexiq.db",
codec: [new GzipCodec(), new HmacCodec(hmacKey)], // encodes gzip, then hmac
});CodecSerializer is the internal Serializer that layers a codec chain
around a delegate serializer — QueueOptions.codec builds one for you, so
you rarely construct it directly.
Serializer interfaceinterface Serializer {
serialize(value: unknown): Uint8Array;
deserialize(bytes: Uint8Array): unknown;
}The Rust core treats payloads as opaque bytes; serialization is entirely Node-side. Producers and workers must use a compatible serializer.
See the Serializers guide for a custom implementation.