跳转到内容
简体中文

AvroSerializer

此内容尚不支持你的语言。

Defined in: src/serialization/AvroSerializer.ts:39

Avro Serializer — compact, schema-driven binary for a single type.

The schema library stays the user’s: pass a compiled avsc type (or anything with the same toBuffer/fromBuffer pair) and this class owns the parts that are easy to get wrong when wiring one up by hand — the Buffer coercion avsc needs on the read path (a plain Uint8Array, which is what base64 framing yields, throws deep inside the decoder), byte ownership, the manifest, and errors that name the serializer instead of surfacing a library-internal message.

import avsc from 'avsc';
const avroType = avsc.Type.forSchema({
name: 'Deposited',
type: 'record',
fields: [{ name: 'amount', type: 'int' }],
});
const avroOptions = AvroSerializerOptions.create<Deposited>()
.withAvroType(avroType)
.withId(100);
const serializer = new AvroSerializer(avroOptions);

Reaches stored rows through a store’s withSerializer(...) (one format for the whole store) or, per (manifest, version), through serializerCodec(serializer) and the SchemaRegistry.

Stateless and safe to share: every method reads only the compiled type.

T = unknown

new AvroSerializer<T>(options): AvroSerializer<T>

Defined in: src/serialization/AvroSerializer.ts:47

AvroSerializerOptions<T>

AvroSerializer<T>

readonly id: number

Defined in: src/serialization/AvroSerializer.ts:40

Stable identifier that is embedded in every frame. Numbers 1..99 are reserved for the actor-ts built-ins (JSON=1, CBOR=2). User-defined serializers SHOULD use IDs ≥ RESERVED_SERIALIZER_IDS_BELOW.

Serializer.id


readonly includesManifest: boolean

Defined in: src/serialization/AvroSerializer.ts:42

True when this serializer is willing to encode the given value.

Serializer.includesManifest


readonly name: string

Defined in: src/serialization/AvroSerializer.ts:41

Human-readable name, surfaced in diagnostics.

Serializer.name

fromBinary(bytes, manifest): T

Defined in: src/serialization/AvroSerializer.ts:70

Decode from binary. manifest is whatever was produced on the other side (or ” when the serializer does not use one).

Uint8Array

string

T

Serializer.fromBinary


manifest(_obj): string

Defined in: src/serialization/AvroSerializer.ts:60

Return a tag describing the concrete type of obj so the decoder knows how to reconstruct it. Typical values: class name, event ID, “map”, “null”, etc. May return an empty string for serializers that don’t need a manifest.

T

string

Serializer.manifest


toBinary(obj): Uint8Array

Defined in: src/serialization/AvroSerializer.ts:62

Encode to binary.

T

Uint8Array

Serializer.toBinary