refactor(net): #13 Parsed.TrailerTruncated + diag logging
Code-quality review followup on Task 2 (becbde6) — addresses I1 (the
forward-looking concern that Tasks 3-9's inner-catch will leave partial
lists visible to callers with no signal) and M1 (silent inner catch).
Changes:
- Parsed gains a trailing `bool TrailerTruncated` field. Both
construction sites pass `false` by default; the trailer try/catch
flips a local `trailerTruncated` to `true` on FormatException and
feeds it into the final return.
- Inner catch logs `pos`/`payload.Length`/exception message under
ACDREAM_DUMP_VITALS=1, mirroring the outer catch's diagnostic
pattern.
- Task 2 test strengthened to assert defaults on Options2 /
SpellbookFilters / HotbarSpells / DesiredComps / GameplayOptions /
Equipped + TrailerTruncated=false (M2 followup — gives Tasks 3-9
a regression guard if they consume into the wrong field).
- New test `TryParse_TrailerAbsent_LessThan8BytesAfterEnchantments_*`
documents the contract that <8 bytes after enchantments means the
trailer is absent (not truncated): TrailerTruncated stays false,
upstream attribute data survives.
- Plan updated in lockstep so Tasks 3-11 implementers see the
`trailerTruncated` local and the new return-arg position.
271/271 AcDream.Core.Net.Tests pass.
This commit is contained in:
parent
becbde60a4
commit
9a0dfe03da
3 changed files with 96 additions and 11 deletions
|
|
@ -227,6 +227,13 @@ public static class PlayerDescriptionParser
|
|||
uint EquipLocation,
|
||||
uint Priority);
|
||||
|
||||
/// <summary>Result of <see cref="TryParse"/>. Trailer fields
|
||||
/// (<c>OptionFlags</c> through <c>Equipped</c>) may be partially
|
||||
/// populated when <see cref="TrailerTruncated"/> is <c>true</c> —
|
||||
/// the parse degraded gracefully rather than discarding upstream
|
||||
/// attribute / skill / spell / enchantment data. Callers that
|
||||
/// require all-or-nothing trailer semantics should ignore the
|
||||
/// trailer fields when this flag is set.</summary>
|
||||
public readonly record struct Parsed(
|
||||
uint WeenieType,
|
||||
DescriptionPropertyFlag PropertyFlags,
|
||||
|
|
@ -247,7 +254,8 @@ public static class PlayerDescriptionParser
|
|||
uint SpellbookFilters,
|
||||
ReadOnlyMemory<byte> GameplayOptions,
|
||||
IReadOnlyList<InventoryEntry> Inventory,
|
||||
IReadOnlyList<EquippedEntry> Equipped);
|
||||
IReadOnlyList<EquippedEntry> Equipped,
|
||||
bool TrailerTruncated);
|
||||
|
||||
/// <summary>
|
||||
/// Parse a PlayerDescription payload. The 0xF7B0 envelope has been
|
||||
|
|
@ -325,6 +333,7 @@ public static class PlayerDescriptionParser
|
|||
ReadOnlyMemory<byte> gameplayOptions = ReadOnlyMemory<byte>.Empty;
|
||||
List<InventoryEntry> inventory = new();
|
||||
List<EquippedEntry> equipped = new();
|
||||
bool trailerTruncated = false;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -334,9 +343,16 @@ public static class PlayerDescriptionParser
|
|||
options1 = ReadU32(payload, ref pos);
|
||||
}
|
||||
}
|
||||
catch (FormatException)
|
||||
catch (FormatException ex)
|
||||
{
|
||||
// Trailer corrupted — keep what we have and return.
|
||||
// Trailer corrupted — keep what we have and flag it. Once
|
||||
// Tasks 3-9 add list reads inside this try block, partial
|
||||
// lists may be visible to callers; TrailerTruncated tells
|
||||
// them so they can ignore the trailer if they need all-or-
|
||||
// nothing semantics.
|
||||
trailerTruncated = true;
|
||||
if (System.Environment.GetEnvironmentVariable("ACDREAM_DUMP_VITALS") == "1")
|
||||
System.Console.WriteLine($"PlayerDescriptionParser: trailer FormatException at pos={pos}/{payload.Length}: {ex.Message}");
|
||||
}
|
||||
|
||||
return new Parsed(
|
||||
|
|
@ -344,7 +360,7 @@ public static class PlayerDescriptionParser
|
|||
bundle, positions, attributes, skills, spells, enchantments,
|
||||
optionFlags, options1, options2,
|
||||
shortcuts, hotbarSpells, desiredComps, spellbookFilters,
|
||||
gameplayOptions, inventory, equipped);
|
||||
gameplayOptions, inventory, equipped, trailerTruncated);
|
||||
}
|
||||
catch (FormatException ex)
|
||||
{
|
||||
|
|
@ -373,7 +389,8 @@ public static class PlayerDescriptionParser
|
|||
0u,
|
||||
ReadOnlyMemory<byte>.Empty,
|
||||
System.Array.Empty<InventoryEntry>(),
|
||||
System.Array.Empty<EquippedEntry>());
|
||||
System.Array.Empty<EquippedEntry>(),
|
||||
TrailerTruncated: false);
|
||||
}
|
||||
|
||||
// ── Attribute block reader ──────────────────────────────────────────────
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue