From 13302797a0316dca05a60697cb651eb8b43f075a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Thu, 30 Dec 2021 19:56:07 +0100 Subject: [PATCH] feat: skip to last token of nested levels if possible --- .../AttributeGenerators/PacketIndexAttributeGenerator.cs | 9 +++++++++ .../Converters/Special/ListTypeConverter.cs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/Core/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs b/Core/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs index 9f7ff82..05d7771 100644 --- a/Core/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs +++ b/Core/NosSmooth.PacketSerializersGenerator/AttributeGenerators/PacketIndexAttributeGenerator.cs @@ -95,6 +95,15 @@ if ({parameterInfo.Name}Result.Entity is null) {{ if (pushedLevel) { + // If we know that we are not on the last token in the item level, just skip to the end of the item. + // Note that if this is the case, then that means the converter is either corrupted + // or the packet has more fields. + textWriter.WriteLine($@" +while (stringEnumerator.IsOnLastToken() == false) +{{ + stringEnumerator.GetNextToken(); +}} +"); textWriter.WriteLine("stringEnumerator.PopLevel();"); } diff --git a/Core/NosSmooth.Packets/Converters/Special/ListTypeConverter.cs b/Core/NosSmooth.Packets/Converters/Special/ListTypeConverter.cs index 9aa2637..3e3034c 100644 --- a/Core/NosSmooth.Packets/Converters/Special/ListTypeConverter.cs +++ b/Core/NosSmooth.Packets/Converters/Special/ListTypeConverter.cs @@ -53,6 +53,15 @@ public class ListTypeConverter : ISpecialTypeConverter } var result = _typeConverterRepository.Deserialize(genericType, stringEnumerator); + + // If we know that we are not on the last token in the item level, just skip to the end of the item. + // Note that if this is the case, then that means the converter is either corrupted + // or the packet has more fields. + while (stringEnumerator.IsOnLastToken() == false) + { + stringEnumerator.GetNextToken(); + } + stringEnumerator.PopLevel(); if (!result.IsSuccess) { -- 2.48.1