コンテンツにスキップ
日本語

ProtobufMessageType

このコンテンツはまだ日本語訳がありません。

Defined in: src/serialization/ProtobufSerializerOptions.ts:51

The slice of a Protobuf message type that ProtobufSerializer uses. Declared structurally rather than imported from protobufjs, the same call zodCodec makes with ParserLike: the schema belongs to the user’s project, so actor-ts neither pins a library version nor lazily imports something it never calls itself.

Why a message type and not a .proto path. Loading .proto at runtime would mean filesystem access — unavailable in a browser, behind a permission prompt on Deno, and a deployment concern everywhere (the file has to ship next to the bundle). Taking the compiled type pushes that choice to the user, who can reach it three ways without a build step being mandatory:

// 1. parse a .proto source string at startup (no filesystem)
const root = protobuf.parse(protoSource).root;
const messageType = root.lookupType('Order');
// 2. a JSON descriptor bundled with the app
const messageType = protobuf.Root.fromJSON(descriptor).lookupType('Order');
// 3. generated static code (pbjs, ts-proto) — shape matches too
import { Order } from './generated/order.js';

verify and toObject exist only on protobufjs’s reflection types, so both are optional here and generated static code still fits.

decode returns unknown, not T, on purpose. A reflection Type decodes to a dynamic Message that TypeScript cannot see the fields of, so declaring T there would make root.lookupType('Order') — the documented way to get a message type — fail to typecheck. The cast to T happens once, inside fromBinary, which is also where the plain- object conversion decides what the value actually is.

T = unknown

readonly optional fullName?: string

Defined in: src/serialization/ProtobufSerializerOptions.ts:61

Fully-qualified message name, used as the default manifest when set.

decode(bytes): unknown

Defined in: src/serialization/ProtobufSerializerOptions.ts:55

Decode bytes back into a dynamic message.

Uint8Array

unknown


encode(message): ProtobufWriter

Defined in: src/serialization/ProtobufSerializerOptions.ts:53

Encode a message into a writer; finish() produces the bytes.

T

ProtobufWriter


optional toObject(message, options?): Record<string, unknown>

Defined in: src/serialization/ProtobufSerializerOptions.ts:59

Reflection only: convert a decoded message into a plain object.

unknown

ProtobufConversionOptions

Record<string, unknown>


optional verify(message): string | null

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

Reflection only: returns a reason string when the message doesn’t match the schema.

T

string | null