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.
Type Parameters
Section titled “Type Parameters”T = unknown
Implements
Section titled “Implements”Serializer<T>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ProtobufSerializer<
T>(options):ProtobufSerializer<T>
Defined in: src/serialization/ProtobufSerializer.ts:57
Parameters
Section titled “Parameters”options
Section titled “options”Returns
Section titled “Returns”ProtobufSerializer<T>
Properties
Section titled “Properties”
readonlyid: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.
Implementation of
Section titled “Implementation of”includesManifest
Section titled “includesManifest”
readonlyincludesManifest:boolean
Defined in: src/serialization/ProtobufSerializer.ts:51
True when this serializer is willing to encode the given value.
Implementation of
Section titled “Implementation of”
readonlyname:string
Defined in: src/serialization/ProtobufSerializer.ts:50
Human-readable name, surfaced in diagnostics.
Implementation of
Section titled “Implementation of”Methods
Section titled “Methods”fromBinary()
Section titled “fromBinary()”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).
Parameters
Section titled “Parameters”Uint8Array
manifest
Section titled “manifest”string
Returns
Section titled “Returns”T
Implementation of
Section titled “Implementation of”manifest()
Section titled “manifest()”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.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”string
Implementation of
Section titled “Implementation of”toBinary()
Section titled “toBinary()”toBinary(
obj):Uint8Array
Defined in: src/serialization/ProtobufSerializer.ts:74
Encode to binary.
Parameters
Section titled “Parameters”T
Returns
Section titled “Returns”Uint8Array
