mirror of https://github.com/oliverbooth/X10D
refactor!: add Bytes suffix to IO methods
This commit is contained in:
parent
fc334d164c
commit
b7d9a255e5
|
@ -33,7 +33,7 @@ internal class DoubleTests
|
|||
|
||||
var expected = new byte[] { 0x40, 0x45, 0x40, 0, 0, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class DoubleTests
|
|||
|
||||
var expected = new byte[] { 0, 0, 0, 0, 0, 0x40, 0x45, 0x40 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ internal class DoubleTests
|
|||
{
|
||||
const double value = 42.5;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -61,6 +61,6 @@ internal class DoubleTests
|
|||
{
|
||||
const double value = 42.5;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ internal class Int16Tests
|
|||
|
||||
byte[] expected = { 0x0F, 0 };
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class Int16Tests
|
|||
|
||||
byte[] expected = { 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ internal class Int16Tests
|
|||
{
|
||||
const short value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -61,6 +61,6 @@ internal class Int16Tests
|
|||
{
|
||||
const short value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ internal class Int32Tests
|
|||
|
||||
var expected = new byte[] { 0, 0, 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class Int32Tests
|
|||
|
||||
var expected = new byte[] { 0x0F, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ internal class Int32Tests
|
|||
{
|
||||
const int value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -61,6 +61,6 @@ internal class Int32Tests
|
|||
{
|
||||
const int value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ internal class Int64Tests
|
|||
|
||||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class Int64Tests
|
|||
|
||||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ internal class Int64Tests
|
|||
{
|
||||
const long value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -61,6 +61,6 @@ internal class Int64Tests
|
|||
{
|
||||
const long value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ internal class SingleTests
|
|||
|
||||
var expected = new byte[] { 0x42, 0x2A, 0, 0 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ internal class SingleTests
|
|||
|
||||
var expected = new byte[] { 0, 0, 0x2A, 0x42 };
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ internal class SingleTests
|
|||
{
|
||||
const float value = 42.5f;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -61,6 +61,6 @@ internal class SingleTests
|
|||
{
|
||||
const float value = 42.5f;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using X10D.IO;
|
||||
|
||||
namespace X10D.Tests.IO;
|
||||
|
@ -33,7 +33,7 @@ internal class UInt16Tests
|
|||
byte[] expected = { 0x0F, 0 };
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ internal class UInt16Tests
|
|||
byte[] expected = { 0, 0x0F };
|
||||
|
||||
Span<byte> actual = stackalloc byte[2];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ internal class UInt16Tests
|
|||
{
|
||||
const ushort value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -63,6 +63,6 @@ internal class UInt16Tests
|
|||
{
|
||||
const ushort value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using X10D.IO;
|
||||
|
||||
namespace X10D.Tests.IO;
|
||||
|
@ -33,7 +33,7 @@ internal class UInt32Tests
|
|||
byte[] expected = { 0x0F, 0, 0, 0 };
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ internal class UInt32Tests
|
|||
byte[] expected = { 0, 0, 0, 0x0F };
|
||||
|
||||
Span<byte> actual = stackalloc byte[4];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ internal class UInt32Tests
|
|||
{
|
||||
const uint value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -63,6 +63,6 @@ internal class UInt32Tests
|
|||
{
|
||||
const uint value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using NUnit.Framework;
|
||||
using NUnit.Framework;
|
||||
using X10D.IO;
|
||||
|
||||
namespace X10D.Tests.IO;
|
||||
|
@ -33,7 +33,7 @@ internal class UInt64Tests
|
|||
byte[] expected = { 0x0F, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteLittleEndian(actual));
|
||||
Assert.That(value.TryWriteLittleEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ internal class UInt64Tests
|
|||
byte[] expected = { 0, 0, 0, 0, 0, 0, 0, 0x0F };
|
||||
|
||||
Span<byte> actual = stackalloc byte[8];
|
||||
Assert.That(value.TryWriteBigEndian(actual));
|
||||
Assert.That(value.TryWriteBigEndianBytes(actual));
|
||||
|
||||
CollectionAssert.AreEqual(expected, actual.ToArray());
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ internal class UInt64Tests
|
|||
{
|
||||
const ulong value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteLittleEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteLittleEndianBytes(buffer), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -63,6 +63,6 @@ internal class UInt64Tests
|
|||
{
|
||||
const ulong value = 0x0F;
|
||||
Span<byte> buffer = stackalloc byte[0];
|
||||
Assert.That(value.TryWriteBigEndian(buffer), Is.False);
|
||||
Assert.That(value.TryWriteBigEndianBytes(buffer), Is.False);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public static class DecimalExtensions
|
|||
public static byte[] GetBigEndianBytes(this decimal value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class DecimalExtensions
|
|||
public static byte[] GetLittleEndianBytes(this decimal value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -41,15 +41,15 @@ public static class DecimalExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this decimal value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this decimal value, Span<byte> destination)
|
||||
{
|
||||
Span<int> buffer = stackalloc int[4];
|
||||
GetBits(value, buffer);
|
||||
|
||||
if (buffer[0].TryWriteBigEndian(destination[..4]) &&
|
||||
buffer[1].TryWriteBigEndian(destination[4..8]) &&
|
||||
buffer[2].TryWriteBigEndian(destination[8..12]) &&
|
||||
buffer[3].TryWriteBigEndian(destination[12..]))
|
||||
if (buffer[0].TryWriteBigEndianBytes(destination[..4]) &&
|
||||
buffer[1].TryWriteBigEndianBytes(destination[4..8]) &&
|
||||
buffer[2].TryWriteBigEndianBytes(destination[8..12]) &&
|
||||
buffer[3].TryWriteBigEndianBytes(destination[12..]))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
@ -69,15 +69,15 @@ public static class DecimalExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this decimal value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this decimal value, Span<byte> destination)
|
||||
{
|
||||
Span<int> buffer = stackalloc int[4];
|
||||
GetBits(value, buffer);
|
||||
|
||||
if (buffer[0].TryWriteLittleEndian(destination[..4]) &&
|
||||
buffer[1].TryWriteLittleEndian(destination[4..8]) &&
|
||||
buffer[2].TryWriteLittleEndian(destination[8..12]) &&
|
||||
buffer[3].TryWriteLittleEndian(destination[12..]))
|
||||
if (buffer[0].TryWriteLittleEndianBytes(destination[..4]) &&
|
||||
buffer[1].TryWriteLittleEndianBytes(destination[4..8]) &&
|
||||
buffer[2].TryWriteLittleEndianBytes(destination[8..12]) &&
|
||||
buffer[3].TryWriteLittleEndianBytes(destination[12..]))
|
||||
{
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
|
@ -18,7 +18,7 @@ public static class DoubleExtensions
|
|||
public static byte[] GetBigEndianBytes(this double value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class DoubleExtensions
|
|||
public static byte[] GetLittleEndianBytes(this double value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public static class DoubleExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this double value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this double value, Span<byte> destination)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return BinaryPrimitives.TryWriteDoubleBigEndian(destination, value);
|
||||
|
@ -62,7 +62,7 @@ public static class DoubleExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this double value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this double value, Span<byte> destination)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return BinaryPrimitives.TryWriteDoubleLittleEndian(destination, value);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -17,7 +17,7 @@ public static class Int16Extensions
|
|||
public static byte[] GetBigEndianBytes(this short value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public static class Int16Extensions
|
|||
public static byte[] GetLittleEndianBytes(this short value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public static class Int16Extensions
|
|||
/// <param name="value">The <see cref="short" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this short value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this short value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt16BigEndian(destination, value);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public static class Int16Extensions
|
|||
/// <param name="value">The <see cref="short" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this short value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this short value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt16LittleEndian(destination, value);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -17,7 +17,7 @@ public static class Int32Extensions
|
|||
public static byte[] GetBigEndianBytes(this int value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public static class Int32Extensions
|
|||
public static byte[] GetLittleEndianBytes(this int value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public static class Int32Extensions
|
|||
/// <param name="value">The <see cref="int" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this int value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this int value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt32BigEndian(destination, value);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public static class Int32Extensions
|
|||
/// <param name="value">The <see cref="int" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this int value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this int value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt32LittleEndian(destination, value);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -17,7 +17,7 @@ public static class Int64Extensions
|
|||
public static byte[] GetBigEndianBytes(this long value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ public static class Int64Extensions
|
|||
public static byte[] GetLittleEndianBytes(this long value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public static class Int64Extensions
|
|||
/// <param name="value">The <see cref="long" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this long value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this long value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt64BigEndian(destination, value);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public static class Int64Extensions
|
|||
/// <param name="value">The <see cref="long" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this long value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this long value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteInt64LittleEndian(destination, value);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
#if !NET5_0_OR_GREATER
|
||||
using System.Runtime.InteropServices;
|
||||
|
@ -20,7 +20,7 @@ public static class SingleExtensions
|
|||
public static byte[] GetBigEndianBytes(this float value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public static class SingleExtensions
|
|||
public static byte[] GetLittleEndianBytes(this float value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public static class SingleExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this float value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this float value, Span<byte> destination)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return BinaryPrimitives.TryWriteSingleBigEndian(destination, value);
|
||||
|
@ -64,7 +64,7 @@ public static class SingleExtensions
|
|||
/// <param name="value">The <see cref="float" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this float value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this float value, Span<byte> destination)
|
||||
{
|
||||
#if NET5_0_OR_GREATER
|
||||
return BinaryPrimitives.TryWriteSingleLittleEndian(destination, value);
|
||||
|
|
|
@ -25,7 +25,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -101,7 +101,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -178,7 +178,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[16];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -305,7 +305,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -330,7 +330,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -356,7 +356,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
@ -382,7 +382,7 @@ public static partial class StreamExtensions
|
|||
}
|
||||
|
||||
Span<byte> buffer = stackalloc byte[16];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return stream.WriteInternal(buffer);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -18,7 +18,7 @@ public static class UInt16Extensions
|
|||
public static byte[] GetBigEndianBytes(this ushort value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class UInt16Extensions
|
|||
public static byte[] GetLittleEndianBytes(this ushort value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[2];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public static class UInt16Extensions
|
|||
/// <param name="value">The <see cref="ushort" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this ushort value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this ushort value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt16BigEndian(destination, value);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public static class UInt16Extensions
|
|||
/// <param name="value">The <see cref="ushort" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this ushort value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this ushort value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt16LittleEndian(destination, value);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -18,7 +18,7 @@ public static class UInt32Extensions
|
|||
public static byte[] GetBigEndianBytes(this uint value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class UInt32Extensions
|
|||
public static byte[] GetLittleEndianBytes(this uint value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[4];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public static class UInt32Extensions
|
|||
/// <param name="value">The <see cref="uint" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this uint value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this uint value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt32BigEndian(destination, value);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public static class UInt32Extensions
|
|||
/// <param name="value">The <see cref="uint" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this uint value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this uint value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt32LittleEndian(destination, value);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Buffers.Binary;
|
||||
using System.Buffers.Binary;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace X10D.IO;
|
||||
|
@ -18,7 +18,7 @@ public static class UInt64Extensions
|
|||
public static byte[] GetBigEndianBytes(this ulong value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteBigEndian(buffer);
|
||||
value.TryWriteBigEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ public static class UInt64Extensions
|
|||
public static byte[] GetLittleEndianBytes(this ulong value)
|
||||
{
|
||||
Span<byte> buffer = stackalloc byte[8];
|
||||
value.TryWriteLittleEndian(buffer);
|
||||
value.TryWriteLittleEndianBytes(buffer);
|
||||
return buffer.ToArray();
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ public static class UInt64Extensions
|
|||
/// <param name="value">The <see cref="ulong" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as big endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteBigEndian(this ulong value, Span<byte> destination)
|
||||
public static bool TryWriteBigEndianBytes(this ulong value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt64BigEndian(destination, value);
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ public static class UInt64Extensions
|
|||
/// <param name="value">The <see cref="ulong" /> value.</param>
|
||||
/// <param name="destination">The span of bytes where the value is to be written, as little endian.</param>
|
||||
/// <returns><see langword="true" /> if the conversion was successful; otherwise, <see langword="false" />.</returns>
|
||||
public static bool TryWriteLittleEndian(this ulong value, Span<byte> destination)
|
||||
public static bool TryWriteLittleEndianBytes(this ulong value, Span<byte> destination)
|
||||
{
|
||||
return BinaryPrimitives.TryWriteUInt64LittleEndian(destination, value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue