RabbitRpc.Serialization.MemoryPack
4.0.0
dotnet add package RabbitRpc.Serialization.MemoryPack --version 4.0.0
NuGet\Install-Package RabbitRpc.Serialization.MemoryPack -Version 4.0.0
<PackageReference Include="RabbitRpc.Serialization.MemoryPack" Version="4.0.0" />
<PackageVersion Include="RabbitRpc.Serialization.MemoryPack" Version="4.0.0" />
<PackageReference Include="RabbitRpc.Serialization.MemoryPack" />
paket add RabbitRpc.Serialization.MemoryPack --version 4.0.0
#r "nuget: RabbitRpc.Serialization.MemoryPack, 4.0.0"
#:package RabbitRpc.Serialization.MemoryPack@4.0.0
#addin nuget:?package=RabbitRpc.Serialization.MemoryPack&version=4.0.0
#tool nuget:?package=RabbitRpc.Serialization.MemoryPack&version=4.0.0
RabbitRpc.Serialization.MemoryPack
MemoryPack binary IRpcSerializer adapter for RabbitRpc. One of three serialization adapters available for RabbitRpc 4.x — pick this one when you need a compact binary wire format and want to keep working with vendor DTOs that you cannot decorate with [MemoryPackable].
Installation
dotnet add package RabbitRpc.Serialization.MemoryPack
dotnet add package RabbitRpc.Client # or RabbitRpc.Server
Pack for NuGet
dotnet pack -c Release
This package is a sidecar to RabbitRpc.Client / RabbitRpc.Server — install one (or both) of those alongside it.
Configuration
Server:
using AsbtCore.Broker.Server;
using AsbtCore.Broker.Serialization.MemoryPack;
services.AddRabbitRpcServer(configuration)
.UseMemoryPackRpcSerialization()
.Register<IMyService, MyServiceImpl>();
Client:
using AsbtCore.Broker.Client;
using AsbtCore.Broker.Serialization.MemoryPack;
services.AddRabbitRpcClient(configuration)
.UseMemoryPackRpcSerialization()
.AddProxy<IMyService>();
ContentType published on BasicProperties is application/x-memorypack.
DTO requirements
Two supported paths — mix freely in the same contract:
1. Source-generated ([MemoryPackable]) — recommended for hot paths. Declare DTOs partial and decorate; MemoryPack emits codecs at compile time. AOT/trim-safe.
[MemoryPackable]
public sealed partial class UserDto
{
public Guid Id { get; init; }
public string Name { get; init; } = string.Empty;
}
2. Reflection-built (no attribute). Plain DTOs, records, and init-only POCOs are auto-discovered on first use. Wire layout matches the declaration-order source-gen for compatible types. Useful for vendor DTOs you cannot modify. Not AOT/trim-safe.
For polymorphism, register the union explicitly — MemoryPack cannot infer derived types from a base reference at runtime:
services.AddRabbitRpcServer(configuration)
.UseMemoryPackRpcSerialization(opt =>
{
opt.PrewarmAssembly(typeof(UserDto).Assembly);
opt.RegisterUnion<Animal>(b => b
.Add<Cat>(tag: 1)
.Add<Dog>(tag: 2));
});
Wire format & performance
- Binary, length-prefixed; identical bytes for
[MemoryPackable]and reflection-built paths for the same logical type. [MemoryPackable]source-gen: zero-allocation hot paths, fastest of the three adapters for known-shape DTOs.- Reflection-built: estimated ~2-4× slower than source-gen on the same DTO, still measurably faster than JSON. (Architectural estimate; no benchmark on this codepath yet.)
PrewarmType/PrewarmAssemblymove the per-type formatter build off the hot path to startup.
Limitations
- Reflection-built path is not AOT or trim safe. Compile with
PublishAot=trueonly when every DTO is[MemoryPackable]. - Polymorphic base types must be registered with
RegisterUnion<T>(...); runtime discovery cannot infer the union table. - Cycle detection uses thread-static state; no cross-thread aliasing in a single serialization call (this matters only for custom transports).
See Also
- RabbitRpc.Client — client-side library with typed proxies.
- RabbitRpc.Server — server-side library that hosts RPC implementations.
- RabbitRpc.Serialization.XPacketRpc — sibling binary adapter, source-gen via XPacketRpc.
- RabbitRpc.Serialization.SystemTextJson — JSON adapter for v3 wire compatibility and debugging.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MemoryPack (>= 1.21.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0 | 88 | 5/15/2026 |
v4.0.0 — Unified release under the RabbitRpc 4.x line.
- Targets the IRpcSerializer v4 surface (SerializeEnvelope/DeserializeEnvelope/SerializeFragment/DeserializeFragment).
- Compatible with RabbitRpc.Client 4.x and RabbitRpc.Server 4.x; wire format is incompatible with v3.x adapters.
- Reflection-based formatter for DTOs without [MemoryPackable] (lazy auto-discovery for POCO / record / init-only DTOs).
- MemoryPackRpcOptions API: PrewarmType / PrewarmTypes / PrewarmAssembly, and RegisterUnion<T> for polymorphism.
- Wire format unchanged for [MemoryPackable] types; reflection layout matches declaration-order source-gen for plain DTOs.
- UseMemoryPackRpcSerialization() callers continue to work; new overload accepts Action<MemoryPackRpcOptions>.