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:
parent
9d8f5706ad
commit
686b32831b
1 changed files with 3 additions and 3 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue