Skip to content
Closed
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
8 changes: 4 additions & 4 deletions benchmark/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public int DeserializeAllProperties()
ReadOnlySpan<int> integers = view.Integers;
ReadOnlySpan<long> longs = view.Longs;
ReadOnlySpan<PackedBenchmarkValue> packedValues = view.PackedValues;
NestedPayloadView nested = view.Nested;
int nestedVersion = nested.Version;
ReadOnlySpan<char> nestedLabel = nested.Label;
PackedBenchmarkValueView nestedSummary = nested.Summary;
NestedPayloadView? nested = view.Nested;
int nestedVersion = nested?.Version ?? -1;
ReadOnlySpan<char> nestedLabel = (nested ?? new()).Label; // Nullable<ReadOnlySpan<char>> is invalid
PackedBenchmarkValueView nestedSummary = nested?.Summary ?? new();
NestedStructPayloadView nestedStruct = view.NestedStruct;
int nestedStructCode = nestedStruct.Code;
long nestedStructAmount = nestedStruct.Amount;
Expand Down
2 changes: 2 additions & 0 deletions src/FieldGenerationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ internal FieldGenerationModel(

internal int ElementByteCount { get; }

internal int BlittableByteOffset { get; set; }

internal ITypeSymbol? ArrayElementType { get; }

internal INamedTypeSymbol? NestedSerializableType { get; }
Expand Down
33 changes: 22 additions & 11 deletions src/ZeroSerializerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@
}

// Roslyn's member order is the wire declaration order; never infer a different order from file paths or spans.
int blittableByteOffset = 0;
foreach (ISymbol declaredMember in serializableType.GetMembers())
{
// Only public getter properties define the wire contract; fields, setters, and indexers must never leak into it.
Expand Down Expand Up @@ -362,7 +363,9 @@
continue;
}

propertyModel.BlittableByteOffset = blittableByteOffset;
generationModel.Fields.Add(propertyModel);
blittableByteOffset += propertyModel.ElementByteCount;
}

return generationModel;
Expand Down Expand Up @@ -1194,14 +1197,28 @@
propertyType = field.Symbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
}

sourceBuilder.AppendLine($"{propertyAccessibility} {propertyType} {EscapeIdentifier(field.Symbol.Name)}");
var propertyReturnType
= field.Kind is FieldSerializationKind.BlittableStruct or FieldSerializationKind.Nested
? (field.NullableUnderlyingType is not null || field.Symbol.Type.TypeKind is TypeKind.Class)
? GetQualifiedViewName(field.NestedSerializableType) + "?"
: GetQualifiedViewName(field.NestedSerializableType)
: propertyType;
sourceBuilder.AppendLine($"{propertyAccessibility} {propertyReturnType} {EscapeIdentifier(field.Symbol.Name)}");
sourceBuilder.OpenBlock();
sourceBuilder.AppendLine("get");
sourceBuilder.OpenBlock();
if (containingModel.IsBlittableStruct)
{
sourceBuilder.AppendLine($"{containingModel.QualifiedSourceTypeName} blittableSourceValue = MemoryMarshal.Read<{containingModel.QualifiedSourceTypeName}>(serializedMemory.Span);");
sourceBuilder.AppendLine($"return blittableSourceValue.{EscapeIdentifier(field.Symbol.Name)};");
if (field.Kind == FieldSerializationKind.BlittableStruct
&& field.NestedSerializableType is not null)
{
sourceBuilder.AppendLine($"return new {GetQualifiedViewName(field.NestedSerializableType)}(serializedMemory.Slice({field.BlittableByteOffset}, {field.ElementByteCount}));");
}
else
{
sourceBuilder.AppendLine($"{containingModel.QualifiedSourceTypeName} blittableSourceValue = MemoryMarshal.Read<{containingModel.QualifiedSourceTypeName}>(serializedMemory.Span);");
sourceBuilder.AppendLine($"return blittableSourceValue.{EscapeIdentifier(field.Symbol.Name)};");
}
sourceBuilder.CloseBlock();
sourceBuilder.CloseBlock();
return;
Expand All @@ -1214,14 +1231,8 @@
// Null is represented entirely by the offset table; no property payload marker is read.
sourceBuilder.AppendLine("if (fieldDataOffset == 0)");
sourceBuilder.OpenBlock();
if (field.NullableUnderlyingType is not null && field.Kind != FieldSerializationKind.Nested)
{
sourceBuilder.AppendLine("return null;");
}
else
{
sourceBuilder.AppendLine("return default;");
}
// Always use 'default' instead of 'null' for reference types.
sourceBuilder.AppendLine("return default;");
sourceBuilder.CloseBlock();
}

Expand Down Expand Up @@ -1268,8 +1279,8 @@
}

sourceBuilder.CloseBlock();
sourceBuilder.CloseBlock();

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1282 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.
}

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

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

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Debug)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / test (Release)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net5.0, .NET 5)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

Check warning on line 1283 in src/ZeroSerializerGenerator.cs

View workflow job for this annotation

GitHub Actions / benchmark (net10.0, .NET 10)

Possible null reference argument for parameter 'symbol' in 'string ZeroSerializerGenerator.GetQualifiedViewName(INamedTypeSymbol symbol)'.

private static void EmitViewCollectionHeader(
GeneratedSourceBuilder sourceBuilder,
Expand Down
6 changes: 3 additions & 3 deletions tests-unity/UnityCompatibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@
&& variableView.OptionalState == PacketState.Ready
&& variableView.OptionalPosition!.Value.X == 30
&& variableView.MissingOptionalPosition is null
&& variableView.Child.Identifier == 99
&& variableView.Child?.Identifier == 99
&& variableView.StructChild.Identifier == 100
&& variableView.StructChild.Name.SequenceEqual("struct".AsSpan())
&& variableView.OptionalStructChild.Identifier == 101
&& variableView.OptionalStructChild.Name.SequenceEqual("optional struct".AsSpan())
&& variableView.OptionalStructChild?.Identifier == 101
&& variableView.OptionalStructChild?.Name.SequenceEqual("optional struct".AsSpan()) == true
&& variableView.FloatValues.Length == 3
&& variableView.FloatValues[1] == 2.5f
&& variableView.DoubleValues.Length == 3
Expand Down Expand Up @@ -267,7 +267,7 @@
public int? OptionalValue { get; init; }

public int? MissingOptionalValue { get; init; }

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

GitHub Actions / test (Release)

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

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

View workflow job for this annotation

GitHub Actions / test (Debug)

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

GitHub Actions / test (Debug)

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

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

View workflow job for this annotation

GitHub Actions / test (Release)

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

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

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

View workflow job for this annotation

GitHub Actions / test (Debug)

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

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

View workflow job for this annotation

GitHub Actions / test (Release)

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

public PackedPosition? OptionalPosition { get; init; }
Expand Down
24 changes: 12 additions & 12 deletions tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ public void VariableDataRoundTrip()

int expectedRequiredByteLength = -(24 + (4 * IntPtr.Size));
TestAssert.Equal(expectedRequiredByteLength, VariableRecordView.RequiredByteLength, nameof(VariableRecordView.RequiredByteLength));
TestAssert.Equal(source.Text, view.Text.ToString(), nameof(view.Text));
TestAssert.SequenceEqual<int>(source.Values, view.Values, nameof(view.Values));
TestAssert.Equal(source.OptionalNumber, view.OptionalNumber, nameof(view.OptionalNumber));
TestAssert.Equal(source.Child.Identifier, view.Child.Identifier, nameof(view.Child.Identifier));
TestAssert.Equal(source.Child.State, view.Child.State, nameof(view.Child.State));
TestAssert.Equal(source.Tail, view.Tail, nameof(view.Tail));
TestAssert.Equal(source.Text, view.Text.ToString(), nameof(source.Text));
TestAssert.SequenceEqual<int>(source.Values, view.Values, nameof(source.Values));
TestAssert.Equal(source.OptionalNumber, view.OptionalNumber, nameof(source.OptionalNumber));
TestAssert.Equal(source.Child.Identifier, view.Child?.Identifier ?? -1, nameof(source.Child.Identifier));
TestAssert.Equal(source.Child.State, view.Child?.State ?? ByteState.None, nameof(source.Child.State));
TestAssert.Equal(source.Tail, view.Tail, nameof(source.Tail));
int textFieldOffset = BinaryPrimitives.ReadInt32LittleEndian(buffer.AsSpan(0, 4));
int valuesFieldOffset = BinaryPrimitives.ReadInt32LittleEndian(buffer.AsSpan(4, 4));
int optionalNumberFieldOffset = BinaryPrimitives.ReadInt32LittleEndian(buffer.AsSpan(8, 4));
Expand Down Expand Up @@ -284,8 +284,8 @@ public void VariableViewOnlyRequiresCorrectSerializedStart()
TestAssert.Equal(source.Text, view.Text.ToString(), nameof(view.Text));
TestAssert.SequenceEqual<int>(source.Values, view.Values, nameof(view.Values));
TestAssert.Equal(source.OptionalNumber, view.OptionalNumber, nameof(view.OptionalNumber));
TestAssert.Equal(source.Child.Identifier, view.Child.Identifier, nameof(view.Child.Identifier));
TestAssert.Equal(source.Child.State, view.Child.State, nameof(view.Child.State));
TestAssert.Equal(source.Child.Identifier, view.Child?.Identifier ?? -1, nameof(FixedClassView.Identifier));
TestAssert.Equal(source.Child.State, view.Child?.State ?? ByteState.None, nameof(FixedClassView.State));
TestAssert.Equal(source.Tail, view.Tail, nameof(view.Tail));

ReadOnlyMemory<byte> borrowedSerializedMemory = view;
Expand Down Expand Up @@ -521,9 +521,9 @@ public void EveryTruncatedSerializedBufferThrowsStandardBoundsExceptionWhenRead(
_ = view.Text.Length;
_ = view.Values.Length;
_ = view.OptionalNumber;
FixedClassView childView = view.Child;
_ = childView.Identifier;
_ = childView.State;
FixedClassView? childView = view.Child;
_ = childView?.Identifier;
_ = childView?.State;
_ = view.Tail;
},
nameof(VariableRecord));
Expand Down Expand Up @@ -777,7 +777,7 @@ public void NestedTypesReturnViewsTest()
// 2. Assert that nested non-blittable type returns view
PropertyInfo? childProperty = typeof(VariableRecordView).GetProperty(nameof(VariableRecordView.Child));
Assert.NotNull(childProperty);
Assert.Equal(typeof(FixedClassView), childProperty!.PropertyType);
Assert.Equal(typeof(FixedClassView?), childProperty!.PropertyType);
}

public void StrictBlittableStructTests()
Expand Down
Loading