Commit d1ff29ea authored by Ray Koopa's avatar Ray Koopa

Use Spans for ByteConverters. Prepare for 5.0.0 release.

parent a0018dda
......@@ -36,17 +36,17 @@ namespace Syroot.BinaryData
else if (valueType == typeof(SByte))
Buffer[0] = (byte)(sbyte)value;
else if (valueType == typeof(Int16))
converter.GetBytes((Int16)value, buffer, 0);
converter.GetBytes((Int16)value, buffer);
else if (valueType == typeof(Int32))
converter.GetBytes((Int32)value, buffer, 0);
converter.GetBytes((Int32)value, buffer);
else if (valueType == typeof(Int64))
converter.GetBytes((Int64)value, buffer, 0);
converter.GetBytes((Int64)value, buffer);
else if (valueType == typeof(UInt16))
converter.GetBytes((UInt16)value, buffer, 0);
converter.GetBytes((UInt16)value, buffer);
else if (valueType == typeof(UInt32))
converter.GetBytes((UInt32)value, buffer, 0);
converter.GetBytes((UInt32)value, buffer);
else if (valueType == typeof(UInt64))
converter.GetBytes((UInt64)value, buffer, 0);
converter.GetBytes((UInt64)value, buffer);
else
throw new NotImplementedException($"Unsupported enum type {valueType}.");
......
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>Syroot.BinaryData.Serialization</AssemblyName>
<AssemblyTitle>BinaryData Serialization</AssemblyTitle>
<Authors>Syroot</Authors>
<Configurations>Debug;Release;Release (Signed)</Configurations>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
<Copyright>(c) Syroot, licensed under MIT</Copyright>
<Description>.NET library automating binary serialization of classes and structs.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
......@@ -17,14 +17,15 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Syroot/BinaryData</RepositoryUrl>
<TargetFrameworks>net452;netstandard20</TargetFrameworks>
<VersionPrefix>5.0.0-alpha1</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<AssemblyOriginatorKeyFile>Syroot.BinaryData.Serialization.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Syroot.BinaryData\Syroot.BinaryData.csproj" />
</ItemGroup>
<!-- Release (Signed) -->
<PropertyGroup Condition="'$(Configuration)' == 'Release (Signed)'">
<PropertyGroup Condition="'$(Configuration)' == 'ReleaseSigned'">
<AssemblyOriginatorKeyFile>Syroot.BinaryData.Serialization.pfx</AssemblyOriginatorKeyFile>
<PackageId>Syroot.BinaryData.Serialization.Signed</PackageId>
<SignAssembly>true</SignAssembly>
......
......@@ -121,7 +121,7 @@ namespace Syroot.BinaryData
attrib = attrib ?? new BinaryMemberAttribute();
// Field must be decorated or public.
if (hasAttrib || (!Attribute.Explicit && field.IsPublic))
if (hasAttrib || !Attribute.Explicit && field.IsPublic)
{
// For fields of enumerable type ElementCount must be specified.
if (field.FieldType.IsEnumerable() && attrib.Length <= 0)
......@@ -157,7 +157,7 @@ namespace Syroot.BinaryData
}
// Property must be decorated or getter and setter public.
if (hasAttrib
|| (!Attribute.Explicit && prop.GetMethod?.IsPublic == true && prop.SetMethod?.IsPublic == true))
|| !Attribute.Explicit && prop.GetMethod?.IsPublic == true && prop.SetMethod?.IsPublic == true)
{
// For properties of enumerable type ElementCount must be specified.
if (prop.PropertyType.IsEnumerable() && attrib.Length <= 0)
......
......@@ -14,34 +14,34 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release (Signed)|Any CPU = Release (Signed)|Any CPU
Release|Any CPU = Release|Any CPU
ReleaseSigned|Any CPU = ReleaseSigned|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Release (Signed)|Any CPU.ActiveCfg = Release (Signed)|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Release (Signed)|Any CPU.Build.0 = Release (Signed)|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.Release|Any CPU.Build.0 = Release|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU
{89B34252-236F-401B-B3FD-D48C9ABD7139}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Release (Signed)|Any CPU.ActiveCfg = Release|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Release (Signed)|Any CPU.Build.0 = Release|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.Release|Any CPU.Build.0 = Release|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU
{AEF72396-F3E0-49EB-A45B-3F666B6039E5}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Release (Signed)|Any CPU.ActiveCfg = Release (Signed)|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Release (Signed)|Any CPU.Build.0 = Release (Signed)|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.Release|Any CPU.Build.0 = Release|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.ReleaseSigned|Any CPU.ActiveCfg = ReleaseSigned|Any CPU
{CCE887C9-DB18-401A-91F4-DF3BC4442E68}.ReleaseSigned|Any CPU.Build.0 = ReleaseSigned|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Release (Signed)|Any CPU.ActiveCfg = Release|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Release (Signed)|Any CPU.Build.0 = Release|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.Release|Any CPU.Build.0 = Release|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.ReleaseSigned|Any CPU.ActiveCfg = Release|Any CPU
{CBB0637C-986F-4399-8689-F4F22027D973}.ReleaseSigned|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
using System;
using System.Runtime.InteropServices;
using System.Security;
namespace Syroot.BinaryData
{
/// <summary>
/// Represents a <see cref="ByteConverter"/> which handles system endianness.
/// </summary>
[SecuritySafeCritical]
public sealed class ByteConverterSystem : ByteConverter
{
// ---- FIELDS -------------------------------------------------------------------------------------------------
private readonly Endian _systemEndianness = BitConverter.IsLittleEndian ? Endian.Little : Endian.Big;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
/// <summary>
/// Gets the <see cref="BinaryData.Endian"/> in which data is stored as converted by this instance.
/// </summary>
public override Endian Endian => _systemEndianness;
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
/// <summary>
/// Stores the specified <see cref="Double"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(Double value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(Double)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="Int16"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(Int16 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(Int16)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="Int32"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(Int32 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(Int32)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="Int64"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(Int64 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(Int64)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="Single"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(Single value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(Single)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="UInt16"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(UInt16 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(UInt16)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="UInt32"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(UInt32 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(UInt32)).CopyTo(buffer);
/// <summary>
/// Stores the specified <see cref="UInt64"/> value as bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="value">The value to convert.</param>
/// <param name="buffer">The byte array to store the value in.</param>
[SecuritySafeCritical]
public override unsafe void GetBytes(UInt64 value, Span<byte> buffer)
=> new Span<byte>(&value, sizeof(UInt64)).CopyTo(buffer);
/// <summary>
/// Returns an <see cref="Double"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override Double ToDouble(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, Double>(buffer)[0];
/// <summary>
/// Returns an <see cref="Int16"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override Int16 ToInt16(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, Int16>(buffer)[0];
/// <summary>
/// Returns an <see cref="Int32"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override Int32 ToInt32(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, Int32>(buffer)[0];
/// <summary>
/// Returns an <see cref="Int64"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override Int64 ToInt64(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, Int64>(buffer)[0];
/// <summary>
/// Returns an <see cref="Single"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override Single ToSingle(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, Single>(buffer)[0];
/// <summary>
/// Returns an <see cref="UInt16"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override UInt16 ToUInt16(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, UInt16>(buffer)[0];
/// <summary>
/// Returns an <see cref="UInt32"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override UInt32 ToUInt32(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, UInt32>(buffer)[0];
/// <summary>
/// Returns an <see cref="UInt64"/> instance converted from the bytes in the given <paramref name="buffer"/>.
/// </summary>
/// <param name="buffer">The byte array storing the raw data.</param>
/// <returns>The converted value.</returns>
public override UInt64 ToUInt64(ReadOnlySpan<byte> buffer) => MemoryMarshal.Cast<byte, UInt64>(buffer)[0];
}
}
......@@ -105,12 +105,12 @@ namespace Syroot.BinaryData
break;
case BooleanCoding.Word:
buffer = Buffer;
converter.GetBytes((Int16)(value ? 1 : 0), buffer, 0);
converter.GetBytes((Int16)(value ? 1 : 0), buffer);
stream.Write(Buffer, 0, sizeof(Int16));
break;
case BooleanCoding.Dword:
buffer = Buffer;
converter.GetBytes(value ? 1 : 0, buffer, 0);
converter.GetBytes(value ? 1 : 0, buffer);
stream.Write(Buffer, 0, sizeof(Int32));
break;
default:
......@@ -139,12 +139,12 @@ namespace Syroot.BinaryData
break;
case BooleanCoding.Word:
buffer = Buffer;
converter.GetBytes((Int16)(value ? 1 : 0), buffer, 0);
converter.GetBytes((Int16)(value ? 1 : 0), buffer);
await stream.WriteAsync(Buffer, 0, sizeof(Int16), cancellationToken);
break;
case BooleanCoding.Dword:
buffer = Buffer;
converter.GetBytes(value ? 1 : 0, buffer, 0);
converter.GetBytes(value ? 1 : 0, buffer);
await stream.WriteAsync(Buffer, 0, sizeof(Int32), cancellationToken);
break;
default:
......
......@@ -72,7 +72,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Decimal value)
{
byte[] buffer = Buffer;
ByteConverter.GetBytes(value, buffer, 0);
ByteConverter.GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Decimal));
}
......@@ -86,7 +86,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
ByteConverter.GetBytes(value, buffer, 0);
ByteConverter.GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Decimal), cancellationToken);
}
......
......@@ -81,7 +81,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Double value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Double));
}
......@@ -109,7 +109,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Double), cancellationToken);
}
......
......@@ -440,32 +440,32 @@ namespace Syroot.BinaryData
}
else if (valueType == typeof(Int16))
{
converter.GetBytes((Int16)value, buffer, 0);
converter.GetBytes((Int16)value, buffer);
return sizeof(Int16);
}
else if (valueType == typeof(Int32))
{
converter.GetBytes((Int32)value, buffer, 0);
converter.GetBytes((Int32)value, buffer);
return sizeof(Int32);
}
else if (valueType == typeof(Int64))
{
converter.GetBytes((Int64)value, buffer, 0);
converter.GetBytes((Int64)value, buffer);
return sizeof(Int64);
}
else if (valueType == typeof(UInt16))
{
converter.GetBytes((UInt16)value, buffer, 0);
converter.GetBytes((UInt16)value, buffer);
return sizeof(UInt16);
}
else if (valueType == typeof(UInt32))
{
converter.GetBytes((UInt32)value, buffer, 0);
converter.GetBytes((UInt32)value, buffer);
return sizeof(UInt32);
}
else if (valueType == typeof(UInt64))
{
converter.GetBytes((UInt64)value, buffer, 0);
converter.GetBytes((UInt64)value, buffer);
return sizeof(UInt64);
}
else
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Int16 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Int16));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Int16), cancellationToken);
}
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Int32 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Int32));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Int32), cancellationToken);
}
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Int64 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Int64));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Int64), cancellationToken);
}
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, Single value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(Single));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(Single), cancellationToken);
}
......
......@@ -230,12 +230,12 @@ namespace Syroot.BinaryData
stream.Write(textBuffer, 0, textBuffer.Length);
break;
case StringCoding.Int16CharCount:
converter.GetBytes((Int16)value.Length, Buffer, 0);
converter.GetBytes((Int16)value.Length, Buffer);
stream.Write(Buffer, 0, sizeof(Int16));
stream.Write(textBuffer, 0, textBuffer.Length);
break;
case StringCoding.Int32CharCount:
converter.GetBytes(value.Length, Buffer, 0);
converter.GetBytes(value.Length, Buffer);
stream.Write(Buffer, 0, sizeof(Int32));
stream.Write(textBuffer, 0, textBuffer.Length);
break;
......@@ -309,12 +309,12 @@ namespace Syroot.BinaryData
await stream.WriteAsync(textBuffer, 0, textBuffer.Length, cancellationToken);
break;
case StringCoding.Int16CharCount:
converter.GetBytes((Int16)value.Length, Buffer, 0);
converter.GetBytes((Int16)value.Length, Buffer);
await stream.WriteAsync(Buffer, 0, sizeof(Int16), cancellationToken);
await stream.WriteAsync(textBuffer, 0, textBuffer.Length, cancellationToken);
break;
case StringCoding.Int32CharCount:
converter.GetBytes(value.Length, Buffer, 0);
converter.GetBytes(value.Length, Buffer);
await stream.WriteAsync(Buffer, 0, sizeof(Int32), cancellationToken);
await stream.WriteAsync(textBuffer, 0, textBuffer.Length, cancellationToken);
break;
......@@ -463,7 +463,7 @@ namespace Syroot.BinaryData
builder.Append(charBuffer, 0, charsDecoded);
}
}
} while ((lengthInChars && builder.Length < length) || (!lengthInChars && totalBytesRead < length));
} while (lengthInChars && builder.Length < length || !lengthInChars && totalBytesRead < length);
}
return builder.ToString();
}
......@@ -498,7 +498,7 @@ namespace Syroot.BinaryData
builder.Append(charBuffer, 0, charsDecoded);
}
}
} while ((lengthInChars && builder.Length < length) || (!lengthInChars && totalBytesRead < length));
} while (lengthInChars && builder.Length < length || !lengthInChars && totalBytesRead < length);
return builder.ToString();
}
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, UInt16 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(UInt16));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(UInt16), cancellationToken);
}
......
......@@ -79,7 +79,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, UInt32 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(UInt32));
}
......@@ -107,7 +107,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(UInt32), cancellationToken);
}
......
......@@ -78,7 +78,7 @@ namespace Syroot.BinaryData
public static void Write(this Stream stream, UInt64 value, ByteConverter converter = null)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
stream.Write(buffer, 0, sizeof(UInt64));
}
......@@ -106,7 +106,7 @@ namespace Syroot.BinaryData
CancellationToken cancellationToken = default)
{
byte[] buffer = Buffer;
(converter ?? ByteConverter.System).GetBytes(value, buffer, 0);
(converter ?? ByteConverter.System).GetBytes(value, buffer);
await stream.WriteAsync(buffer, 0, sizeof(UInt64), cancellationToken);
}
......
......@@ -4,7 +4,7 @@
<AssemblyName>Syroot.BinaryData</AssemblyName>
<AssemblyTitle>BinaryData</AssemblyTitle>
<Authors>Syroot</Authors>
<Configurations>Debug;Release;Release (Signed)</Configurations>
<Configurations>Debug;Release;ReleaseSigned</Configurations>
<Copyright>(c) Syroot, licensed under MIT</Copyright>
<Description>.NET library extending binary reading and writing functionality.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
......@@ -18,13 +18,17 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Syroot/BinaryData</RepositoryUrl>
<TargetFrameworks>net452;netstandard20</TargetFrameworks>
<VersionPrefix>5.0.0-beta1</VersionPrefix>
<VersionPrefix>5.0.0</VersionPrefix>
<AssemblyOriginatorKeyFile>Syroot.BinaryData.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<!-- Release (Signed) -->
<PropertyGroup Condition="'$(Configuration)' == 'Release (Signed)'">
<PropertyGroup Condition="'$(Configuration)' == 'ReleaseSigned'">
<AssemblyOriginatorKeyFile>Syroot.BinaryData.pfx</AssemblyOriginatorKeyFile>
<PackageId>Syroot.BinaryData.Signed</PackageId>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>
</Project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment