MessagePack for C# has extension point and you can add external type's serialization support. There are official extension support.
Install-Package MessagePack.ImmutableCollection
Install-Package MessagePack.ReactiveProperty
Install-Package MessagePack.UnityShims
Install-Package MessagePack.AspNetCoreMvcFormatter
MessagePack.ImmutableCollection
package add support for System.Collections.Immutable library. It adds ImmutableArray<>
, ImmutableList<>
, ImmutableDictionary<,>
, ImmutableHashSet<>
, ImmutableSortedDictionary<,>
, ImmutableSortedSet<>
, ImmutableQueue<>
, ImmutableStack<>
, IImmutableList<>
, IImmutableDictionary<,>
, IImmutableQueue<>
, IImmutableSet<>
, IImmutableStack<>
serialization support.
MessagePack.ReactiveProperty
package add support for ReactiveProperty library. It adds ReactiveProperty<>
, IReactiveProperty<>
, IReadOnlyReactiveProperty<>
, ReactiveCollection<>
, Unit
serialization support. It is useful for save viewmodel state.
MessagePack.UnityShims
package provides shim of Unity's standard struct(Vector2
, Vector3
, Vector4
, Quaternion
, Color
, Bounds
, Rect
, AnimationCurve
, Keyframe
, Matrix4x4
, Gradient
, Color32
, RectOffset
, LayerMask
, Vector2Int
, Vector3Int
, RangeInt
, RectInt
, BoundsInt
) and there formatter. It can enable to commnicate between server and Unity client.
After install, extension package must enable by configuration. Here is sample of enable all extension.
// set extensions to default resolver.
MessagePack.Resolvers.CompositeResolver.RegisterAndSetAsDefault(
// enable extension packages first
ImmutableCollectionResolver.Instance,
ReactivePropertyResolver.Instance,
MessagePack.Unity.Extension.UnityBlitResolver.Instance,
MessagePack.Unity.UnityResolver.Instance,
// finaly use standard(default) resolver
StandardResolver.Instance);
);
Configuration details, see:Extension Point section.
MessagePack.AspNetCoreMvcFormatter
is add-on of ASP.NET Core MVC's serialization to boostup performance. This is configuration sample.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddMvcOptions(option =>
{
option.OutputFormatters.Clear();
option.OutputFormatters.Add(new MessagePackOutputFormatter(ContractlessStandardResolver.Instance));
option.InputFormatters.Clear();
option.InputFormatters.Add(new MessagePackInputFormatter(ContractlessStandardResolver.Instance));
});
}
Author is creating other extension packages, too.
- MasterMemory - Embedded Readonly In-Memory Document Database
- MagicOnion - gRPC based HTTP/2 RPC Streaming Framework
- DatadogSharp - C# Datadog client
You can make your own extension serializers or integrate with framework, let's create them and share it!
- MessagePack.FSharpExtensions - supports F# list,set,map,unit,option,discriminated union
- MessagePack.NodaTime - Support for NodaTime types to MessagePack C#
- WebApiContrib.Core.Formatter.MessagePack - supports ASP.NET Core MVC(details in blog post)
- MessagePack.MediaTypeFormatter - MessagePack MediaTypeFormatter