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: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<PackageVersion Include="Microsoft.TestPlatform.TranslationLayer" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.0.0" />
<PackageVersion Include="Polyfill" Version="9.0.0-beta.10" />
<PackageVersion Include="Polyfill" Version="9.0.0-beta.12" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
</ItemGroup>
<ItemGroup Label="Test dependencies">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ internal abstract class BaseSerializer
protected static string ReadString(Stream stream)
{
Span<byte> len = stackalloc byte[sizeof(int)];
#if NET7_0_OR_GREATER
stream.ReadExactly(len);
#else
_ = stream.Read(len);
#endif
int stringLen = BitConverter.ToInt32(len);
byte[] bytes = ArrayPool<byte>.Shared.Rent(stringLen);
try
{
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes, 0, stringLen);
#else
_ = stream.Read(bytes, 0, stringLen);
#endif
return Encoding.UTF8.GetString(bytes, 0, stringLen);
}
finally
Expand All @@ -45,11 +37,7 @@ protected static string ReadStringValue(Stream stream, int size)
byte[] bytes = ArrayPool<byte>.Shared.Rent(size);
try
{
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes, 0, size);
#else
_ = stream.Read(bytes, 0, size);
#endif
return Encoding.UTF8.GetString(bytes, 0, size);
}
finally
Expand Down Expand Up @@ -148,44 +136,28 @@ protected static void WriteBool(Stream stream, bool value)
protected static int ReadInt(Stream stream)
{
Span<byte> bytes = stackalloc byte[sizeof(int)];
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes);
#else
_ = stream.Read(bytes);
#endif
return BitConverter.ToInt32(bytes);
}

protected static long ReadLong(Stream stream)
{
Span<byte> bytes = stackalloc byte[sizeof(long)];
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes);
#else
_ = stream.Read(bytes);
#endif
return BitConverter.ToInt64(bytes);
}

protected static ushort ReadShort(Stream stream)
{
Span<byte> bytes = stackalloc byte[sizeof(ushort)];
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes);
#else
_ = stream.Read(bytes);
#endif
return BitConverter.ToUInt16(bytes);
}

protected static bool ReadBool(Stream stream)
{
Span<byte> bytes = stackalloc byte[sizeof(bool)];
#if NET7_0_OR_GREATER
stream.ReadExactly(bytes);
#else
_ = stream.Read(bytes);
#endif
return BitConverter.ToBoolean(bytes);
}

Expand Down