commit d7a50b9d9a8de447a4dec61219fd584e862095a3
Merge: 02ae418 5a6cda6
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Mon Oct 26 09:33:45 2020 +0900

    Merge remote-tracking branch 'upstream/develop' into solution#1085-mpc

commit 02ae418a39cdd6d5bbdab7b900eb5169d80fa7e9
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Mon Oct 26 09:25:20 2020 +0900

    Update: Loop demonstration

commit d84ae759892b2ab9fc10d8d434902fca10ee88c1
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Mon Oct 26 09:24:31 2020 +0900

    Change: drop deserialized value -> reader.Skip()

commit 9b0d4a21a8824dc277a48ac63180e901b6f9890e
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Mon Oct 26 00:27:10 2020 +0900

    Fix: remove unused boolean local variables

commit fdfabeb2f1fc8b87bc41419fb0ccaee2c354b98a
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Mon Oct 26 00:00:28 2020 +0900

    Update: Make the same as Dynamic

commit bef4692e10cc47b137b7c647acb11feffb177206
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 19:37:11 2020 +0900

    Add test project

commit a8fac80ec561f476f122d35ad2cbcd831a955d41
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 18:55:27 2020 +0900

    Add types to sandbox

commit 6ffc3c309b6b47728e927799b574fc23b37fa2c8
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 18:45:40 2020 +0900

    Update: string-key mpc.exe

commit 44819e6d551961598c29fdab5aa0bf65d53ed0e6
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 18:05:24 2020 +0900

    Update: int-key mpc.exe

commit 0a2fef4d2f3ae7f568bd34a554792f006ec31275
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 12:12:57 2020 +0900

    Fix: var -> global::MessagePack.IFormatterResolver

commit 086aa11e7ce4fb0723014c8bda554104b3b38463
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 12:05:21 2020 +0900

    Fix: Line Feed

commit 39d3d0844848f1d742820e2786528baf2bd1627c
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 12:03:37 2020 +0900

    Fix: space

commit c57f423a49fed8e1c1b365310017a2ec382b5f07
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sun Oct 25 12:00:32 2020 +0900

    Change: var to globall::
    Revert: DepthStep position
    Revert: }#> -> } #>

commit de6fd239491b3fb7aa373644a384a71772d23b43
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sat Oct 24 11:04:44 2020 +0900

     fix CRLF

commit 4b6ae7c6089f7d6732691a0af7f1d93424ccaa95
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Sat Oct 24 10:59:50 2020 +0900

    Change the format to decrease template part lines.

    Change the iterator `i` type from `int` to `var`.

commit 95f41adff75a0ff605e760d5cdc485de10ee13be
Author: pCYSl5EDgo <pCYSl5EDgo@yahoo.co.jp>
Date:   Fri Oct 23 21:03:54 2020 +0900

    This is a cherry-pick of #1074.
    This is a refactoring of int-key mpc.exe tt file.
This commit is contained in:
pCYSl5EDgo 2020-10-27 20:27:47 +09:00
Родитель 5a6cda6f9f
Коммит 1fba6ccb57
11 изменённых файлов: 1223 добавлений и 997 удалений

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

@ -88,6 +88,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.Experimental",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MessagePack.Experimental.Tests", "tests\MessagePack.Experimental.Tests\MessagePack.Experimental.Tests.csproj", "{8AB40D1C-1134-4D77-B39A-19AEDC729450}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MessagePack.GeneratedCode.Tests", "tests\MessagePack.GeneratedCode.Tests\MessagePack.GeneratedCode.Tests.csproj", "{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -310,6 +312,14 @@ Global
{8AB40D1C-1134-4D77-B39A-19AEDC729450}.Release|Any CPU.Build.0 = Release|Any CPU
{8AB40D1C-1134-4D77-B39A-19AEDC729450}.Release|NoVSIX.ActiveCfg = Release|Any CPU
{8AB40D1C-1134-4D77-B39A-19AEDC729450}.Release|NoVSIX.Build.0 = Release|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Debug|NoVSIX.ActiveCfg = Debug|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Debug|NoVSIX.Build.0 = Debug|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Release|Any CPU.Build.0 = Release|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Release|NoVSIX.ActiveCfg = Release|Any CPU
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E}.Release|NoVSIX.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -342,6 +352,7 @@ Global
{4C9BB260-62D8-49CD-9F9C-9AA6A8BFC637} = {51A614B0-E583-4DD2-AC7D-6A65634582E0}
{AC2503A7-736D-4AE6-9355-CF35D9DF6139} = {86309CF6-0054-4CE3-BFD3-CA0AA7DB17BC}
{8AB40D1C-1134-4D77-B39A-19AEDC729450} = {19FE674A-AC94-4E7E-B24C-2285D1D04CDE}
{D4CE7347-CEBE-46E5-BD12-1319573B6C5E} = {19FE674A-AC94-4E7E-B24C-2285D1D04CDE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B3911209-2DBF-47F8-98F6-BBC0EDFE63DE}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -181,10 +181,8 @@ namespace MessagePack.Formatters.TestData2
namespace MessagePack.Formatters.TestData2
{
using System;
using System.Buffers;
using System.Runtime.InteropServices;
using MessagePack;
using global::System.Buffers;
using global::MessagePack;
public sealed class AFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.A>
{
@ -203,7 +201,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(3);
writer.WriteRaw(GetSpan_a());
writer.Write(value.a);
@ -221,15 +219,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __a__ = default(int);
var __bs__ = default(global::System.Collections.Generic.List<global::TestData2.B>);
var __c__ = default(global::TestData2.C);
var ____result = new global::TestData2.A();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -241,28 +237,21 @@ namespace MessagePack.Formatters.TestData2
{
default: goto FAIL;
case 97UL:
__a__ = reader.ReadInt32();
____result.a = reader.ReadInt32();
continue;
case 99UL:
__c__ = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
____result.c = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
continue;
}
case 2:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 29538UL) { goto FAIL; }
__bs__ = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Deserialize(ref reader, options);
____result.bs = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.B>>().Deserialize(ref reader, options);
continue;
}
}
var ____result = new global::TestData2.A()
{
a = __a__,
bs = __bs__,
c = __c__,
};
reader.Depth--;
return ____result;
}
@ -285,7 +274,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(3);
writer.WriteRaw(GetSpan_ass());
formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Serialize(ref writer, value.ass, options);
@ -303,15 +292,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __ass__ = default(global::System.Collections.Generic.List<global::TestData2.A>);
var __c__ = default(global::TestData2.C);
var __a__ = default(int);
var ____result = new global::TestData2.B();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -321,30 +308,23 @@ namespace MessagePack.Formatters.TestData2
case 3:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 7566177UL) { goto FAIL; }
__ass__ = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Deserialize(ref reader, options);
____result.ass = formatterResolver.GetFormatterWithVerify<global::System.Collections.Generic.List<global::TestData2.A>>().Deserialize(ref reader, options);
continue;
case 1:
switch (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey))
{
default: goto FAIL;
case 99UL:
__c__ = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
____result.c = formatterResolver.GetFormatterWithVerify<global::TestData2.C>().Deserialize(ref reader, options);
continue;
case 97UL:
__a__ = reader.ReadInt32();
____result.a = reader.ReadInt32();
continue;
}
}
}
var ____result = new global::TestData2.B()
{
ass = __ass__,
c = __c__,
a = __a__,
};
reader.Depth--;
return ____result;
}
@ -365,7 +345,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(2);
writer.WriteRaw(GetSpan_b());
formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Serialize(ref writer, value.b, options);
@ -381,14 +361,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __b__ = default(global::TestData2.B);
var __a__ = default(int);
var ____result = new global::TestData2.C();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -400,22 +379,16 @@ namespace MessagePack.Formatters.TestData2
{
default: goto FAIL;
case 98UL:
__b__ = formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Deserialize(ref reader, options);
____result.b = formatterResolver.GetFormatterWithVerify<global::TestData2.B>().Deserialize(ref reader, options);
continue;
case 97UL:
__a__ = reader.ReadInt32();
____result.a = reader.ReadInt32();
continue;
}
}
}
var ____result = new global::TestData2.C()
{
b = __b__,
a = __a__,
};
reader.Depth--;
return ____result;
}
@ -436,7 +409,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(2);
writer.WriteRaw(GetSpan_EnumId());
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.Id>().Serialize(ref writer, value.EnumId, options);
@ -452,14 +425,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __EnumId__ = default(global::TestData2.Nest1.Id);
var __ClassId__ = default(global::TestData2.Nest1.IdType);
var ____result = new global::TestData2.Nest1();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -469,23 +441,17 @@ namespace MessagePack.Formatters.TestData2
case 6:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 110266531802693UL) { goto FAIL; }
__EnumId__ = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.Id>().Deserialize(ref reader, options);
____result.EnumId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.Id>().Deserialize(ref reader, options);
continue;
case 7:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 28228257876896835UL) { goto FAIL; }
__ClassId__ = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.IdType>().Deserialize(ref reader, options);
____result.ClassId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest1.IdType>().Deserialize(ref reader, options);
continue;
}
}
var ____result = new global::TestData2.Nest1()
{
EnumId = __EnumId__,
ClassId = __ClassId__,
};
reader.Depth--;
return ____result;
}
@ -493,7 +459,6 @@ namespace MessagePack.Formatters.TestData2
public sealed class Nest1_IdTypeFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.Nest1.IdType>
{
public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::TestData2.Nest1.IdType value, global::MessagePack.MessagePackSerializerOptions options)
{
if (value is null)
@ -533,7 +498,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(2);
writer.WriteRaw(GetSpan_EnumId());
formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.Id>().Serialize(ref writer, value.EnumId, options);
@ -549,14 +514,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __EnumId__ = default(global::TestData2.Nest2.Id);
var __ClassId__ = default(global::TestData2.Nest2.IdType);
var ____result = new global::TestData2.Nest2();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -566,23 +530,17 @@ namespace MessagePack.Formatters.TestData2
case 6:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 110266531802693UL) { goto FAIL; }
__EnumId__ = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.Id>().Deserialize(ref reader, options);
____result.EnumId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.Id>().Deserialize(ref reader, options);
continue;
case 7:
if (global::MessagePack.Internal.AutomataKeyGen.GetKey(ref stringKey) != 28228257876896835UL) { goto FAIL; }
__ClassId__ = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.IdType>().Deserialize(ref reader, options);
____result.ClassId = formatterResolver.GetFormatterWithVerify<global::TestData2.Nest2.IdType>().Deserialize(ref reader, options);
continue;
}
}
var ____result = new global::TestData2.Nest2()
{
EnumId = __EnumId__,
ClassId = __ClassId__,
};
reader.Depth--;
return ____result;
}
@ -590,7 +548,6 @@ namespace MessagePack.Formatters.TestData2
public sealed class Nest2_IdTypeFormatter : global::MessagePack.Formatters.IMessagePackFormatter<global::TestData2.Nest2.IdType>
{
public void Serialize(ref global::MessagePack.MessagePackWriter writer, global::TestData2.Nest2.IdType value, global::MessagePack.MessagePackSerializerOptions options)
{
if (value is null)
@ -630,7 +587,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(2);
writer.WriteRaw(GetSpan_MyProperty1());
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty1, options);
@ -646,14 +603,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __MyProperty1__ = default(string);
var __MyProperty2__ = default(string);
var ____result = new global::TestData2.PropNameCheck1();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -669,10 +625,10 @@ namespace MessagePack.Formatters.TestData2
{
default: goto FAIL;
case 3242356UL:
__MyProperty1__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
____result.MyProperty1 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
continue;
case 3307892UL:
__MyProperty2__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
____result.MyProperty2 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
continue;
}
@ -681,12 +637,6 @@ namespace MessagePack.Formatters.TestData2
}
}
var ____result = new global::TestData2.PropNameCheck1()
{
MyProperty1 = __MyProperty1__,
MyProperty2 = __MyProperty2__,
};
reader.Depth--;
return ____result;
}
@ -707,7 +657,7 @@ namespace MessagePack.Formatters.TestData2
return;
}
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
writer.WriteMapHeader(2);
writer.WriteRaw(GetSpan_MyProperty1());
formatterResolver.GetFormatterWithVerify<string>().Serialize(ref writer, value.MyProperty1, options);
@ -723,14 +673,13 @@ namespace MessagePack.Formatters.TestData2
}
options.Security.DepthStep(ref reader);
IFormatterResolver formatterResolver = options.Resolver;
var formatterResolver = options.Resolver;
var length = reader.ReadMapHeader();
var __MyProperty1__ = default(string);
var __MyProperty2__ = default(string);
var ____result = new global::TestData2.PropNameCheck2();
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -746,10 +695,10 @@ namespace MessagePack.Formatters.TestData2
{
default: goto FAIL;
case 3242356UL:
__MyProperty1__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
____result.MyProperty1 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
continue;
case 3307892UL:
__MyProperty2__ = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
____result.MyProperty2 = formatterResolver.GetFormatterWithVerify<string>().Deserialize(ref reader, options);
continue;
}
@ -758,12 +707,6 @@ namespace MessagePack.Formatters.TestData2
}
}
var ____result = new global::TestData2.PropNameCheck2()
{
MyProperty1 = __MyProperty1__,
MyProperty2 = __MyProperty2__,
};
reader.Depth--;
return ____result;
}

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

@ -118,18 +118,30 @@ namespace ");
this.Write(" throw new global::System.InvalidOperationException(\"typecode is n" +
"ull, struct not supported\");\r\n");
}
this.Write(" }\r\n\r\n options.Security.DepthStep(ref reader);\r\n");
this.Write(" }\r\n\r\n");
if (objInfo.MaxKey == -1 && !objInfo.HasIMessagePackSerializationCallbackReceiver) {
this.Write(" reader.Skip();\r\n return new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write(";\r\n");
} else {
this.Write(" options.Security.DepthStep(ref reader);\r\n");
if (isFormatterResolverNecessary) {
this.Write(" global::MessagePack.IFormatterResolver formatterResolver = options.Re" +
"solver;\r\n");
}
this.Write(" var length = reader.ReadArrayHeader();\r\n");
foreach (var member in objInfo.Members) {
var canOverwrite = objInfo.ConstructorParameters.Length == 0;
if (canOverwrite) {
this.Write(" var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write(";\r\n");
} else { foreach (var member in objInfo.Members) {
this.Write(" var __");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__ = default(");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Type));
this.Write(");\r\n");
}
}
this.Write("\r\n for (int i = 0; i < length; i++)\r\n {\r\n sw" +
"itch (i)\r\n {\r\n");
@ -138,25 +150,51 @@ namespace ");
if (member == null) { continue; }
this.Write(" case ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.IntKey));
this.Write(":\r\n __");
this.Write(":\r\n");
if (canOverwrite) {
if (member.IsWritable) {
this.Write(" ____result.");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write(" = ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.GetDeserializeMethodString()));
this.Write(";\r\n");
} else {
this.Write(" ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.GetDeserializeMethodString()));
this.Write(";\r\n");
}
} else {
this.Write(" __");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__ = ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.GetDeserializeMethodString()));
this.Write(";\r\n break;\r\n");
this.Write(";\r\n");
}
this.Write(" break;\r\n");
}
this.Write(" default:\r\n reader.Skip();\r\n " +
" break;\r\n }\r\n }\r\n\r\n var ____res" +
"ult = new ");
" break;\r\n }\r\n }\r\n\r\n");
if (!canOverwrite) {
this.Write(" var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write(";\r\n");
for (var memberIndex = 0; memberIndex <= objInfo.MaxKey; memberIndex++) {
bool memberAssignExists = false;
for (var memberIndex = 0; memberIndex <= objInfo.MaxKey; memberIndex++) {
var member = objInfo.GetMember(memberIndex);
if (member == null || !member.IsWritable) { continue; }
this.Write(" ____result.");
if (member == null || !member.IsWritable || objInfo.ConstructorParameters.Any(p => p.Equals(member))) { continue; }
memberAssignExists = true;
this.Write(" if (length <= ");
this.Write(this.ToStringHelper.ToStringWithCulture(memberIndex));
this.Write(")\r\n {\r\n goto MEMBER_ASSIGNMENT_END;\r\n }\r\n\r\n " +
" ____result.");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write(" = __");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__;\r\n");
}
if (memberAssignExists) {
this.Write("\r\n MEMBER_ASSIGNMENT_END:\r\n");
}
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
@ -167,7 +205,9 @@ namespace ");
this.Write(" ____result.OnAfterDeserialize();\r\n");
}
}
this.Write(" reader.Depth--;\r\n return ____result;\r\n }\r\n }\r\n");
this.Write(" reader.Depth--;\r\n return ____result;\r\n");
}
this.Write(" }\r\n }\r\n");
}
this.Write(@"}

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

@ -81,13 +81,21 @@ namespace <#= Namespace #>
<# } #>
}
<# if (objInfo.MaxKey == -1 && !objInfo.HasIMessagePackSerializationCallbackReceiver) { #>
reader.Skip();
return new <#= objInfo.GetConstructorString() #>;
<# } else { #>
options.Security.DepthStep(ref reader);
<# if (isFormatterResolverNecessary) { #>
global::MessagePack.IFormatterResolver formatterResolver = options.Resolver;
<# } #>
var length = reader.ReadArrayHeader();
<# foreach (var member in objInfo.Members) { #>
<# var canOverwrite = objInfo.ConstructorParameters.Length == 0;
if (canOverwrite) { #>
var ____result = new <#= objInfo.GetConstructorString() #>;
<# } else { foreach (var member in objInfo.Members) { #>
var __<#= member.Name #>__ = default(<#= member.Type #>);
<# } #>
<# } #>
for (int i = 0; i < length; i++)
@ -98,7 +106,15 @@ namespace <#= Namespace #>
var member = objInfo.GetMember(memberIndex);
if (member == null) { continue; } #>
case <#= member.IntKey #>:
<# if (canOverwrite) {
if (member.IsWritable) { #>
____result.<#= member.Name #> = <#= member.GetDeserializeMethodString() #>;
<# } else { #>
<#= member.GetDeserializeMethodString() #>;
<# } #>
<# } else {#>
__<#= member.Name #>__ = <#= member.GetDeserializeMethodString() #>;
<# } #>
break;
<# } #>
default:
@ -107,12 +123,25 @@ namespace <#= Namespace #>
}
}
<# if (!canOverwrite) { #>
var ____result = new <#= objInfo.GetConstructorString() #>;
<# for (var memberIndex = 0; memberIndex <= objInfo.MaxKey; memberIndex++) {
<# bool memberAssignExists = false;
for (var memberIndex = 0; memberIndex <= objInfo.MaxKey; memberIndex++) {
var member = objInfo.GetMember(memberIndex);
if (member == null || !member.IsWritable) { continue; } #>
if (member == null || !member.IsWritable || objInfo.ConstructorParameters.Any(p => p.Equals(member))) { continue; }
memberAssignExists = true;#>
if (length <= <#= memberIndex #>)
{
goto MEMBER_ASSIGNMENT_END;
}
____result.<#= member.Name #> = __<#= member.Name #>__;
<# } #>
<# if (memberAssignExists) { #>
MEMBER_ASSIGNMENT_END:
<# }
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
if (objInfo.NeedsCastOnAfter) { #>
@ -123,6 +152,7 @@ namespace <#= Namespace #>
<# } #>
reader.Depth--;
return ____result;
<# } #>
}
}
<# } #>

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

@ -12,28 +12,67 @@ namespace MessagePackCompiler.Generator
{
internal static class StringKeyFormatterDeserializeHelper
{
public static string Classify(MemberSerializationInfo[] memberArray, string indent)
public static string Classify(ObjectSerializationInfo objectSerializationInfo, string indent, bool canOverwrite)
{
var memberArray = objectSerializationInfo.Members;
var buffer = new StringBuilder();
foreach (var memberInfoTuples in memberArray.Select(member => new MemberInfoTuple(member)).GroupBy(member => member.Binary.Length))
foreach (var memberInfoTuples in memberArray.Select(member => new MemberInfoTuple(member, IsConstructorParameter(objectSerializationInfo, member))).GroupBy(member => member.Binary.Length))
{
var binaryLength = memberInfoTuples.Key;
var keyLength = binaryLength >> 3;
keyLength += keyLength << 3 == binaryLength ? 0 : 1;
buffer.Append(indent).Append("case ").Append(binaryLength).Append(":\r\n");
ClassifyRecursion(buffer, indent, 1, keyLength, memberInfoTuples);
ClassifyRecursion(buffer, indent, 1, keyLength, memberInfoTuples, canOverwrite);
}
return buffer.ToString();
}
private static void Assign(StringBuilder buffer, in MemberInfoTuple member)
private static bool IsConstructorParameter(ObjectSerializationInfo objectSerializationInfo, MemberSerializationInfo member)
{
buffer.Append("__").Append(member.Info.Name).Append("__ = ").Append(member.Info.GetDeserializeMethodString()).Append(";\r\n");
foreach (var parameter in objectSerializationInfo.ConstructorParameters)
{
if (parameter.Equals(member))
{
return true;
}
}
return false;
}
private static void ClassifyRecursion(StringBuilder buffer, string indent, int tabCount, int keyLength, IEnumerable<MemberInfoTuple> memberCollection)
private static void Assign(StringBuilder buffer, in MemberInfoTuple member, bool canOverwrite, string indent, string tab, int tabCount)
{
if (member.Info.IsWritable)
{
if (canOverwrite)
{
buffer.Append("____result.").Append(member.Info.Name).Append(" = ");
}
else
{
if (!member.IsConstructorParameter)
{
buffer.Append("__").Append(member.Info.Name).Append("__IsInitialized = true;\r\n").Append(indent);
for (var i = 0; i < tabCount; i++)
{
buffer.Append(tab);
}
}
buffer.Append("__").Append(member.Info.Name).Append("__ = ");
}
buffer.Append(member.Info.GetDeserializeMethodString()).Append(";\r\n");
}
else
{
buffer.Append("reader.Skip();\r\n");
}
}
private static void ClassifyRecursion(StringBuilder buffer, string indent, int tabCount, int keyLength, IEnumerable<MemberInfoTuple> memberCollection, bool canOverwrite)
{
const string Tab = " ";
buffer.Append(indent);
@ -46,7 +85,7 @@ namespace MessagePackCompiler.Generator
if (memberArray.Length == 1)
{
var member = memberArray[0];
EmbedOne(buffer, indent, tabCount, member);
EmbedOne(buffer, indent, tabCount, member, canOverwrite);
return;
}
@ -83,7 +122,7 @@ namespace MessagePackCompiler.Generator
}
var member = grouping.Single();
Assign(buffer, member);
Assign(buffer, member, canOverwrite, indent, Tab, tabCount + 2);
buffer.Append(Tab + Tab).Append(indent);
for (var i = 0; i < tabCount; i++)
{
@ -94,7 +133,7 @@ namespace MessagePackCompiler.Generator
continue;
}
ClassifyRecursion(buffer, indent + Tab, tabCount + 1, keyLength, grouping);
ClassifyRecursion(buffer, indent + Tab, tabCount + 1, keyLength, grouping, canOverwrite);
}
buffer.Append("\r\n").Append(indent);
@ -106,7 +145,7 @@ namespace MessagePackCompiler.Generator
buffer.Append("}\r\n");
}
private static void EmbedOne(StringBuilder buffer, string indent, int tabCount, in MemberInfoTuple member)
private static void EmbedOne(StringBuilder buffer, string indent, int tabCount, in MemberInfoTuple member, bool canOverwrite)
{
const string Tab = " ";
var binary = member.Binary.AsSpan((tabCount - 1) << 3);
@ -136,7 +175,7 @@ namespace MessagePackCompiler.Generator
buffer.Append(Tab);
}
Assign(buffer, member);
Assign(buffer, member, canOverwrite, indent, Tab, tabCount);
buffer.Append(indent);
for (var i = 0; i < tabCount; i++)
{
@ -166,12 +205,14 @@ namespace MessagePackCompiler.Generator
internal readonly struct MemberInfoTuple : IComparable<MemberInfoTuple>
{
public readonly MemberSerializationInfo Info;
public readonly bool IsConstructorParameter;
public readonly byte[] Binary;
public readonly ulong[] Key;
public MemberInfoTuple(MemberSerializationInfo info)
public MemberInfoTuple(MemberSerializationInfo info, bool isConstructorParameter)
{
Info = info;
IsConstructorParameter = isConstructorParameter;
Binary = EmbedStringHelper.Utf8.GetBytes(info.StringKey);
ReadOnlySpan<byte> span = Binary;
var keyLength = Binary.Length >> 3;

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

@ -43,22 +43,17 @@ namespace MessagePackCompiler.Generator
namespace ");
this.Write(this.ToStringHelper.ToStringWithCulture(Namespace));
this.Write("\r\n{\r\n using System;\r\n using System.Buffers;\r\n using System.Runtime.Inter" +
"opServices;\r\n using MessagePack;\r\n");
var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos)
{
this.Write("\r\n{\r\n using global::System.Buffers;\r\n using global::MessagePack;\r\n");
var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos) {
list.Clear();
foreach (var member in objInfo.Members)
{
foreach (var member in objInfo.Members) {
var binary = EmbedStringHelper.Utf8.GetBytes(member.StringKey);
list.Add(new ValueTuple<MemberSerializationInfo, byte[]>(member, binary));
}
string formatterName = objInfo.Name + (objInfo.IsOpenGenericType ? $"Formatter<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : "Formatter");
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);
this.Write("\r\n public sealed class ");
this.Write(this.ToStringHelper.ToStringWithCulture(formatterName));
this.Write(" : global::MessagePack.Formatters.IMessagePackFormatter<");
@ -72,12 +67,9 @@ foreach (var objInfo in ObjectSerializationInfos)
this.Write("\r\n");
}
this.Write(" {\r\n");
foreach (var memberAndBinary in list)
{
var member = memberAndBinary.Item1;
var binary = memberAndBinary.Item2;
for (var i = 0; i < list.Count; i++) {
var member = list[i].Item1;
var binary = list[i].Item2;
this.Write(" // ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.StringKey));
this.Write("\r\n private static global::System.ReadOnlySpan<byte> GetSpan_");
@ -85,121 +77,86 @@ foreach (var objInfo in ObjectSerializationInfos)
this.Write("() => ");
this.Write(this.ToStringHelper.ToStringWithCulture(EmbedStringHelper.ToByteArrayString(binary)));
this.Write(";\r\n");
}
this.Write("\r\n public void Serialize(ref global::MessagePack.MessagePackWriter writer," +
" ");
}
if (list.Count != 0) {
this.Write("\r\n");
}
this.Write(" public void Serialize(ref global::MessagePack.MessagePackWriter writer, ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
this.Write(" value, global::MessagePack.MessagePackSerializerOptions options)\r\n {\r\n");
if (objInfo.IsClass)
{
if (objInfo.IsClass) {
this.Write(" if (value is null)\r\n {\r\n writer.WriteNil();" +
"\r\n return;\r\n }\r\n\r\n");
}
}
if (isFormatterResolverNecessary)
{
this.Write(" IFormatterResolver formatterResolver = options.Resolver;\r\n");
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver)
{
if (objInfo.NeedsCastOnBefore)
{
if (isFormatterResolverNecessary) {
this.Write(" var formatterResolver = options.Resolver;\r\n");
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
if (objInfo.NeedsCastOnBefore) {
this.Write(" ((global::MessagePack.IMessagePackSerializationCallbackReceiver)value" +
").OnBeforeSerialize();\r\n");
}
else
{
} else {
this.Write(" value.OnBeforeSerialize();\r\n");
}
}
}
}
this.Write(" writer.WriteMapHeader(");
this.Write(this.ToStringHelper.ToStringWithCulture(list.Count));
this.Write(");\r\n");
foreach (var memberAndBinary in list)
{
var member = memberAndBinary.Item1;
foreach (var memberAndBinary in list) {
var member = memberAndBinary.Item1;
this.Write(" writer.WriteRaw(GetSpan_");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("());\r\n ");
this.Write(this.ToStringHelper.ToStringWithCulture(member.GetSerializeMethodString()));
this.Write(";\r\n");
}
}
this.Write(" }\r\n\r\n public ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.FullName));
this.Write(" Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePac" +
"k.MessagePackSerializerOptions options)\r\n {\r\n if (reader.TryRe" +
"adNil())\r\n {\r\n");
if (objInfo.IsClass)
{
if (objInfo.IsClass) {
this.Write(" return null;\r\n");
}
else
{
} else {
this.Write(" throw new global::System.InvalidOperationException(\"typecode is n" +
"ull, struct not supported\");\r\n");
}
}
this.Write(" }\r\n\r\n");
if (objInfo.Members.Length == 0)
{
if (objInfo.Members.Length == 0) {
this.Write(" reader.Skip();\r\n var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write(";\r\n");
}
else
{
} else {
this.Write(" options.Security.DepthStep(ref reader);\r\n");
if (isFormatterResolverNecessary)
{
this.Write(" IFormatterResolver formatterResolver = options.Resolver;\r\n");
}
if (isFormatterResolverNecessary) {
this.Write(" var formatterResolver = options.Resolver;\r\n");
}
this.Write(" var length = reader.ReadMapHeader();\r\n");
foreach (var memberInfo in objInfo.Members)
{
var canOverwrite = objInfo.ConstructorParameters.Length == 0;
if (canOverwrite) {
this.Write(" var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write(";\r\n");
} else {
foreach (var member in objInfo.Members.Where(x => x.IsWritable)) {
if (objInfo.ConstructorParameters.All(p => !p.Equals(member))) {
this.Write(" var __");
this.Write(this.ToStringHelper.ToStringWithCulture(memberInfo.Name));
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__IsInitialized = false;\r\n");
}
this.Write(" var __");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__ = default(");
this.Write(this.ToStringHelper.ToStringWithCulture(memberInfo.Type));
this.Write(this.ToStringHelper.ToStringWithCulture(member.Type));
this.Write(");\r\n");
}
}
}
this.Write(@"
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
@ -207,55 +164,36 @@ foreach (var objInfo in ObjectSerializationInfos)
reader.Skip();
continue;
");
this.Write(this.ToStringHelper.ToStringWithCulture(StringKeyFormatterDeserializeHelper.Classify(objInfo.Members, " ")));
this.Write("\r\n }\r\n }\r\n\r\n var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(StringKeyFormatterDeserializeHelper.Classify(objInfo, " ", canOverwrite)));
this.Write("\r\n }\r\n }\r\n\r\n");
if (!canOverwrite) {
this.Write(" var ____result = new ");
this.Write(this.ToStringHelper.ToStringWithCulture(objInfo.GetConstructorString()));
this.Write("\r\n {\r\n");
// Preparation for C#9 Record class
foreach (var member in objInfo.Members.Where(x => x.IsWritable))
{
this.Write(" ");
this.Write(";\r\n");
foreach (var member in objInfo.Members.Where(x => x.IsWritable && !objInfo.ConstructorParameters.Any(p => p.Equals(x)))) {
this.Write(" if (__");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__IsInitialized)\r\n {\r\n ____result.");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write(" = __");
this.Write(this.ToStringHelper.ToStringWithCulture(member.Name));
this.Write("__,\r\n");
}
this.Write(" };\r\n\r\n");
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver)
{
if (objInfo.NeedsCastOnAfter)
{
this.Write("__;\r\n }\r\n\r\n");
}
}
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
if (objInfo.NeedsCastOnAfter) {
this.Write(" ((global::MessagePack.IMessagePackSerializationCallbackReceiver)____r" +
"esult).OnAfterDeserialize();\r\n");
}
else
{
} else {
this.Write(" ____result.OnAfterDeserialize();\r\n");
}
}
if (objInfo.Members.Length != 0)
{
}
}
if (objInfo.Members.Length != 0) {
this.Write(" reader.Depth--;\r\n");
}
}
this.Write(" return ____result;\r\n }\r\n }\r\n");
}
}
this.Write("}\r\n");
return this.GenerationEnvironment.ToString();
}

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

@ -22,199 +22,131 @@
namespace <#= Namespace #>
{
using System;
using System.Buffers;
using System.Runtime.InteropServices;
using MessagePack;
<#
var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos)
{
using global::System.Buffers;
using global::MessagePack;
<# var list = new List<ValueTuple<MemberSerializationInfo, byte[]>>();
foreach (var objInfo in ObjectSerializationInfos) {
list.Clear();
foreach (var member in objInfo.Members)
{
foreach (var member in objInfo.Members) {
var binary = EmbedStringHelper.Utf8.GetBytes(member.StringKey);
list.Add(new ValueTuple<MemberSerializationInfo, byte[]>(member, binary));
}
string formatterName = objInfo.Name + (objInfo.IsOpenGenericType ? $"Formatter<{string.Join(", ", objInfo.GenericTypeParameters.Select(x => x.Name))}>" : "Formatter");
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members);
#>
bool isFormatterResolverNecessary = ShouldUseFormatterResolverHelper.ShouldUseFormatterResolver(objInfo.Members); #>
public sealed class <#= formatterName #> : global::MessagePack.Formatters.IMessagePackFormatter<<#= objInfo.FullName #>>
<# foreach (var typeArg in objInfo.GenericTypeParameters.Where(x => x.HasConstraints)) {#>
where <#= typeArg.Name #> : <#= typeArg.Constraints #>
<# }#>
{
<#
foreach (var memberAndBinary in list)
{
var member = memberAndBinary.Item1;
var binary = memberAndBinary.Item2;
#>
<# for (var i = 0; i < list.Count; i++) {
var member = list[i].Item1;
var binary = list[i].Item2; #>
// <#= member.StringKey #>
private static global::System.ReadOnlySpan<byte> GetSpan_<#= member.Name #>() => <#= EmbedStringHelper.ToByteArrayString(binary) #>;
<#
}
#>
<# } #>
<# if (list.Count != 0) { #>
<# } #>
public void Serialize(ref global::MessagePack.MessagePackWriter writer, <#= objInfo.FullName #> value, global::MessagePack.MessagePackSerializerOptions options)
{
<#
if (objInfo.IsClass)
{
#>
<# if (objInfo.IsClass) { #>
if (value is null)
{
writer.WriteNil();
return;
}
<#
}
<# }
if (isFormatterResolverNecessary)
{
#>
IFormatterResolver formatterResolver = options.Resolver;
<#
}
if (isFormatterResolverNecessary) { #>
var formatterResolver = options.Resolver;
<# }
if (objInfo.HasIMessagePackSerializationCallbackReceiver)
{
if (objInfo.NeedsCastOnBefore)
{
#>
if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
if (objInfo.NeedsCastOnBefore) { #>
((global::MessagePack.IMessagePackSerializationCallbackReceiver)value).OnBeforeSerialize();
<#
}
else
{
#>
<# } else { #>
value.OnBeforeSerialize();
<#
}
}
#>
<# } #>
<# } #>
writer.WriteMapHeader(<#= list.Count #>);
<#
foreach (var memberAndBinary in list)
{
var member = memberAndBinary.Item1;
#>
<# foreach (var memberAndBinary in list) {
var member = memberAndBinary.Item1; #>
writer.WriteRaw(GetSpan_<#= member.Name #>());
<#= member.GetSerializeMethodString() #>;
<#
}
#>
<# } #>
}
public <#= objInfo.FullName #> Deserialize(ref global::MessagePack.MessagePackReader reader, global::MessagePack.MessagePackSerializerOptions options)
{
if (reader.TryReadNil())
{
<#
if (objInfo.IsClass)
{
#>
<# if (objInfo.IsClass) { #>
return null;
<#
}
else
{
#>
<# } else { #>
throw new global::System.InvalidOperationException("typecode is null, struct not supported");
<#
}
#>
<# } #>
}
<#
if (objInfo.Members.Length == 0)
{
#>
<# if (objInfo.Members.Length == 0) { #>
reader.Skip();
var ____result = new <#= objInfo.GetConstructorString() #>;
<#
}
else
{
#>
<# } else { #>
options.Security.DepthStep(ref reader);
<#
if (isFormatterResolverNecessary)
{
#>
IFormatterResolver formatterResolver = options.Resolver;
<#
}
#>
<# if (isFormatterResolverNecessary) { #>
var formatterResolver = options.Resolver;
<# } #>
var length = reader.ReadMapHeader();
<#
foreach (var memberInfo in objInfo.Members)
{
#>
var __<#= memberInfo.Name #>__ = default(<#= memberInfo.Type #>);
<#
}
#>
<# var canOverwrite = objInfo.ConstructorParameters.Length == 0;
if (canOverwrite) { #>
var ____result = new <#= objInfo.GetConstructorString() #>;
<# } else {
foreach (var member in objInfo.Members.Where(x => x.IsWritable)) { #>
<# if (objInfo.ConstructorParameters.All(p => !p.Equals(member))) { #>
var __<#= member.Name #>__IsInitialized = false;
<# } #>
var __<#= member.Name #>__ = default(<#= member.Type #>);
<# } #>
<# } #>
for (int i = 0; i < length; i++)
{
ReadOnlySpan<byte> stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
var stringKey = global::MessagePack.Internal.CodeGenHelpers.ReadStringSpan(ref reader);
switch (stringKey.Length)
{
default:
FAIL:
reader.Skip();
continue;
<#= StringKeyFormatterDeserializeHelper.Classify(objInfo.Members, " ") #>
<#= StringKeyFormatterDeserializeHelper.Classify(objInfo, " ", canOverwrite) #>
}
}
var ____result = new <#= objInfo.GetConstructorString() #>
<# if (!canOverwrite) { #>
var ____result = new <#= objInfo.GetConstructorString() #>;
<# foreach (var member in objInfo.Members.Where(x => x.IsWritable && !objInfo.ConstructorParameters.Any(p => p.Equals(x)))) { #>
if (__<#= member.Name #>__IsInitialized)
{
<#
// Preparation for C#9 Record class
foreach (var member in objInfo.Members.Where(x => x.IsWritable))
{
#>
<#= member.Name #> = __<#= member.Name #>__,
<#
}
#>
};
____result.<#= member.Name #> = __<#= member.Name #>__;
}
<#
}
if (objInfo.HasIMessagePackSerializationCallbackReceiver)
{
if (objInfo.NeedsCastOnAfter)
{
#>
<# } #>
<# } #>
<# } #>
<# if (objInfo.HasIMessagePackSerializationCallbackReceiver) {
if (objInfo.NeedsCastOnAfter) { #>
((global::MessagePack.IMessagePackSerializationCallbackReceiver)____result).OnAfterDeserialize();
<#
}
else
{
#>
<# } else { #>
____result.OnAfterDeserialize();
<#
}
}
if (objInfo.Members.Length != 0)
{
#>
<# } #>
<# } #>
<# if (objInfo.Members.Length != 0) { #>
reader.Depth--;
<#
}
#>
<# } #>
return ____result;
}
}
<#
}
#>
<# } #>
}

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

@ -115,6 +115,108 @@ namespace SharedData
}
}
[MessagePackObject(true)]
public class DefaultValueStringKeyClassWithoutExplicitConstructor
{
public const int Prop1Constant = 11;
public const int Prop2Constant = 45;
public int Prop1 { get; set; } = Prop1Constant;
public int Prop2 { get; set; } = Prop2Constant;
}
[MessagePackObject(true)]
public class DefaultValueStringKeyClassWithExplicitConstructor
{
public const int Prop2Constant = 1419;
public int Prop1 { get; set; }
public int Prop2 { get; set; }
public DefaultValueStringKeyClassWithExplicitConstructor(int prop1)
{
Prop1 = prop1;
Prop2 = Prop2Constant;
}
}
[MessagePackObject(true)]
public struct DefaultValueStringKeyStructWithExplicitConstructor
{
public const int Prop2Constant = 198;
public int Prop1 { get; set; }
public int Prop2 { get; set; }
public DefaultValueStringKeyStructWithExplicitConstructor(int prop1)
{
Prop1 = prop1;
Prop2 = Prop2Constant;
}
}
[MessagePackObject]
public class DefaultValueIntKeyClassWithoutExplicitConstructor
{
public const int Prop1Constant = 33;
public const int Prop2Constant = -4;
[Key(0)]
public int Prop1 { get; set; } = Prop1Constant;
[Key(1)]
public int Prop2 { get; set; } = Prop2Constant;
}
[MessagePackObject]
public class DefaultValueIntKeyClassWithExplicitConstructor
{
public const int Prop2Constant = -109;
public const string Prop3Constant = "生命、宇宙、そして万物についての究極の疑問の答え";
public const string Prop4Constant = "Hello, world! To you, From me.";
[Key(0)]
public int Prop1 { get; set; }
[Key(1)]
public int Prop2 { get; set; }
[Key(2)]
public string Prop3 { get; set; }
[Key(3)]
public string Prop4 { get; set; }
public DefaultValueIntKeyClassWithExplicitConstructor(int prop1)
{
Prop1 = prop1;
Prop2 = Prop2Constant;
Prop3 = Prop3Constant;
Prop4 = Prop4Constant;
}
}
[MessagePackObject]
public struct DefaultValueIntKeyStructWithExplicitConstructor
{
public const int Prop2Constant = 31;
[Key(0)]
public int Prop1 { get; set; }
[Key(1)]
public int Prop2 { get; set; }
public DefaultValueIntKeyStructWithExplicitConstructor(int prop1)
{
Prop1 = prop1;
Prop2 = Prop2Constant;
}
}
[MessagePackObject(true)]
public class SimpleStringKeyData
{

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

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Nerdbank.Streams" Version="2.4.48" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="coverlet.collector" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\sandbox\Sandbox\Sandbox.csproj" />
</ItemGroup>
</Project>

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

@ -0,0 +1,105 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using MessagePack.Resolvers;
using Nerdbank.Streams;
using SharedData;
using Xunit;
namespace MessagePack.GeneratedCode.Tests
{
public class MissingPropertiesTest
{
private readonly MessagePackSerializerOptions options;
public MissingPropertiesTest()
{
var resolver = CompositeResolver.Create(GeneratedResolver.Instance, StandardResolver.Instance);
options = MessagePackSerializerOptions.Standard.WithResolver(resolver);
}
[Fact]
public void DefaultValueStringKeyClassWithoutExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteMapHeader(0);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueStringKeyClassWithoutExplicitConstructor>(seq, options);
Assert.Equal(DefaultValueStringKeyClassWithoutExplicitConstructor.Prop1Constant, instance.Prop1);
Assert.Equal(DefaultValueStringKeyClassWithoutExplicitConstructor.Prop2Constant, instance.Prop2);
}
[Fact]
public void DefaultValueStringKeyClassWithExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteMapHeader(1);
writer.Write(nameof(DefaultValueStringKeyClassWithExplicitConstructor.Prop1));
writer.Write(-1);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueStringKeyClassWithExplicitConstructor>(seq, options);
Assert.Equal(-1, instance.Prop1);
Assert.Equal(DefaultValueStringKeyClassWithExplicitConstructor.Prop2Constant, instance.Prop2);
}
[Fact]
public void DefaultValueStringKeyStructWithExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteMapHeader(1);
writer.Write(nameof(DefaultValueStringKeyStructWithExplicitConstructor.Prop1));
writer.Write(-1);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueStringKeyStructWithExplicitConstructor>(seq, options);
Assert.Equal(-1, instance.Prop1);
Assert.Equal(DefaultValueStringKeyStructWithExplicitConstructor.Prop2Constant, instance.Prop2);
}
[Fact]
public void DefaultValueIntKeyClassWithoutExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteArrayHeader(0);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueIntKeyClassWithoutExplicitConstructor>(seq, options);
Assert.Equal(DefaultValueIntKeyClassWithoutExplicitConstructor.Prop1Constant, instance.Prop1);
Assert.Equal(DefaultValueIntKeyClassWithoutExplicitConstructor.Prop2Constant, instance.Prop2);
}
[Fact]
public void DefaultValueIntKeyClassWithExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteArrayHeader(1);
writer.Write(-1);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueIntKeyClassWithExplicitConstructor>(seq, options);
Assert.Equal(-1, instance.Prop1);
Assert.Equal(DefaultValueIntKeyClassWithExplicitConstructor.Prop2Constant, instance.Prop2);
}
[Fact]
public void DefaultValueIntKeyStructWithExplicitConstructorTest()
{
var seq = new Sequence<byte>();
var writer = new MessagePackWriter(seq);
writer.WriteArrayHeader(1);
writer.Write(-1);
writer.Flush();
var instance = MessagePackSerializer.Deserialize<DefaultValueIntKeyStructWithExplicitConstructor>(seq, options);
Assert.Equal(-1, instance.Prop1);
Assert.Equal(DefaultValueIntKeyStructWithExplicitConstructor.Prop2Constant, instance.Prop2);
}
}
}