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
<PackageReference Include="OutWit.Common.MessagePack" Version="1.1.2" />
<PackageVersion Include="OutWit.Common.MessagePack" Version="1.1.2" />
<PackageReference Include="OutWit.Common.MessagePack" />
paket add OutWit.Common.MessagePack --version 1.1.2
#r "nuget: OutWit.Common.MessagePack, 1.1.2"
#:package OutWit.Common.MessagePack@1.1.2
#addin nuget:?package=OutWit.Common.MessagePack&version=1.1.2
#tool nuget:?package=OutWit.Common.MessagePack&version=1.1.2
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
: SerializesSystem.Type
objects.PropertyChangedEventArgsFormatter
: SerializesSystem.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 | Versions 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. |
-
.NETStandard 2.0
- MessagePack (>= 3.1.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net6.0
- MessagePack (>= 3.1.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net7.0
- MessagePack (>= 3.1.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net8.0
- MessagePack (>= 3.1.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
-
net9.0
- MessagePack (>= 3.1.3)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- OutWit.Common.Aspects (>= 1.2.2)
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.