This commit is contained in:
neuecc 2017-09-08 15:18:40 +09:00
Родитель 5508adc2b2
Коммит 06ea365088
6 изменённых файлов: 525 добавлений и 0 удалений

Просмотреть файл

@ -53,6 +53,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.AspNetCoreMvcFo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfBenchmarkDotNet", "sandbox\PerfBenchmarkDotNet\PerfBenchmarkDotNet.csproj", "{814F94D6-1413-4ACB-B1B5-A3488CAA1E6B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestData2", "sandbox\TestData2\TestData2.csproj", "{2A32A538-BA26-4D89-85D0-E4249AFA0837}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -231,6 +233,18 @@ Global
{814F94D6-1413-4ACB-B1B5-A3488CAA1E6B}.Release|x64.Build.0 = Release|Any CPU
{814F94D6-1413-4ACB-B1B5-A3488CAA1E6B}.Release|x86.ActiveCfg = Release|Any CPU
{814F94D6-1413-4ACB-B1B5-A3488CAA1E6B}.Release|x86.Build.0 = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|x64.ActiveCfg = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|x64.Build.0 = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|x86.ActiveCfg = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Debug|x86.Build.0 = Debug|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|Any CPU.Build.0 = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|x64.ActiveCfg = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|x64.Build.0 = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|x86.ActiveCfg = Release|Any CPU
{2A32A538-BA26-4D89-85D0-E4249AFA0837}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -250,5 +264,6 @@ Global
{014A3DCE-50A6-4774-A4C1-C66EEAB67133} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
{17831017-C29C-4A48-B159-849BCE5079FB} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{814F94D6-1413-4ACB-B1B5-A3488CAA1E6B} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
{2A32A538-BA26-4D89-85D0-E4249AFA0837} = {BF4C4202-5015-4FBD-80E6-D0F36A06F700}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,18 @@
using MessagePack;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestData2
{
[MessagePackObject(true)]
public class A { public int a; public List<B> bs; public C c; }
[MessagePackObject(true)]
public class B { public List<A> ass; public C c; public int a; }
[MessagePackObject(true)]
public class C { public B b; public int a; }
}

Просмотреть файл

@ -0,0 +1,390 @@
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168
namespace MessagePack.Resolvers
{
using System;
using MessagePack;
public class GeneratedResolver : global::MessagePack.IFormatterResolver
{
public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver();
GeneratedResolver()
{
}
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>()
{
return FormatterCache<T>.formatter;
}
static class FormatterCache<T>
{
public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter;
static FormatterCache()
{
var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T));
if (f != null)
{
formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f;
}
}
}
}
internal static class GeneratedResolverGetFormatterHelper
{
static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup;
static GeneratedResolverGetFormatterHelper()
{
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(5)
{
{typeof(global::System.Collections.Generic.List<global::TestData2.A>), 0 },
{typeof(global::System.Collections.Generic.List<global::TestData2.B>), 1 },
{typeof(global::TestData2.C), 2 },
{typeof(global::TestData2.B), 3 },
{typeof(global::TestData2.A), 4 },
};
}
internal static object GetFormatter(Type t)
{
int key;
if (!lookup.TryGetValue(t, out key)) return null;
switch (key)
{
case 0: return new global::MessagePack.Formatters.ListFormatter<global::TestData2.A>();
case 1: return new global::MessagePack.Formatters.ListFormatter<global::TestData2.B>();
case 2: return new MessagePack.Formatters.TestData2.CFormatter();
case 3: return new MessagePack.Formatters.TestData2.BFormatter();
case 4: return new MessagePack.Formatters.TestData2.AFormatter();
default: return null;
}
}
}
}
#pragma warning disable 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612
#pragma warning disable 618
#pragma warning disable 612
#pragma warning disable 414
#pragma warning disable 168
namespace MessagePack.Formatters.TestData2
{
using System;
using MessagePack;
public sealed class CFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.C>
{
readonly global::MessagePack.Internal.AutomataDictionary ____keyMapping;
readonly byte[][] ____stringByteKeys;
public CFormatter()
{
this.____keyMapping = new global::MessagePack.Internal.AutomataDictionary()
{
{ "b", 0},
{ "a", 1},
};
this.____stringByteKeys = new byte[][]
{
global::System.Text.Encoding.UTF8.GetBytes("b"),
global::System.Text.Encoding.UTF8.GetBytes("a"),
};
}
public int Serialize(ref byte[] bytes, int offset, global::TestData2.C value, global::MessagePack.IFormatterResolver formatterResolver)
{
if (value == null)
{
return global::MessagePack.MessagePackBinary.WriteNil(ref bytes, offset);
}
var startOffset = offset;
offset += global::MessagePack.MessagePackBinary.WriteFixedMapHeaderUnsafe(ref bytes, offset, 2);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[0]);
offset += formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Serialize(ref bytes, offset, value.b, formatterResolver);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[1]);
offset += MessagePackBinary.WriteInt32(ref bytes, offset, value.a);
return offset - startOffset;
}
public global::TestData2.C Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
{
if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return null;
}
var startOffset = offset;
var length = global::MessagePack.MessagePackBinary.ReadMapHeader(bytes, offset, out readSize);
offset += readSize;
var __b__ = default(global::TestData2.B);
var __a__ = default(int);
for (int i = 0; i < length; i++)
{
var stringKey = global::MessagePack.MessagePackBinary.ReadStringSegment(bytes, offset, out readSize);
offset += readSize;
int key;
if (!____keyMapping.TryGetValueSafe(stringKey, out key))
{
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
goto NEXT_LOOP;
}
switch (key)
{
case 0:
__b__ = formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Deserialize(bytes, offset, formatterResolver, out readSize);
break;
case 1:
__a__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
break;
default:
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
break;
}
NEXT_LOOP:
offset += readSize;
}
readSize = offset - startOffset;
var ____result = new global::TestData2.C();
____result.b = __b__;
____result.a = __a__;
return ____result;
}
}
public sealed class BFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.B>
{
readonly global::MessagePack.Internal.AutomataDictionary ____keyMapping;
readonly byte[][] ____stringByteKeys;
public BFormatter()
{
this.____keyMapping = new global::MessagePack.Internal.AutomataDictionary()
{
{ "ass", 0},
{ "c", 1},
{ "a", 2},
};
this.____stringByteKeys = new byte[][]
{
global::System.Text.Encoding.UTF8.GetBytes("ass"),
global::System.Text.Encoding.UTF8.GetBytes("c"),
global::System.Text.Encoding.UTF8.GetBytes("a"),
};
}
public int Serialize(ref byte[] bytes, int offset, global::TestData2.B value, global::MessagePack.IFormatterResolver formatterResolver)
{
if (value == null)
{
return global::MessagePack.MessagePackBinary.WriteNil(ref bytes, offset);
}
var startOffset = offset;
offset += global::MessagePack.MessagePackBinary.WriteFixedMapHeaderUnsafe(ref bytes, offset, 3);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[0]);
offset += formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Serialize(ref bytes, offset, value.ass, formatterResolver);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[1]);
offset += formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Serialize(ref bytes, offset, value.c, formatterResolver);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[2]);
offset += MessagePackBinary.WriteInt32(ref bytes, offset, value.a);
return offset - startOffset;
}
public global::TestData2.B Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
{
if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return null;
}
var startOffset = offset;
var length = global::MessagePack.MessagePackBinary.ReadMapHeader(bytes, offset, out readSize);
offset += readSize;
var __ass__ = default(global::System.Collections.Generic.List<global::TestData2.A>);
var __c__ = default(global::TestData2.C);
var __a__ = default(int);
for (int i = 0; i < length; i++)
{
var stringKey = global::MessagePack.MessagePackBinary.ReadStringSegment(bytes, offset, out readSize);
offset += readSize;
int key;
if (!____keyMapping.TryGetValueSafe(stringKey, out key))
{
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
goto NEXT_LOOP;
}
switch (key)
{
case 0:
__ass__ = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Deserialize(bytes, offset, formatterResolver, out readSize);
break;
case 1:
__c__ = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(bytes, offset, formatterResolver, out readSize);
break;
case 2:
__a__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
break;
default:
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
break;
}
NEXT_LOOP:
offset += readSize;
}
readSize = offset - startOffset;
var ____result = new global::TestData2.B();
____result.ass = __ass__;
____result.c = __c__;
____result.a = __a__;
return ____result;
}
}
public sealed class AFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.A>
{
readonly global::MessagePack.Internal.AutomataDictionary ____keyMapping;
readonly byte[][] ____stringByteKeys;
public AFormatter()
{
this.____keyMapping = new global::MessagePack.Internal.AutomataDictionary()
{
{ "a", 0},
{ "bs", 1},
{ "c", 2},
};
this.____stringByteKeys = new byte[][]
{
global::System.Text.Encoding.UTF8.GetBytes("a"),
global::System.Text.Encoding.UTF8.GetBytes("bs"),
global::System.Text.Encoding.UTF8.GetBytes("c"),
};
}
public int Serialize(ref byte[] bytes, int offset, global::TestData2.A value, global::MessagePack.IFormatterResolver formatterResolver)
{
if (value == null)
{
return global::MessagePack.MessagePackBinary.WriteNil(ref bytes, offset);
}
var startOffset = offset;
offset += global::MessagePack.MessagePackBinary.WriteFixedMapHeaderUnsafe(ref bytes, offset, 3);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[0]);
offset += MessagePackBinary.WriteInt32(ref bytes, offset, value.a);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[1]);
offset += formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Serialize(ref bytes, offset, value.bs, formatterResolver);
offset += global::MessagePack.MessagePackBinary.WriteStringBytes(ref bytes, offset, this.____stringByteKeys[2]);
offset += formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Serialize(ref bytes, offset, value.c, formatterResolver);
return offset - startOffset;
}
public global::TestData2.A Deserialize(byte[] bytes, int offset, global::MessagePack.IFormatterResolver formatterResolver, out int readSize)
{
if (global::MessagePack.MessagePackBinary.IsNil(bytes, offset))
{
readSize = 1;
return null;
}
var startOffset = offset;
var length = global::MessagePack.MessagePackBinary.ReadMapHeader(bytes, offset, out readSize);
offset += readSize;
var __a__ = default(int);
var __bs__ = default(global::System.Collections.Generic.List<global::TestData2.B>);
var __c__ = default(global::TestData2.C);
for (int i = 0; i < length; i++)
{
var stringKey = global::MessagePack.MessagePackBinary.ReadStringSegment(bytes, offset, out readSize);
offset += readSize;
int key;
if (!____keyMapping.TryGetValueSafe(stringKey, out key))
{
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
goto NEXT_LOOP;
}
switch (key)
{
case 0:
__a__ = MessagePackBinary.ReadInt32(bytes, offset, out readSize);
break;
case 1:
__bs__ = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Deserialize(bytes, offset, formatterResolver, out readSize);
break;
case 2:
__c__ = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(bytes, offset, formatterResolver, out readSize);
break;
default:
readSize = global::MessagePack.MessagePackBinary.ReadNextBlock(bytes, offset);
break;
}
NEXT_LOOP:
offset += readSize;
}
readSize = offset - startOffset;
var ____result = new global::TestData2.A();
____result.a = __a__;
____result.bs = __bs__;
____result.c = __c__;
return ____result;
}
}
}
#pragma warning disable 168
#pragma warning restore 414
#pragma warning restore 618
#pragma warning restore 612

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("TestData2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestData2")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は、
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]
// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
[assembly: Guid("2a32a538-ba26-4d89-85d0-e4249afa0837")]
// アセンブリのバージョン情報は次の 4 つの値で構成されています:
//
// メジャー バージョン
// マイナー バージョン
// ビルド番号
// Revision
//
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 以下のように '*' を使用します:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Просмотреть файл

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2A32A538-BA26-4D89-85D0-E4249AFA0837}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestData2</RootNamespace>
<AssemblyName>TestData2</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="MessagePack, Version=1.6.1.0, Culture=neutral, PublicKeyToken=b4a0369545f0a1be, processorArchitecture=MSIL">
<HintPath>..\..\packages\MessagePack.1.6.1\lib\net45\MessagePack.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Threading.Tasks.Extensions.4.3.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Generated.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MessagePack" version="1.6.1" targetFramework="net461" />
<package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net461" />
</packages>