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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RabbitRpc.Serialization.MemoryPack" Version="4.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RabbitRpc.Serialization.MemoryPack" Version="4.0.0" />
                    
Directory.Packages.props
<PackageReference Include="RabbitRpc.Serialization.MemoryPack" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RabbitRpc.Serialization.MemoryPack --version 4.0.0
                    
#r "nuget: RabbitRpc.Serialization.MemoryPack, 4.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RabbitRpc.Serialization.MemoryPack@4.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RabbitRpc.Serialization.MemoryPack&version=4.0.0
                    
Install as a Cake Addin
#tool nuget:?package=RabbitRpc.Serialization.MemoryPack&version=4.0.0
                    
Install as a Cake Tool

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 / PrewarmAssembly move the per-type formatter build off the hot path to startup.

Limitations

  • Reflection-built path is not AOT or trim safe. Compile with PublishAot=true only 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

License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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