Skip to content

Commit

Permalink
Formatting AeroRouting
Browse files Browse the repository at this point in the history
  • Loading branch information
Xsear committed Mar 7, 2024
1 parent 3d38611 commit 9d8ca18
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Aero/Aero.Gen/Aero.Gen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<LangVersion>9</LangVersion>

<PackageId>Aero.Gen</PackageId>
<Version>1.2.14</Version>
<Version>1.2.15</Version>
<Authors></Authors>
<Company>The Melding Wars</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.2.14</PackageVersion>
<PackageVersion>1.2.15</PackageVersion>
<Description>A source genrator to serialise class and struct with minimal attributes efficently</Description>
<PackageProjectUrl>https://github.com/themeldingwars/Aero</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/themeldingwars/Aero/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/themeldingwars/Aero</RepositoryUrl>
<PackageTags>TMW, Serialisation, Source Genrator</PackageTags>
<AssemblyVersion>1.2.14</AssemblyVersion>
<AssemblyVersion>1.2.15</AssemblyVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
24 changes: 16 additions & 8 deletions Aero/Aero.Gen/AeroGenrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void AddPacketSwitch(IEnumerable<AeroMessageIdAttribute> msgs)
AddLine(sb, $"_ => null,");
}
UnIndentAndAddLine(sb, "};");
AddLine(sb, "");
AddLine(sb, "return msg;");
}

Expand All @@ -169,22 +170,26 @@ void AddPacketSwitch(IEnumerable<AeroMessageIdAttribute> msgs)
AddLine(sb, $"public static IAero GetNewMessageHandler(AeroMessageIdAttribute.MsgType typ, AeroMessageIdAttribute.MsgSrc src, int messageId, int controllerId = -1)");
AddLineAndIndent(sb, "{");
{
AddLineAndIndent(sb, "if (typ == AeroMessageIdAttribute.MsgType.Control) {");
AddLine(sb, "if (typ == AeroMessageIdAttribute.MsgType.Control)");
AddLineAndIndent(sb, "{");
{
var controllMsgs = snRecv.AeroMessageIds.Values.Where(x => x.Typ == AeroMessageIdAttribute.MsgType.Control);
AddPacketSwitch(controllMsgs);

UnIndentAndAddLine(sb, "}");
AddLineAndIndent(sb, "else if (typ == AeroMessageIdAttribute.MsgType.Matrix) {");
AddLine(sb, "else if (typ == AeroMessageIdAttribute.MsgType.Matrix)");
AddLineAndIndent(sb, "{");
{
AddLineAndIndent(sb, "if (src == AeroMessageIdAttribute.MsgSrc.Command || src == AeroMessageIdAttribute.MsgSrc.Both) {");
AddLine(sb, "if (src == AeroMessageIdAttribute.MsgSrc.Command || src == AeroMessageIdAttribute.MsgSrc.Both) ");
AddLineAndIndent(sb, "{");
{
var msgs = snRecv.AeroMessageIds.Values.Where(x => x.Typ == AeroMessageIdAttribute.MsgType.Matrix && x.Src is AeroMessageIdAttribute.MsgSrc.Command or AeroMessageIdAttribute.MsgSrc.Both);
AddPacketSwitch(msgs);
}
UnIndentAndAddLine(sb, "}");

AddLineAndIndent(sb, "else if (src == AeroMessageIdAttribute.MsgSrc.Message || src == AeroMessageIdAttribute.MsgSrc.Both) {");
AddLine(sb, "else if (src == AeroMessageIdAttribute.MsgSrc.Message || src == AeroMessageIdAttribute.MsgSrc.Both)");
AddLineAndIndent(sb, "{");
{
var msgs = snRecv.AeroMessageIds.Values.Where(x => x.Typ == AeroMessageIdAttribute.MsgType.Matrix && x.Src is AeroMessageIdAttribute.MsgSrc.Message or AeroMessageIdAttribute.MsgSrc.Both);
AddPacketSwitch(msgs);
Expand All @@ -193,9 +198,11 @@ void AddPacketSwitch(IEnumerable<AeroMessageIdAttribute> msgs)
}
UnIndentAndAddLine(sb, "}");

AddLineAndIndent(sb, "else if (typ == AeroMessageIdAttribute.MsgType.GSS) {");
AddLine(sb, "else if (typ == AeroMessageIdAttribute.MsgType.GSS)");
AddLineAndIndent(sb, "{");
{
AddLineAndIndent(sb, "if (src == AeroMessageIdAttribute.MsgSrc.Command || src == AeroMessageIdAttribute.MsgSrc.Both) {");
AddLine(sb, "if (src == AeroMessageIdAttribute.MsgSrc.Command || src == AeroMessageIdAttribute.MsgSrc.Both)");
AddLineAndIndent(sb, "{");
{
var controllerMsgs = snRecv.AeroMessageIds.Values.Where(x => x.Typ == AeroMessageIdAttribute.MsgType.GSS &&
x.Src is AeroMessageIdAttribute.MsgSrc.Command or AeroMessageIdAttribute.MsgSrc.Both).GroupBy(x => x.ControllerId);
Expand All @@ -209,7 +216,8 @@ void AddPacketSwitch(IEnumerable<AeroMessageIdAttribute> msgs)
}
UnIndentAndAddLine(sb, "}");

AddLineAndIndent(sb, "else if (src == AeroMessageIdAttribute.MsgSrc.Message || src == AeroMessageIdAttribute.MsgSrc.Both) {");
AddLine(sb, "else if (src == AeroMessageIdAttribute.MsgSrc.Message || src == AeroMessageIdAttribute.MsgSrc.Both)");
AddLineAndIndent(sb, "{");
{
var controllerMsgs = snRecv.AeroMessageIds.Values.Where(x => x.Typ == AeroMessageIdAttribute.MsgType.GSS &&
x.Src is AeroMessageIdAttribute.MsgSrc.Message or AeroMessageIdAttribute.MsgSrc.Both).GroupBy(x => x.ControllerId);
Expand All @@ -225,7 +233,7 @@ void AddPacketSwitch(IEnumerable<AeroMessageIdAttribute> msgs)
}
UnIndent();
AddLine(sb, "}");

AddLine(sb, "");
AddLine(sb, "return null;");

UnIndentAndAddLine(sb, "}");
Expand Down

1 comment on commit 9d8ca18

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark result (use as a guide):

BenchmarkDotNet=v0.12.1, OS=ubuntu 22.04
AMD EPYC 7763, 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=5.0.408
 [Host] : .NET Core 5.0.17 (CoreCLR 5.0.1722.21314, CoreFX 5.0.1722.21314), X64 RyuJIT
 Job-CAJJPM : .NET Core 5.0.17 (CoreCLR 5.0.1722.21314, CoreFX 5.0.1722.21314), X64 RyuJIT

Runtime=.NET Core 5.0 IterationCount=10 LaunchCount=1 
WarmupCount=5 
Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
BinaryReaderBaseLine 219.9570 ns 1.2764 ns 0.6676 ns 0.0043 - - 376 B
BinaryWriterBaseLine 384.5223 ns 1.0354 ns 0.6162 ns 0.0057 - - 496 B
SimpleTypesRead 9.9110 ns 0.1098 ns 0.0654 ns - - - -
SubTypesRead 5.2928 ns 0.0208 ns 0.0137 ns - - - -
ArraysCombinedRead 1,274.7904 ns 23.9469 ns 15.8394 ns 0.0687 - - 5800 B
ByteArrayRead 88.1486 ns 1.6829 ns 1.1131 ns 0.0014 - - 128 B
IntArrayRead 132.3231 ns 2.0047 ns 1.3260 ns 0.0050 - - 424 B
BlockArrayRead 918.7202 ns 12.0108 ns 7.1474 ns 0.0572 0.0010 - 4824 B
FixedLengthString 31.6854 ns 0.3386 ns 0.2015 ns 0.0005 - - 40 B
PrefixedLengthString 30.5553 ns 0.3153 ns 0.2086 ns 0.0005 - - 40 B
NullTerminatedLengthString 35.8304 ns 0.3064 ns 0.2027 ns 0.0005 - - 40 B
Vector2Array2Read 13.2287 ns 0.1380 ns 0.0913 ns 0.0005 - - 40 B
GetPackedLengthSimple 0.6489 ns 0.0219 ns 0.0131 ns - - - -
GetPackedLengthComplex 0.3094 ns 0.0193 ns 0.0128 ns - - - -
PackSimple 4.2781 ns 0.0164 ns 0.0109 ns - - - -
PackSubTypesSimple 4.7775 ns 0.0078 ns 0.0046 ns - - - -
PackComplex 142.0253 ns 0.9756 ns 0.6453 ns - - - -
PackArraysCombined 943.7357 ns 7.7496 ns 4.6116 ns - - - -
PackByteArray 69.7989 ns 0.0986 ns 0.0587 ns - - - -
PackIntArray 99.9070 ns 1.6339 ns 1.0807 ns - - - -
PackBlockArray 661.6788 ns 2.4409 ns 1.6145 ns - - - -
PackFixedLengthString 26.3132 ns 0.3423 ns 0.2264 ns 0.0005 - - 40 B
PackPrefixedLengthString 25.6467 ns 0.1014 ns 0.0671 ns 0.0005 - - 40 B
PackNullTerminatedLengthString 25.5085 ns 0.0971 ns 0.0643 ns 0.0005 - - 40 B

Please sign in to comment.