Skip to content

Protocol Buffers serialization in Orleans

Use the Protocol Buffers integration to pass generated Google.Protobuf messages in grain calls. Orleans delegates payload serialization to the message and deserialization to its descriptor’s parser.

Terminal window
dotnet add package Microsoft.Orleans.Serialization.Protobuf

Generate your C# message types from .proto files using the Protocol Buffers C# tooling.

Register AddProtobufSerializer through the ISiloBuilder services:

siloBuilder.Services.AddSerializer(serializerBuilder =>
{
serializerBuilder.AddProtobufSerializer();
});

The parameterless registration selects concrete Google.Protobuf IMessage implementations for serialization and deep copying. Generated message types supply the parameterless constructor and descriptor parser used by the codec. The overload accepting isSerializable and isCopyable delegates lets you select a subset of message types.

Apply matching registrations on every silo and client that exchanges these messages. See Authorize type-name resolution for shared type authorization settings.

Orleans wraps the Protocol Buffers payload with its wire metadata, including the runtime type. Deep copying writes the message and parses a new instance using its descriptor’s parser.

Protocol Buffers defines the schema and compatibility rules within each message. Preserve field numbers and follow the Protocol Buffers updating guidance when evolving .proto contracts.