GameCult.Thing.Contract: Present refuses the default byte view, not every unbacked empty one

MemoryMarshal.TryGetArray answers true for any empty view, so it cannot tell nil
from empty; equality with default can. The commit before this fails the new payload test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-14 04:31:52 +02:00
commit 686b32831b

View file

@ -50,11 +50,11 @@ public static class ThingDomain
value ?? throw new ThingDomainException(slot, "present");
/// <summary>
/// A required byte slot. A null on the wire decodes to a default view with no backing store, so a view that is
/// empty and backed by nothing is refused as nil; an empty array is a present, empty payload.
/// A required byte slot. A null on the wire decodes to a default view with no backing store, so the default view is
/// refused as nil; an empty array is a present, empty payload.
/// </summary>
public static ReadOnlyMemory<byte> Present(ReadOnlyMemory<byte> value, string slot) =>
value.IsEmpty && !System.Runtime.InteropServices.MemoryMarshal.TryGetArray(value, out _)
value.Equals(default(ReadOnlyMemory<byte>))
? throw new ThingDomainException(slot, "present")
: value;