Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/msgpack/msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
https://github.com/msgpack/msgpack-cli

c-sharp messagepack msgpack serialization

Last synced: about 1 month ago
JSON representation

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]

Lists

README

        

# MessagePack for CLI

## CI Status

|**Configuration**|**Status**|
|:--|:--|
|Release |[![Build status release](https://ci.appveyor.com/api/projects/status/5ln7u7efwjepj6o8?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-x2p85)|
|Debug (.NET Core 2.0) |[![Build status debug (.NET Core 2.0)](https://ci.appveyor.com/api/projects/status/dlc0v4rrolwj0t2t?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli)|
|Debug (.NET Core 2.0) |[![Build status debug (.NET Core 1.0)](https://ci.appveyor.com/api/projects/status/avurf519all92v5u?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-g3guk)|
|Debug (.NET Framework 4.x) |[![Build status debug (.NET Framework 4.x)](https://ci.appveyor.com/api/projects/status/np6723q2uiqofr1a?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-nuf62)|
|Debug (Code DOM)] |[![Build status debug (Code DOM)](https://ci.appveyor.com/api/projects/status/1mw78wkxx50jvab1?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-rhnh0)|
|Debug (miscs)] |[![Build status debug (miscs)](https://ci.appveyor.com/api/projects/status/avufc51yu2cm6idw?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-bo856)|
|Debug (.NET Framework 3.5) |[![Build status debug (.NET Framework 3.5)](https://ci.appveyor.com/api/projects/status/cjp8phlnbwj7gkj9?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-3jme9)|
|Debug (.NET Framework 3.5 Code DOM) |[![Build status debug (.NET Framework 3.5 Code DOM)](https://ci.appveyor.com/api/projects/status/1mw78wkxx50jvab1?svg=true)](https://ci.appveyor.com/project/yfakariya/msgpack-cli-rhnh0)|

## What is it?

This is MessagePack serialization/deserialization for CLI (Common Language Infrastructure) implementations such as .NET Framework, Silverlight, Mono (including Moonlight.)
This library can be used from ALL CLS compliant languages such as C#, F#, Visual Basic, Iron Python, Iron Ruby, PowerShell, C++/CLI or so.

## Usage

You can serialize/deserialize objects as following:

1. Create serializer via `MessagePackSerializer.Get` generic method. This method creates dependent types serializers as well.
2. Invoke serializer as following:
* `Pack` method with destination `Stream` and target object for serialization.
* `Unpack` method with source `Stream`.

```c#
// Creates serializer.
var serializer = MessagePackSerializer.Get();
// Pack obj to stream.
serializer.Pack(stream, obj);
// Unpack from stream.
var unpackedObject = serializer.Unpack(stream);
```

```vb
' Creates serializer.
Dim serializer = MessagePackSerializer.Get(Of T)()
' Pack obj to stream.
serializer.Pack(stream, obj)
' Unpack from stream.
Dim unpackedObject = serializer.Unpack(stream)
```

**For production environment, you should instantiate own `SerializationContext` and manage its lifetime. It is good idea to treat it as singleton because `SerializationContext` is thread-safe.**

## Features

* Fast and interoperable binary format serialization with simple API.
* Generating pre-compiled assembly for rapid start up.
* Flexible MessagePackObject which represents MessagePack type system naturally.

**Note: AOT support is limited yet. Use [serializer pre-generation](https://github.com/msgpack/msgpack-cli/wiki/Xamarin-and-Unity) with `mpu -s` utility or API.**
If you do not pre-generated serializers, MsgPack for CLI uses reflection in AOT environments, it is slower and it sometimes causes AOT related error (`ExecutionEngineException` for runtime JIT compilation). **You also have to call `MessagePackSerializer.PrepareType` and companions in advance to avoid AOT related error.** See [wiki](https://github.com/msgpack/msgpack-cli/wiki/Xamarin-and-Unity) for details.

## Documentation

See [wiki](https://github.com/msgpack/msgpack-cli/wiki)

## Installation

* Binary files distributed via the NuGet package [MsgPack.Cli](http://www.nuget.org/packages/MsgPack.Cli/).
* You can extract binary (DLL) file as following:
1. Download *.zip file from [GitHub Release page](https://github.com/msgpack/msgpack-cli/releases/).
2. Extract it.
3. Under the `bin` directory, binaries are there!
* For mono, you can use `net461` or `net35` drops as you run with.
* For Unity, `unity3d` drop is suitable.

## How to build

### For .NET Framework

1. Install Visual Studio 2017 (Community edition is OK) and 2015 (for MsgPack.Windows.sln).
* You must install .NET Framework 3.5, 4.x, .NET Core, and Xamarin dev tools to build all builds successfully.
If you do not want to install options, edit `` element in `*.csproj` files to exclude platforms you want to exclude.
2. Install latest .NET Core SDK.
3. Run with Visual Studio Developer Command Prompt:

msbuild MsgPack.sln /t:Restore
msbuild MsgPack.sln

Or (for Unity 3D drops):

msbuild MsgPack.compats.sln /t:Restore
msbuild MsgPack.compats.sln

Or (for Windows Runtime/Phone drops and Silverlight 5 drops):

msbuild MsgPack.Windows.sln /t:Restore
msbuild MsgPack.Windows.sln

Or (for Xamarin unit testing, you must have Xamarin Business or upper license and Mac machine on the LAN to build on Windows):

msbuild MsgPack.Xamarin.sln /t:Restore
msbuild MsgPack.Xamarin.sln

Or open one of above solution files in your IDE and run build command in it.

### For Mono

1. Install latest Mono and .NET Core SDK.
2. Now, you can build MsgPack.sln and MsgPack.Xamarin.sln with above instructions and `msbuild` in latest Mono. Note that `xbuild` does not work because it does not support latest csproj format.

### Own Unity 3D Build

First of all, there are binary drops on github release page, you should use it to save your time.
Because we will not guarantee source code organization compatibilities, we might add/remove non-public types or members, which should break source code build.
If you want to import sources, you must include just only described on MsgPack.Unity3D.csproj.
If you want to use ".NET 2.0 Subset" settings, you must use just only described on MsgPack.Unity3D.CorLibOnly.csproj file, and define `CORLIB_ONLY` compiler constants.

### Xamarin Android testing

If you run on Windows, it is recommended to use HXM instead of Hyper-V based emulator.
You can disable Hyper-V from priviledged (administrator) powershell as follows:

```powershell
Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor
```

If you want to use Hyper-V again (such as for Docker for Windows etc.), you can do it by following in priviledged (administrator) powershell:

```powershell
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor
```

#### Xamarin Android Trouble shooting tips

* **Q:** Javac shows compilation error.
* **A:** Rebuild the test project and try it run again.

### Xamarin iOS testing

You must create provisoning profiles in your MacOS devices.
See [Xamarin documents about provisining](https://developer.xamarin.com/guides/ios/getting_started/installation/device_provisioning/free-provisioning/) for details.

There are bundle IDs of current iOS tests:

* `org.msgpack.msgpack-cli-xamarin-ios-test`
* `org.msgpack.msgpack-cli-xamarin-ios-test-packer`
* `org.msgpack.msgpack-cli-xamarin-ios-test-unpacker`
* `org.msgpack.msgpack-cli-xamarin-ios-test-unpacking`
* `org.msgpack.msgpack-cli-xamarin-ios-test-timestamp`
* `org.msgpack.msgpack-cli-xamarin-ios-test-arrayserialization`
* `org.msgpack.msgpack-cli-xamarin-ios-test-mapserialization`

*Note that some reflection based serializer tests failed with AOT related limitation.*

#### Xamarin iOS Trouble shooting tips

See [Xamarin's official trouble shooting docs first.](https://developer.xamarin.com/guides/ios/getting_started/installation/windows/connecting-to-mac/troubleshooting/)

* **Q:** An error occurred while running unit test project.
* **A:** Rebuild the project and rerun it. Or, login your Mac again, ant retry it.
* **Q:** It is hard to read English.
* **A:** You can read localized Xamarin docs with putting `{region}-{lang}` as the first component of URL path such as `https://developer.xamarin.com/ja-jp/guides/...`.

## Maintenance

### MsgPack.Windows.sln

This solution contains Silverlight5 and (old) UWP project for backward compability. They are required Visual Studio 2015 to build and test.
You can download Visual Studio 2015 community edition from [here](https://visualstudio.microsoft.com/vs/older-downloads/).

**You do not have to install Visual Studio 2015 as long as you don't edit/test/build Silverlight and/or old UWP project.**

## See also

* GitHub Page : http://cli.msgpack.org/
* Wiki (documentation) : https://github.com/msgpack/msgpack-cli/wiki
* API Reference : http://cli.msgpack.org/doc/top.html
* Issue tracker : https://github.com/msgpack/msgpack-cli/issues
* MSBuild reference : http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx
* Mono xbuild reference : http://www.mono-project.com/Microsoft.Build