OutWit.Common.MessagePack 1.1.2

dotnet add package OutWit.Common.MessagePack --version 1.1.2
                    
NuGet\Install-Package OutWit.Common.MessagePack -Version 1.1.2
                    
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="OutWit.Common.MessagePack" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OutWit.Common.MessagePack" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="OutWit.Common.MessagePack" />
                    
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 OutWit.Common.MessagePack --version 1.1.2
                    
#r "nuget: OutWit.Common.MessagePack, 1.1.2"
                    
#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 OutWit.Common.MessagePack@1.1.2
                    
#: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=OutWit.Common.MessagePack&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=OutWit.Common.MessagePack&version=1.1.2
                    
Install as a Cake Tool

OutWit.Common.MessagePack

A utility library for the MessagePack-CSharp serializer. It simplifies common serialization tasks, provides helpful extension methods, and includes a set of pre-configured, serializable data structures for common use cases.

Features

  • Simple Serialization/Deserialization: Extension methods (ToMessagePackBytes, FromMessagePackBytes) to serialize and deserialize any object with a single line of code.
  • Built-in Compression: Easily enable or disable LZ4 compression via a boolean flag.
  • Deep Cloning: A convenient .MessagePackClone() extension method to perform a deep copy of any serializable object.
  • Centralized Configuration: A simple static class MessagePackUtils for registering custom formatters and resolvers globally.
  • Custom Formatters Included:
    • TypeFormatter: Serializes System.Type objects.
    • PropertyChangedEventArgsFormatter: Serializes System.ComponentModel.PropertyChangedEventArgs.
  • File I/O Helpers: Methods to easily export and load collections to/from a MessagePack file.

Installation

Install the package via the .NET CLI:


dotnet add package OutWit.Common.MessagePack

Quick Start

The library is configured with sensible defaults and is ready to use immediately after installation.

Basic Serialization and Deserialization

The MessagePackUtils class provides extension methods for any object.

using OutWit.Common.MessagePack;

public class MyData
{
    public int Id { get; set; }
    public string Name { get; set; }
}

var myObject = new MyData { Id = 1, Name = "Test" };

// Serialize the object to a byte array (with LZ4 compression by default)
byte[] msgPackBytes = myObject.ToMessagePackBytes(); 

// Deserialize it back
MyData deserializedObject = msgPackBytes.FromMessagePackBytes<MyData>();

Disabling Compression

To serialize without compression, pass false to the withCompression parameter.

// Serialize without compression
byte[] plainBytes = myObject.ToMessagePackBytes(withCompression: false); 

// Deserialize without compression
MyData deserializedObject = plainBytes.FromMessagePackBytes<MyData>(withCompression: false);

Cloning an Object

You can create a deep clone of any serializable object using the MessagePackClone extension method.

var originalObject = new MyData { Id = 10, Name = "Original" };
var clonedObject = originalObject.MessagePackClone(); 

// clonedObject is a new instance with the same values
// but is not the same reference as originalObject.

Registering a Custom Formatter

The library uses a central resolver. You can easily register your own formatters at application startup.

using OutWit.Common.MessagePack;
using MessagePack;
using MessagePack.Formatters;

// 1. Define your custom formatter
public class MyCustomObjectFormatter : IMessagePackFormatter<MyCustomObject>
{
    public void Serialize(ref MessagePackWriter writer, MyCustomObject value, MessagePackSerializerOptions options)
    {
        // ... serialization logic
    }

    public MyCustomObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
    {
        // ... deserialization logic
    }
}

// 2. Register it at startup
public static class Program
{
    public static void Main(string[] args)
    {
        // Register the formatter for MyCustomObject
        MessagePackUtils.Register<MyCustomObjectFormatter>();

        // ... rest of your application
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OutWit.Common.MessagePack:

Package Downloads
OutWit.Communication

The core communication library of the WitRPC framework, providing base RPC functionality such as messaging, dynamic proxy support, and extensibility for multiple transports, serialization formats, and encryption.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.2 276 6/29/2025
1.1.1 248 6/6/2025
1.1.0 90 6/6/2025
1.0.3 127 3/14/2025
1.0.2 900 12/29/2024
1.0.1 115 11/24/2024
1.0.0 129 10/13/2024