Skip to content

Commit

Permalink
Use PayloadReader in System.Resources.Extensions (#102379)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jeremy Barton <jbarton@microsoft.com>
  • Loading branch information
3 people committed Jun 10, 2024
1 parent 3073a03 commit 82aba82
Show file tree
Hide file tree
Showing 160 changed files with 16,615 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "tools\ref", "{DB5983
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{7FF9B3DF-E383-4487-9ADB-E3BF59CFCE83}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Resources.Extensions.Compat.Tests", "tests\CompatTests\System.Resources.Extensions.Compat.Tests.csproj", "{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Resources.Extensions.BinaryFormat.Tests", "tests\BinaryFormatTests\System.Resources.Extensions.BinaryFormat.Tests.csproj", "{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -503,6 +507,66 @@ Global
{7E29F73C-D2DE-4DA4-B399-F6A2475A11EC}.Checked|arm64.ActiveCfg = Debug|Any CPU
{7E29F73C-D2DE-4DA4-B399-F6A2475A11EC}.Checked|x64.ActiveCfg = Debug|Any CPU
{7E29F73C-D2DE-4DA4-B399-F6A2475A11EC}.Checked|x86.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|Any CPU.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|arm.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|arm.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|arm64.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|arm64.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|x64.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|x64.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|x86.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Checked|x86.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|arm.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|arm.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|arm64.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|arm64.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|x64.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|x64.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|x86.ActiveCfg = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Debug|x86.Build.0 = Debug|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|Any CPU.Build.0 = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|arm.ActiveCfg = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|arm.Build.0 = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|arm64.ActiveCfg = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|arm64.Build.0 = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|x64.ActiveCfg = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|x64.Build.0 = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|x86.ActiveCfg = Release|Any CPU
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1}.Release|x86.Build.0 = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|Any CPU.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|Any CPU.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|arm.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|arm.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|arm64.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|arm64.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|x64.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|x64.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|x86.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Checked|x86.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|arm.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|arm.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|arm64.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|arm64.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|x64.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|x64.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|x86.ActiveCfg = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Debug|x86.Build.0 = Debug|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|Any CPU.Build.0 = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|arm.ActiveCfg = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|arm.Build.0 = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|arm64.ActiveCfg = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|arm64.Build.0 = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|x64.ActiveCfg = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|x64.Build.0 = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|x86.ActiveCfg = Release|Any CPU
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -531,6 +595,8 @@ Global
{BE197124-901B-4517-879B-93D0E6684A2C} = {7FF9B3DF-E383-4487-9ADB-E3BF59CFCE83}
{7E29F73C-D2DE-4DA4-B399-F6A2475A11EC} = {DB598308-6179-48EA-A670-0DA6CE5D8340}
{DB598308-6179-48EA-A670-0DA6CE5D8340} = {7FF9B3DF-E383-4487-9ADB-E3BF59CFCE83}
{BD76A85A-8E6F-4D4C-A628-661EFE6999F1} = {2195CD2B-EF9E-46A7-B4AA-A2CD31625957}
{4D72DCD5-BB24-47ED-9B98-8E0B49A9F314} = {2195CD2B-EF9E-46A7-B4AA-A2CD31625957}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E201426B-999F-48A5-BCFD-3E757AA0E182}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,70 @@
<data name="TypeLoadException_CannotLoadConverter" xml:space="preserve">
<value>Could not load a converter for type {0}.</value>
</data>
<data name="Serialization_ArrayContainedNulls" xml:space="preserve">
<value>The array contained null(s).</value>
</data>
<data name="Serialization_InvalidValue" xml:space="preserve">
<value>Invalid value: `{0}`.</value>
</data>
<data name="Serialization_UnexpectedNullRecordCount" xml:space="preserve">
<value>Unexpected Null Record count.</value>
</data>
<data name="Serialization_MaxArrayLength" xml:space="preserve">
<value>The serialized array length ({0}) was larger than the configured limit {1}.</value>
</data>
<data name="NotSupported_RecordType" xml:space="preserve">
<value>{0} Record Type is not supported by design.</value>
</data>
<data name="Serialization_InvalidReference" xml:space="preserve">
<value>Member reference was pointing to a record of unexpected type.</value>
</data>
<data name="Serialization_InvalidTypeName" xml:space="preserve">
<value>Invalid type name: `{0}`.</value>
</data>
<data name="Serialization_TypeMismatch" xml:space="preserve">
<value>Expected the array to be of type {0}, but its element type was {1}.</value>
</data>
<data name="NotSupported_NonZeroOffsets" xml:space="preserve">
<value>Only arrays with zero offsets are supported.</value>
</data>
<data name="Serialization_Cycle" xml:space="preserve">
<value>Unexpected parser cycle.</value>
</data>
<data name="Serialization_Incomplete" xml:space="preserve">
<value>Objects could not be deserialized completely.</value>
</data>
<data name="Serialization_IObjectReferenceOnlyPrimivite" xml:space="preserve">
<value>IObjectReference type '{0}' can only have primitive member data.</value>
</data>
<data name="Serialization_MissingCtor" xml:space="preserve">
<value>The constructor to deserialize an object of type '{0}' was not found.</value>
</data>
<data name="Serialization_MissingField" xml:space="preserve">
<value>Could not find field '{0}' data for type '{1}'.</value>
</data>
<data name="Serialization_MissingType" xml:space="preserve">
<value>Could not find type '{0}'.</value>
</data>
<data name="Serialization_Surrogates" xml:space="preserve">
<value>Surrogate must return the same object that was provided in the 'obj' parameter.</value>
</data>
<data name="Serialization_TypeNotSerializable" xml:space="preserve">
<value>Type '{0}' is not marked as serializable.</value>
</data>
<data name="Serialization_InvalidTypeOrAssemblyName" xml:space="preserve">
<value>Invalid type or assembly name: `{0},{1}`.</value>
</data>
<data name="Argument_NonSeekableStream" xml:space="preserve">
<value>Stream does not support seeking.</value>
</data>
<data name="Serialization_DuplicateMemberName" xml:space="preserve">
<value>Duplicate member name: `{0}`.</value>
</data>
<data name="Serialization_DuplicateSerializationRecordId" xml:space="preserve">
<value>Duplicate Serialization Record Id: `{0}`.</value>
</data>
<data name="Serialization_MemberTypeMismatchException" xml:space="preserve">
<value>Specified member '{0}' was not of the expected type.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,54 @@ System.Resources.Extensions.PreserializedResourceWriter</PackageDescription>
<Compile Include="System\Resources\Extensions\PreserializedResourceWriter.cs" />
<Compile Include="System\Resources\Extensions\SerializationFormat.cs" />
<Compile Include="System\Resources\Extensions\TypeNameComparer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.IParseState.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.ITypeResolver.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.Options.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.ParseState.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObject.TypeResolver.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\BinaryFormattedObjectExtensions.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Id.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\SerializationEvents.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\SerializationExtensions.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\SerializationInfoExtensions.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ArrayRecordDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ArrayUpdater.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ClassRecordDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ClassRecordFieldInfoDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ClassRecordSerializationInfoDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\Deserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\FieldValueUpdater.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\IDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ObjectRecordDeserializer.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\PendingSerializationInfo.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\SerializationInfoValueUpdater.cs" />
<Compile Include="System\Resources\Extensions\BinaryFormat\Deserializer\ValueUpdater.cs" />
<Compile Include="$(CoreLibSharedDir)System\Numerics\Hashing\HashHelpers.cs"
Link="System\Numerics\Hashing\HashHelpers.cs" />
</ItemGroup>

<!-- when System.Runtime.Serialization.BinaryFormat gets approved, this whole block will be repalced with a reference to package -->
<ItemGroup>
<Compile Include="$(LibrariesProjectRoot)\System.Runtime.Serialization.BinaryFormat\src\**\*.cs" />
<ProjectReference Include="$(LibrariesProjectRoot)\System.IO.Hashing\src\System.IO.Hashing.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)\System.Reflection.Metadata\src\System.Reflection.Metadata.csproj" />
<PackageReference Include="System.ValueTuple" Version="$(SystemValueTupleVersion)" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs"
Link="System\Diagnostics\CodeAnalysis\RequiresUnreferencedCodeAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs"
Link="System\Diagnostics\CodeAnalysis\UnconditionalSuppressMessageAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs"
Link="System\Diagnostics\CodeAnalysis\DynamicDependencyAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs"
Link="System\Diagnostics\CodeAnalysis\DynamicallyAccessedMembersAttribute.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs"
Link="System\Diagnostics\CodeAnalysis\DynamicallyAccessedMemberTypes.cs" />
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\RequiresDynamicCodeAttribute.cs"
Link="System\Diagnostics\CodeAnalysis\RequiresDynamicCodeAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.BinaryFormat;

namespace System.Resources.Extensions.BinaryFormat;

internal sealed partial class BinaryFormattedObject
{
/// <summary>
/// Parsing state.
/// </summary>
internal interface IParseState
{
BinaryReader Reader { get; }
IReadOnlyDictionary<int, SerializationRecord> RecordMap { get; }
Options Options { get; }
ITypeResolver TypeResolver { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Reflection.Metadata;

namespace System.Resources.Extensions.BinaryFormat;

internal sealed partial class BinaryFormattedObject
{
/// <summary>
/// Resolver for types.
/// </summary>
internal interface ITypeResolver
{
/// <summary>
/// Resolves the given type name against the specified library.
/// </summary>
[RequiresUnreferencedCode("Calls System.Reflection.Assembly.GetType(String)")]
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
Type GetType(TypeName typeName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters;

namespace System.Resources.Extensions.BinaryFormat;

#pragma warning disable SYSLIB0050 // Type or member is obsolete

internal sealed partial class BinaryFormattedObject
{
internal sealed class Options
{
/// <summary>
/// How exactly assembly names need to match for deserialization.
/// </summary>
public FormatterAssemblyStyle AssemblyMatching { get; set; } = FormatterAssemblyStyle.Simple;

/// <summary>
/// Type name binder.
/// </summary>
public SerializationBinder? Binder { get; set; }

/// <summary>
/// Optional type <see cref="ISerializationSurrogate"/> provider.
/// </summary>
public ISurrogateSelector? SurrogateSelector { get; set; }

/// <summary>
/// Streaming context.
/// </summary>
public StreamingContext StreamingContext { get; set; } = new(StreamingContextStates.All);
}
}

#pragma warning restore SYSLIB0050 // Type or member is obsolete
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.BinaryFormat;

namespace System.Resources.Extensions.BinaryFormat;

internal sealed partial class BinaryFormattedObject
{
/// <summary>
/// Parsing state for <see cref="BinaryFormattedObject"/>.
/// </summary>
internal sealed class ParseState : IParseState
{
private readonly BinaryFormattedObject _format;

public ParseState(BinaryReader reader, BinaryFormattedObject format)
{
Reader = reader;
_format = format;
}

public BinaryReader Reader { get; }
public IReadOnlyDictionary<int, SerializationRecord> RecordMap => _format.RecordMap;
public Options Options => _format._options;
public ITypeResolver TypeResolver => _format.TypeResolver;
}
}

0 comments on commit 82aba82

Please sign in to comment.