콘텐츠로 이동
한국어

ProtobufSerializer

이 콘텐츠는 아직 번역되지 않았습니다.

Defined in: src/serialization/ProtobufSerializer.ts:48

Protobuf Serializer — schema-driven binary with the wire-level forward compatibility Protobuf is chosen for (unknown fields are skipped rather than fatal).

The schema library stays the user’s: pass a compiled message type from protobufjs reflection, a JSON descriptor, or generated static code. This class owns what is easy to get wrong by hand — protobufjs’s Writer.finish() returns a view into a shared pool, so the bytes are detached before they can be handed to a journal; encode performs no validation, so verify runs first when the type offers it; and a decoded Message is converted to a plain object, which is what a persisted payload actually needs.

import protobuf from 'protobufjs';
const root = protobuf.parse(protoSource).root;
const protobufOptions = ProtobufSerializerOptions.create<Order>()
.withMessageType(root.lookupType('Order'))
.withId(101);
const serializer = new ProtobufSerializer(protobufOptions);

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 message type.

T = unknown

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

Defined in: src/serialization/ProtobufSerializer.ts:57

ProtobufSerializerOptions<T>

ProtobufSerializer<T>

readonly id: number

Defined in: src/serialization/ProtobufSerializer.ts:49

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/ProtobufSerializer.ts:51

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

Serializer.includesManifest


readonly name: string

Defined in: src/serialization/ProtobufSerializer.ts:50

Human-readable name, surfaced in diagnostics.

Serializer.name

fromBinary(bytes, manifest): T

Defined in: src/serialization/ProtobufSerializer.ts:86

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/ProtobufSerializer.ts:72

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/ProtobufSerializer.ts:74

Encode to binary.

T

Uint8Array

Serializer.toBinary