diff --git a/ProjectLighthouse/Extensions/ControllerExtensions.cs b/ProjectLighthouse/Extensions/ControllerExtensions.cs index 189d9883..78fb469c 100644 --- a/ProjectLighthouse/Extensions/ControllerExtensions.cs +++ b/ProjectLighthouse/Extensions/ControllerExtensions.cs @@ -33,7 +33,7 @@ public static partial class ControllerExtensions // Separate method because Span/ReadOnlySpan cannot be used in async methods ReadOnlySpan span = readOnlySequence.IsSingleSegment ? readOnlySequence.First.Span - : readOnlySequence.ToArray().AsSpan(); + : readOnlySequence.ToArray(); builder.Append(Encoding.UTF8.GetString(span)); } @@ -47,32 +47,13 @@ public static partial class ControllerExtensions ReadResult readResult = await controller.Request.BodyReader.ReadAsync(); ReadOnlySequence buffer = readResult.Buffer; - SequencePosition? position; - - do + if (buffer.Length > 0) { - // Look for a EOL in the buffer - position = buffer.PositionOf((byte)'\n'); - if (position == null) continue; - - ReadOnlySequence readOnlySequence = buffer.Slice(0, position.Value); - AddStringToBuilder(builder, in readOnlySequence); - - // Skip the line + the \n character (basically position) - buffer = buffer.Slice(buffer.GetPosition(1, position.Value)); - } - while (position != null); - - - if (readResult.IsCompleted && buffer.Length > 0) - { - AddStringToBuilder(builder, in buffer); + AddStringToBuilder(builder, buffer); } - controller.Request.BodyReader.AdvanceTo(buffer.Start, buffer.End); + controller.Request.BodyReader.AdvanceTo(buffer.End); - // At this point, buffer will be updated to point one byte after the last - // \n character. if (readResult.IsCompleted) { break; diff --git a/ProjectLighthouse/Serialization/LighthouseSerializer.cs b/ProjectLighthouse/Serialization/LighthouseSerializer.cs index 122a77ee..36f6aafa 100644 --- a/ProjectLighthouse/Serialization/LighthouseSerializer.cs +++ b/ProjectLighthouse/Serialization/LighthouseSerializer.cs @@ -32,7 +32,7 @@ public static class LighthouseSerializer public static CustomXmlSerializer GetSerializer(Type type, XmlRootAttribute? rootAttribute = null) { - if (serializerCache.TryGetValue((type, rootAttribute), out CustomXmlSerializer? value)) return value; + if (serializerCache.TryGetValue((type, rootAttribute), out CustomXmlSerializer? value)) return value; CustomXmlSerializer serializer = new(type, rootAttribute); diff --git a/ProjectLighthouse/Types/Serialization/GenericSlotResponse.cs b/ProjectLighthouse/Types/Serialization/GenericSlotResponse.cs index 077d81b7..2b6a7dc4 100644 --- a/ProjectLighthouse/Types/Serialization/GenericSlotResponse.cs +++ b/ProjectLighthouse/Types/Serialization/GenericSlotResponse.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using System.ComponentModel; using System.Xml.Serialization; -using LBPUnion.ProjectLighthouse.Serialization; namespace LBPUnion.ProjectLighthouse.Types.Serialization; @@ -9,7 +8,7 @@ public struct GenericSlotResponse : ILbpSerializable, IHasCustomRoot { public GenericSlotResponse() { } - public GenericSlotResponse(string rootElement, List slots, int total, int hintStart) + public GenericSlotResponse(string rootElement, List slots, int total = 0, int hintStart = 0) { this.RootTag = rootElement; this.Slots = slots; @@ -17,14 +16,12 @@ public struct GenericSlotResponse : ILbpSerializable, IHasCustomRoot this.HintStart = hintStart; } - public GenericSlotResponse(string rootElement, List slots) : this(rootElement, slots, 0, 0) { } - public GenericSlotResponse(List slots) : this("slots", slots) { } public GenericSlotResponse(List slots, int total, int hintStart) : this("slots", slots, total, hintStart) { } [XmlIgnore] - public string RootTag { get; set; } + private string RootTag { get; } [XmlElement("slot")] public List Slots { get; set; }