MPack 2.0.4
See the version list below for details.
dotnet add package MPack --version 2.0.4
NuGet\Install-Package MPack -Version 2.0.4
<PackageReference Include="MPack" Version="2.0.4" />
paket add MPack --version 2.0.4
#r "nuget: MPack, 2.0.4"
// Install MPack as a Cake Addin #addin nuget:?package=MPack&version=2.0.4 // Install MPack as a Cake Tool #tool nuget:?package=MPack&version=2.0.4
MPack
This library is a lightweight implementation of the MessagePack binary serialization format. MessagePack is a 1-to-1 binary representation of JSON, and the official specification can be found here: https://github.com/msgpack....
Notes
- This library is designed to be super light weight.
- Its easiest to understand how this library works if you think in terms of json. The type
MDict
represents a dictionary, and the typeMArray
represents an array. - Create MPack values with the static method
MToken.From(object);
. You can pass any simple type (such as string, integer, etc), or any Array composed of a simple type. MPack also has implicit conversions from most of the basic types built in. - Transform an MPack object back into a CLR type with the static method
MToken.To<T>();
orMToken.To(type);
. MPack also has explicit converions going back to most basic types, you can dostring str = (string)mpack;
for instance. - MPack now supports native asynchrounous reading and cancellation tokens. It will not block a thread to wait on a stream.
NuGet
MPack is available as a NuGet package!
PM> Install-Package MPack
Usage
Create a object model that can be represented as MsgPack. Here we are creating a dictionary, but really it can be anything:
using MPack;
var dictionary = new MDict
{
{
"array1", MToken.From(new[]
{
"array1_value1", // implicitly converted string
MToken.From("array1_value2"),
})
},
{"bool1", MToken.From(true)}, //boolean
{"double1", MToken.From(50.5)}, //single-precision float
{"double2", MToken.From(15.2)},
{"int1", 50505}, // implicitly converted integer
{"int2", MToken.From(50)} // integer
};
Serialize the data to a byte array or to a stream to be saved, transmitted, etc:
byte[] encodedBytes = dictionary.EncodeToBytes();
// -- or --
dictionary.EncodeToStream(stream);
Parse the binary data back into a MPack object model (you can also cast back to an MPackMap or MPackArray after reading if you want dictionary/array methods):
var reconstructed = MToken.ParseFromBytes(encodedBytes);
// -- or --
var reconstructed = MToken.ParseFromStream(stream);
Turn MPack objects back into types that we understand with the generic To<>()
method. Since we know the types of everything here we can just call To<bool>()
to reconstruct our bool, but if you don't know you can access the instance enum MToken.ValueType
to know what kind of value it is:
bool bool1 = reconstructed["bool1"].To<bool>();
var array1 = reconstructed["array1"] as MArray;
var array1_value1 = array1[0];
double double1 = reconstructed["double1"].To<double>();
//etc...
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 was computed. 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 was computed. 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. |
.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 | net45 is compatible. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 is compatible. 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. |
-
.NETFramework 4.5
- No dependencies.
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MPack:
Package | Downloads |
---|---|
SharpWood
SharpWood - A C# Wrapper for Mafia: Oakwood |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.1 | 403 | 3/13/2024 |
2.0.4 | 183 | 1/24/2024 |
1.1.0.10 | 6,706 | 2/21/2016 |
1.1.0 | 1,374 | 2/20/2016 |
1.0.16 | 1,683 | 2/18/2016 |
1.0.15 | 1,784 | 2/11/2016 |
1.0.14 | 1,369 | 1/28/2016 |
1.0.12 | 1,613 | 1/26/2016 |
1.0.11 | 1,293 | 1/26/2016 |
1.0.10 | 1,310 | 1/19/2016 |
1.0.9 | 1,306 | 1/19/2016 |
1.0.7 | 1,313 | 1/8/2016 |
1.0.6 | 1,392 | 12/8/2015 |
1.0.5 | 1,423 | 12/8/2015 |
1.0.4 | 1,274 | 12/8/2015 |
1.0.3 | 1,341 | 12/8/2015 |