M Packets/NosSmooth.PacketSerializer.Abstractions/Attributes/PacketIndexAttribute.cs => Packets/NosSmooth.PacketSerializer.Abstractions/Attributes/PacketIndexAttribute.cs +13 -0
@@ 49,4 49,17 @@ public class PacketIndexAttribute : Attribute
/// more complex decision making about using parameters.
/// </remarks>
public bool IsOptional { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets whether there may be multiple separators after the field.
+ /// </summary>
+ public bool AllowMultipleSeparators { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets the number of multiple separators after the field.
+ /// </summary>
+ /// <remarks>
+ /// <see cref="AllowMultipleSeparators"/> has to be true to make this work.
+ /// </remarks>
+ public short MultipleSeparatorsCount { get; set; } = 1;
}=
\ No newline at end of file
M Packets/NosSmooth.PacketSerializer.Abstractions/NosSmooth.PacketSerializer.Abstractions.csproj => Packets/NosSmooth.PacketSerializer.Abstractions/NosSmooth.PacketSerializer.Abstractions.csproj +2 -2
@@ 7,9 7,9 @@
<Description>NosSmooth's packet serializer abstractions that hold all interfaces, classes, errors needed for creating assemblies with packets that can have generated serializers.</Description>
<RepositoryUrl>https://github.com/Rutherther/NosSmooth/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
- <VersionPrefix>1.3.0</VersionPrefix>
+ <VersionPrefix>1.3.1</VersionPrefix>
<TargetFrameworks>net7.0;netstandard2.1</TargetFrameworks>
- <PackageReleaseNotes>Add manual capture and increment of tokens read to allow reading lists of specified size if the separator is same for multiple levels.</PackageReleaseNotes>
+ <PackageReleaseNotes>Add IsOnSeparator method to PacketStringEnumerator.</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
M Packets/NosSmooth.PacketSerializer.Abstractions/PacketStringEnumerator.cs => Packets/NosSmooth.PacketSerializer.Abstractions/PacketStringEnumerator.cs +9 -0
@@ 324,6 324,15 @@ public ref struct PacketStringEnumerator
}
/// <summary>
+ /// Checks whether the current character is a separator.
+ /// </summary>
+ /// <returns>Whether the current character is a separator.</returns>
+ public bool IsOnSeparator()
+ {
+ return IsSeparator(_data[_cursor], out _, out _);
+ }
+
+ /// <summary>
/// Checks if the given character is a separator.
/// </summary>
/// <param name="c">The character to check.</param>
M Packets/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs => Packets/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs +21 -0
@@ 86,6 86,17 @@ public class PacketIndexAttributeGenerator : IParameterGenerator
generator.PopLevel();
}
+ var allowMultipleSeparators = attribute.GetNamedValue("AllowMultipleSeparators", false);
+ var multipleSeparatorsCount = attribute.GetNamedValue<int>("MultipleSeparatorsCount", 1);
+
+ if (allowMultipleSeparators)
+ {
+ for (var i = 0; i < multipleSeparatorsCount; i++)
+ {
+ textWriter.WriteLine("builder.Append(string.Empty);");
+ }
+ }
+
// end optional if
if (parameter.IsOptional())
{
@@ 143,6 154,16 @@ public class PacketIndexAttributeGenerator : IParameterGenerator
generator.PopLevel();
}
+ var allowMultipleSeparators = attribute.GetNamedValue<bool>("AllowMultipleSeparators", false);
+
+ if (allowMultipleSeparators)
+ {
+ textWriter.WriteLine("while (stringEnumerator.IsOnSeparator())");
+ textWriter.WriteLine("{");
+ textWriter.WriteLine("stringEnumerator.GetNextToken(out _);");
+ textWriter.WriteLine("}");
+ }
+
// end is last token if body
if (parameter.IsOptional())
{
M Packets/NosSmooth.PacketSerializersGenerator/NosSmooth.PacketSerializersGenerator.csproj => Packets/NosSmooth.PacketSerializersGenerator/NosSmooth.PacketSerializersGenerator.csproj +2 -4
@@ 9,12 9,10 @@
<IncludeCopyLocalFilesOutputGroup>true</IncludeCopyLocalFilesOutputGroup>
<Description>NosSmooth's source code generator that generates serializers for packets.</Description>
<IncludeBuildOutput>false</IncludeBuildOutput>
- <VersionPrefix>1.1.0</VersionPrefix>
+ <VersionPrefix>1.1.1</VersionPrefix>
<RepositoryUrl>https://github.com/Rutherther/NosSmooth/</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
- <PackageReleaseNotes>Add PacketConditionalList.
-Fix PacketContextList.
-Make not last validations inside current parameter, not previous one.</PackageReleaseNotes>
+ <PackageReleaseNotes>Add support for multiple separators.</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>