Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests-unity/UnityCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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.");

Expand All @@ -275,7 +277,7 @@
}

[ZeroSerializer]
public struct FixedPacket

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 280 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'FixedPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
{
public bool BooleanValue { get; init; }

Expand Down Expand Up @@ -410,13 +412,13 @@
public int IgnoredField;
}

[ZeroSerializer(EmitShapeTag = true)]

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 415 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'
public sealed class EmptyClassPacket
{
}

[ZeroSerializer(EmitShapeTag = true)]

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'

Check warning on line 420 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

'ZeroSerializerAttribute.EmitShapeTag' is obsolete: 'Emitting string representation of the type will expose internal details in the resulting assembly. Consider using `ShapeHash` instead, or using `#if DEBUG` directive to prevent emitting on release build.'
public struct EmptyStructPacket

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 421 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'EmptyStructPacket' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
{
}

Expand Down Expand Up @@ -453,7 +455,7 @@
}

[ZeroSerializer]
public record struct UnitySimpleRecordStruct

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Debug)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization

Check warning on line 458 in tests-unity/UnityCompatibility.cs

View workflow job for this annotation

GitHub Actions / generated-source-preview / preview (Release)

Struct 'UnitySimpleRecordStruct' has a Blittable-compatible property shape; use StructLayout(LayoutKind.Sequential, Pack = 1) to enable raw payload serialization
{
public int IntValue { get; init; }
public double DoubleValue { get; init; }
Expand Down
11 changes: 11 additions & 0 deletions tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,14 @@ public void GetByteLengthCalculatesTotalSizeWhenArrayIsLastField()
byte[] buffer = new byte[64];
int writtenBytes = source.Serialize(buffer);
VariableStructWithArrayAtEndView view = new VariableStructWithArrayAtEndView(buffer);
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(12, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values expected length");
TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithArrayAtEndView.GetByteLength with null values");
}

Expand All @@ -1037,12 +1039,14 @@ public void GetByteLengthCalculatesTotalSizeWhenStringIsLastField()
byte[] buffer = new byte[64];
int writtenBytes = source.Serialize(buffer);
VariableStructWithStringAtEndView view = new VariableStructWithStringAtEndView(buffer);
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(12, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text expected length");
TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithStringAtEndView.GetByteLength with null text");
}

Expand All @@ -1053,12 +1057,14 @@ public void GetByteLengthCalculatesTotalSizeWhenNestedBlittableStructIsLastField
byte[] buffer = new byte[64];
int writtenBytes = source.Serialize(buffer);
VariableStructWithBlittableStructAtEndView view = new VariableStructWithBlittableStructAtEndView(buffer);
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(14, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text expected length");
TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithBlittableStructAtEndView.GetByteLength with null text");
}

Expand All @@ -1069,12 +1075,14 @@ public void GetByteLengthCalculatesTotalSizeWhenPrimitiveIsLastField()
byte[] buffer = new byte[64];
int writtenBytes = source.Serialize(buffer);
VariableStructWithPrimitiveAtEndView view = new VariableStructWithPrimitiveAtEndView(buffer);
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(12, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text expected length");
TestAssert.Equal(writtenBytesNull, viewNull.GetByteLength(), "VariableStructWithPrimitiveAtEndView.GetByteLength with null text");
}

Expand Down Expand Up @@ -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
Expand All @@ -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");
}

Expand Down Expand Up @@ -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(72, view.GetByteLength(), "SharedReferenceInstances GetByteLength expected length");
TestAssert.Equal(writtenBytes, view.GetByteLength(), "SharedReferenceInstances GetByteLength");
}

Expand Down
Loading