From ab6d0fef965541a81da436c3812a57f5469d31d2 Mon Sep 17 00:00:00 2001 From: sator-imaging <16752340+sator-imaging@users.noreply.github.com> Date: Sun, 30 Aug 2026 18:33:05 +0900 Subject: [PATCH 1/3] Add explicit GetByteLength expectations --- tests-unity/UnityCompatibility.cs | 2 ++ tests/SerializationTests.cs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/tests-unity/UnityCompatibility.cs b/tests-unity/UnityCompatibility.cs index 4ec7b0d..d31fb9a 100644 --- a/tests-unity/UnityCompatibility.cs +++ b/tests-unity/UnityCompatibility.cs @@ -238,6 +238,7 @@ && nestedBlittableRecordView.Values[0].DoubleValue == 88.88 && nestedBlittableRecordView.Values[1].IntValue == 99 && nestedBlittableRecordView.Values[1].DoubleValue == 99.99 + && nestedBlittableRecordView.GetByteLength() == 64 && nestedBlittableRecordView.GetByteLength() == nestedBlittableRecordWritten, "UnityBlittableRecordStructContainer non-null roundtrip failed."); @@ -255,6 +256,7 @@ && nestedBlittableRecordNullsView.Value.DoubleValue == 88.88 && nestedBlittableRecordNullsView.OptionalValue is null && nestedBlittableRecordNullsView.Values.IsEmpty + && nestedBlittableRecordNullsView.GetByteLength() == 24 && nestedBlittableRecordNullsView.GetByteLength() == nestedBlittableRecordNullsWritten, "UnityBlittableRecordStructContainer nulls roundtrip failed."); diff --git a/tests/SerializationTests.cs b/tests/SerializationTests.cs index 57cfff0..c02ac18 100644 --- a/tests/SerializationTests.cs +++ b/tests/SerializationTests.cs @@ -1021,12 +1021,14 @@ public void GetByteLengthCalculatesTotalSizeWhenArrayIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithArrayAtEndView view = new VariableStructWithArrayAtEndView(buffer); + TestAssert.Equal(24, view.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength"); // with null values (array is null, last property with non-null value is ID) VariableStructWithArrayAtEnd sourceNull = new VariableStructWithArrayAtEnd { ID = 42, Values = null }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithArrayAtEndView viewNull = new VariableStructWithArrayAtEndView(buffer); + TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values"); } @@ -1037,12 +1039,14 @@ public void GetByteLengthCalculatesTotalSizeWhenStringIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithStringAtEndView view = new VariableStructWithStringAtEndView(buffer); + TestAssert.Equal(22, view.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength"); // with null text VariableStructWithStringAtEnd sourceNull = new VariableStructWithStringAtEnd { ID = 12, Text = null }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithStringAtEndView viewNull = new VariableStructWithStringAtEndView(buffer); + TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text"); } @@ -1053,12 +1057,14 @@ public void GetByteLengthCalculatesTotalSizeWhenNestedBlittableStructIsLastField byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithBlittableStructAtEndView view = new VariableStructWithBlittableStructAtEndView(buffer); + TestAssert.Equal(24, view.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength"); // with null text VariableStructWithBlittableStructAtEnd sourceNull = new VariableStructWithBlittableStructAtEnd { Text = null, Blittable = new PackedRecord { Number = 5, State = SignedState.Positive } }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithBlittableStructAtEndView viewNull = new VariableStructWithBlittableStructAtEndView(buffer); + TestAssert.Equal(10, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text"); } @@ -1069,12 +1075,14 @@ public void GetByteLengthCalculatesTotalSizeWhenPrimitiveIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithPrimitiveAtEndView view = new VariableStructWithPrimitiveAtEndView(buffer); + TestAssert.Equal(22, view.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength"); // with null text VariableStructWithPrimitiveAtEnd sourceNull = new VariableStructWithPrimitiveAtEnd { Text = null, Value = 100 }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithPrimitiveAtEndView viewNull = new VariableStructWithPrimitiveAtEndView(buffer); + TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text"); } @@ -1214,6 +1222,7 @@ public void NestedBlittableRecordStructsReturnViewStructs() TestAssert.Equal(second.IntValue, view.Values[1].IntValue, "Values[1].IntValue"); TestAssert.Equal(second.DoubleValue, view.Values[1].DoubleValue, "Values[1].DoubleValue"); + TestAssert.Equal(64, view.GetByteLength(), "Non-null GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "Non-null GetByteLength"); // 3. Null optional & array roundtrip @@ -1229,6 +1238,7 @@ public void NestedBlittableRecordStructsReturnViewStructs() TestAssert.Equal(first.IntValue, viewNulls.Value.IntValue, nameof(viewNulls.Value.IntValue)); Assert.Null(viewNulls.OptionalValue); TestAssert.True(viewNulls.Values.IsEmpty, nameof(viewNulls.Values.IsEmpty)); + TestAssert.Equal(24, viewNulls.GetByteLength(), "Nulls GetByteLength expected length"); TestAssert.Equal(writtenBytesNulls, viewNulls.GetByteLength(), "Nulls GetByteLength"); } @@ -1312,6 +1322,7 @@ public void SharedReferenceTypeInstancesAreSerializedSequentially() TestAssert.Equal(42, view.Bar?.Nested?.NestedValue, nameof(container.Bar.Nested.NestedValue)); TestAssert.Equal(42, view.Baz?.Nested?.NestedValue, nameof(container.Baz.Nested.NestedValue)); + TestAssert.Equal(48, view.GetByteLength(), "SharedReferenceInstances GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "SharedReferenceInstances GetByteLength"); } From 23d706c7540ac491dec00b1744598759973decc6 Mon Sep 17 00:00:00 2001 From: sator-imaging <16752340+sator-imaging@users.noreply.github.com> Date: Sun, 30 Aug 2026 18:38:23 +0900 Subject: [PATCH 2/3] Fix shared reference byte length expectation --- tests/SerializationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SerializationTests.cs b/tests/SerializationTests.cs index c02ac18..8aa34bf 100644 --- a/tests/SerializationTests.cs +++ b/tests/SerializationTests.cs @@ -1322,7 +1322,7 @@ public void SharedReferenceTypeInstancesAreSerializedSequentially() TestAssert.Equal(42, view.Bar?.Nested?.NestedValue, nameof(container.Bar.Nested.NestedValue)); TestAssert.Equal(42, view.Baz?.Nested?.NestedValue, nameof(container.Baz.Nested.NestedValue)); - TestAssert.Equal(48, view.GetByteLength(), "SharedReferenceInstances GetByteLength expected length"); + TestAssert.Equal(72, view.GetByteLength(), "SharedReferenceInstances GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "SharedReferenceInstances GetByteLength"); } From b70b638d648962359f7902a092c79cad91f9a78e Mon Sep 17 00:00:00 2001 From: sator-imaging <16752340+sator-imaging@users.noreply.github.com> Date: Sun, 30 Aug 2026 18:41:59 +0900 Subject: [PATCH 3/3] Correct variable payload length expectations --- tests/SerializationTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/SerializationTests.cs b/tests/SerializationTests.cs index 8aa34bf..927393b 100644 --- a/tests/SerializationTests.cs +++ b/tests/SerializationTests.cs @@ -1021,14 +1021,14 @@ public void GetByteLengthCalculatesTotalSizeWhenArrayIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithArrayAtEndView view = new VariableStructWithArrayAtEndView(buffer); - TestAssert.Equal(24, view.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength expected length"); + TestAssert.Equal(28, view.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength"); // with null values (array is null, last property with non-null value is ID) VariableStructWithArrayAtEnd sourceNull = new VariableStructWithArrayAtEnd { ID = 42, Values = null }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithArrayAtEndView viewNull = new VariableStructWithArrayAtEndView(buffer); - TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values expected length"); + TestAssert.Equal(12, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values"); } @@ -1039,14 +1039,14 @@ public void GetByteLengthCalculatesTotalSizeWhenStringIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithStringAtEndView view = new VariableStructWithStringAtEndView(buffer); - TestAssert.Equal(22, view.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength expected length"); + TestAssert.Equal(26, view.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength"); // with null text VariableStructWithStringAtEnd sourceNull = new VariableStructWithStringAtEnd { ID = 12, Text = null }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithStringAtEndView viewNull = new VariableStructWithStringAtEndView(buffer); - TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text expected length"); + TestAssert.Equal(12, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text"); } @@ -1057,14 +1057,14 @@ public void GetByteLengthCalculatesTotalSizeWhenNestedBlittableStructIsLastField byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithBlittableStructAtEndView view = new VariableStructWithBlittableStructAtEndView(buffer); - TestAssert.Equal(24, view.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength expected length"); + TestAssert.Equal(28, view.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength"); // with null text VariableStructWithBlittableStructAtEnd sourceNull = new VariableStructWithBlittableStructAtEnd { Text = null, Blittable = new PackedRecord { Number = 5, State = SignedState.Positive } }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithBlittableStructAtEndView viewNull = new VariableStructWithBlittableStructAtEndView(buffer); - TestAssert.Equal(10, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text expected length"); + TestAssert.Equal(14, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text"); } @@ -1075,14 +1075,14 @@ public void GetByteLengthCalculatesTotalSizeWhenPrimitiveIsLastField() byte[] buffer = new byte[64]; int writtenBytes = source.Serialize(buffer); VariableStructWithPrimitiveAtEndView view = new VariableStructWithPrimitiveAtEndView(buffer); - TestAssert.Equal(22, view.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength expected length"); + TestAssert.Equal(26, view.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength expected length"); TestAssert.Equal(writtenBytes, view.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength"); // with null text VariableStructWithPrimitiveAtEnd sourceNull = new VariableStructWithPrimitiveAtEnd { Text = null, Value = 100 }; int writtenBytesNull = sourceNull.Serialize(buffer); VariableStructWithPrimitiveAtEndView viewNull = new VariableStructWithPrimitiveAtEndView(buffer); - TestAssert.Equal(8, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text expected length"); + TestAssert.Equal(12, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text expected length"); TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text"); }