Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into support-record
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Nov 12, 2020
2 parents f2b42ec + e03f2aa commit 433774b
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 6 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ MessagePack has a compact binary size and a full set of general purpose expressi
- [Be careful when copying buffers](#be-careful-when-copying-buffers)
- [Choosing compression](#choosing-compression)
- [Extensions](#extensions)
- [Experimental Features](#experimental-features)
- [High-Level API (`MessagePackSerializer`)](#high-level-api-messagepackserializer)
- [Multiple MessagePack structures on a single `Stream`](#multiple-messagepack-structures-on-a-single-stream)
- [Low-Level API (`IMessagePackFormatter<T>`)](#low-level-api-imessagepackformattert)
Expand Down Expand Up @@ -993,6 +994,16 @@ You can make your own extension serializers or integrate with frameworks. Let's
* [WebApiContrib.Core.Formatter.MessagePack](https://github.com/WebApiContrib/WebAPIContrib.Core#formatters) - supports ASP.NET Core MVC ([details in blog post](https://www.strathweb.com/2017/06/using-messagepack-with-asp-net-core-mvc/))
* [MessagePack.MediaTypeFormatter](https://github.com/sketch7/MessagePack.MediaTypeFormatter) - MessagePack MediaTypeFormatter

## Experimental Features

MessagePack for C# has experimental features which provides you with very performant formatters. There is an official package.

```ps1
Install-Package MessagePack.Experimental
```

For detailed information, see: [Experimental.md](src/MessagePack.Experimental/Experimental.md)

# API

## High-Level API (`MessagePackSerializer`)
Expand Down
11 changes: 11 additions & 0 deletions src/MessagePack.Experimental/Experimental.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# MessagePack.Experimental

This C# project is the experimental project for the features which are very complex, unstable or unsafe.

- [HardwareIntrinsics](HardwareIntrinsics/HardwareIntrinsics.md)
- [UnsafeUnmanagedStructFormatter](UnsafeUnmanagedStructFormatter/UnsafeUnmanagedStructFormatter.md)

**Caution!**

`MessagePack.Experimental` only targets `.NET Core 3.1` and above.
You can not use this in Unity and .NET Framework.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Abstract

`Hardware Intrinsics` is a feature in order to utilize maximum power of the cpu.
You can serialize/deserialize primitive type array much faster than current implementation!

Supported types

- `sbyte[]`
- `short[]`
- `int[]`
- `bool[]`
- `float[]`
- `double[]`

# Usage

```csharp
var resolver = MessagePack.Resolvers.CompositeResolver.Create(new[] { PrimitiveArrayResolver.Instance, MessagePack.Resolvers.StandardResolver.Instance });
```

# When will this feature become official?

- The MessagePack-CSharp's lowest target framework is greater or equals to `.NET Core 3.1`.
- The current very complex and hard to understand implementation is rewritten.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Abstract

`UnsafeUnmanagedStructFormatter`s (de)serialize the blittable value(s) directly.
They are very performant but unstable against the endian.

You should be careful not to share the encoded byte[] among the different endian environments.

Supported types (T where T : unamanaged)

- `T``UnsafeUnmanagedStructFormatter<T>`
- `T[]``UnsafeUnmanagedStructArrayFormatter<T>`
- `Memory<T>``UnsafeUnmanagedStructMemoryFormatter<T>`
- `ReadOnlyMemory<T>``UnsafeUnmanagedStructReadOnlyMemoryFormatter<T>`
- `ReadOnlySequence<T>``UnsafeUnmanagedStructReadOnlySequenceFormatter<T>`

# Usage

```csharp
var resolver = MessagePack.Resolvers.CompositeResolver.Create(
new[] { new UnsafeUnmanagedStructFormatter<Matrix4x4>(typeCode: 96) },
new[] { MessagePack.Resolvers.StandardResolver.Instance });
```

The constructor takes 1 sbyte value.
The sbyte value is the extension type code embedded in serialized byte sequence.

# When will this feature become official?

- Requests are needed.
2 changes: 1 addition & 1 deletion src/MessagePack.Generator/MessagepackCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ await Host.CreateDefaultBuilder()
}

public async Task RunAsync(
[Option("i", "Input path of analyze MSBuild project file or directory, if input multiple project files split with ','.")] string input,
[Option("i", "Input path to MSBuild project file or the directory containing Unity source files.")] string input,
[Option("o", "Output file path(.cs) or directory (multiple generate file).")] string output,
[Option("c", "Conditional compiler symbols, split with ','. Ignored if a project file is specified for input.")] string? conditionalSymbol = null,
[Option("r", "Set resolver name.")] string resolverName = "GeneratedResolver",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private BigIntegerFormatter()

public void Serialize(ref MessagePackWriter writer, System.Numerics.BigInteger value, MessagePackSerializerOptions options)
{
#if NETCOREAPP2_1
#if NETCOREAPP
if (!writer.OldSpec)
{
// try to get bin8 buffer.
Expand Down Expand Up @@ -504,7 +504,7 @@ public void Serialize(ref MessagePackWriter writer, System.Numerics.BigInteger v
public System.Numerics.BigInteger Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options)
{
ReadOnlySequence<byte> bytes = reader.ReadBytes().Value;
#if NETCOREAPP2_1
#if NETCOREAPP
if (bytes.IsSingleSegment)
{
return new System.Numerics.BigInteger(bytes.First.Span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ private string ReadStringSlow(int byteLength)
int bytesRead = Math.Min(remainingByteLength, this.reader.UnreadSpan.Length);
remainingByteLength -= bytesRead;
bool flush = remainingByteLength == 0;
#if NETCOREAPP2_1
#if NETCOREAPP
initializedChars += decoder.GetChars(this.reader.UnreadSpan.Slice(0, bytesRead), charArray.AsSpan(initializedChars), flush);
#else
unsafe
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal static class StringEncoding
{
internal static readonly Encoding UTF8 = new UTF8Encoding(false);

#if !NETCOREAPP2_1 // Define the extension method only where an instance method does not already exist.
#if !NETCOREAPP // Define the extension method only where an instance method does not already exist.
internal static unsafe string GetString(this Encoding encoding, ReadOnlySpan<byte> bytes)
{
if (bytes.Length == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ async void OnGUI()
invokingMpc = true;
try
{
var log = await ProcessHelper.InvokeProcessStartAsync("mpc " + commnadLineArguments);
var log = await ProcessHelper.InvokeProcessStartAsync("mpc", commnadLineArguments);
UnityEngine.Debug.Log(log);
}
finally
Expand Down

0 comments on commit 433774b

Please sign in to comment.