From 14621b3893c6a5fd9c0e3903eeea474ec25e091f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 29 Sep 2026 16:15:29 +0200 Subject: [PATCH] Reference CultMath from Caching.MessagePack and scope the span helpers The first commit's resolver needs the CultMath project reference and scoped span parameters to compile; the golden test file also had two literal slips. Co-Authored-By: Claude Sonnet 5 --- .../CultMathResolver.cs | 20 +++++++++---------- .../GameCult.Caching.MessagePack.csproj | 1 + .../CultMathSerializationTests.cs | 7 ++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/GameCult.Caching.MessagePack/CultMathResolver.cs b/src/GameCult.Caching.MessagePack/CultMathResolver.cs index 71bdec2b..c854e12d 100644 --- a/src/GameCult.Caching.MessagePack/CultMathResolver.cs +++ b/src/GameCult.Caching.MessagePack/CultMathResolver.cs @@ -58,61 +58,61 @@ public sealed class CultMathResolver : IFormatterResolver new(typeof(T), new ArrayShape(write, read)); // Each reader takes the first dst.Length elements and skips the rest. - private static void Singles(ref MessagePackReader r, Span dst) + private static void Singles(ref MessagePackReader r, scoped Span dst) { for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) if (i < dst.Length) dst[i] = r.ReadSingle(); else r.Skip(); } - private static void Doubles(ref MessagePackReader r, Span dst) + private static void Doubles(ref MessagePackReader r, scoped Span dst) { for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) if (i < dst.Length) dst[i] = r.ReadDouble(); else r.Skip(); } - private static void Ints(ref MessagePackReader r, Span dst) + private static void Ints(ref MessagePackReader r, scoped Span dst) { for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) if (i < dst.Length) dst[i] = r.ReadInt32(); else r.Skip(); } - private static void Bools(ref MessagePackReader r, Span dst) + private static void Bools(ref MessagePackReader r, scoped Span dst) { for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) if (i < dst.Length) dst[i] = r.ReadBoolean(); else r.Skip(); } - private static void Bytes(ref MessagePackReader r, Span dst) + private static void Bytes(ref MessagePackReader r, scoped Span dst) { for (int i = 0, n = r.ReadArrayHeader(); i < n; i++) if (i < dst.Length) dst[i] = r.ReadByte(); else r.Skip(); } - private static void Put(ref MessagePackWriter w, ReadOnlySpan v) + private static void Put(ref MessagePackWriter w, scoped ReadOnlySpan v) { w.WriteArrayHeader(v.Length); foreach (var e in v) w.Write(e); } - private static void Put(ref MessagePackWriter w, ReadOnlySpan v) + private static void Put(ref MessagePackWriter w, scoped ReadOnlySpan v) { w.WriteArrayHeader(v.Length); foreach (var e in v) w.Write(e); } - private static void Put(ref MessagePackWriter w, ReadOnlySpan v) + private static void Put(ref MessagePackWriter w, scoped ReadOnlySpan v) { w.WriteArrayHeader(v.Length); foreach (var e in v) w.Write(e); } - private static void Put(ref MessagePackWriter w, ReadOnlySpan v) + private static void Put(ref MessagePackWriter w, scoped ReadOnlySpan v) { w.WriteArrayHeader(v.Length); foreach (var e in v) w.Write(e); } - private static void Put(ref MessagePackWriter w, ReadOnlySpan v) + private static void Put(ref MessagePackWriter w, scoped ReadOnlySpan v) { w.WriteArrayHeader(v.Length); foreach (var e in v) w.Write(e); diff --git a/src/GameCult.Caching.MessagePack/GameCult.Caching.MessagePack.csproj b/src/GameCult.Caching.MessagePack/GameCult.Caching.MessagePack.csproj index c2bd1c1b..a37232a9 100644 --- a/src/GameCult.Caching.MessagePack/GameCult.Caching.MessagePack.csproj +++ b/src/GameCult.Caching.MessagePack/GameCult.Caching.MessagePack.csproj @@ -6,6 +6,7 @@ + diff --git a/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs b/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs index c6b6d161..76f95d34 100644 --- a/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs +++ b/tests/GameCult.Caching.Tests/CultMathSerializationTests.cs @@ -28,9 +28,10 @@ namespace GameCult.Caching.Tests // Bytes the pre-collapse CultVec2/CultVec3/CultRect encodings and Aetheria's Float2/Int2/Bool2/Float3/Float4 // formatters produce: an array of components in declaration order, float32 as 0xCA. - [TestCase("92CA3F800000CA40000000")] - public void Float2_MatchesTheLegacyVectorBytes(string hex) + [Test] + public void Float2_MatchesTheLegacyVectorBytes() { + const string hex = "92CA3F800000CA40000000"; Hex(new float2(1f, 2f)).Should().Be(hex); Decode(hex).Should().Be(new float2(1f, 2f)); } @@ -102,7 +103,7 @@ namespace GameCult.Caching.Tests [Test] public void Matrices_AreArraysOfRows() { - Hex(new float2x2(1f, 2f, 3f, 4f)).Should().Be("9292CA3F800000CA400000009 2CA40400000CA40800000".Replace(" ", "")); + Hex(new float2x2(1f, 2f, 3f, 4f)).Should().Be("9292CA3F800000CA4000000092CA40400000CA40800000"); } [Test]