mirror of
https://github.com/oliverbooth/TcpDotNet
synced 2024-11-10 02:55:41 +00:00
fix: pass in not ref with net8.0 to MemoryMarshal.TryWrite
This commit is contained in:
parent
ed279cfd69
commit
32fecb5ace
@ -1,4 +1,4 @@
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -38,7 +38,11 @@ public sealed class ProtocolWriter : BinaryWriter
|
|||||||
public override void Write(double value)
|
public override void Write(double value)
|
||||||
{
|
{
|
||||||
Span<byte> buffer = stackalloc byte[8];
|
Span<byte> buffer = stackalloc byte[8];
|
||||||
|
#if NET8_0_OR_GREATER
|
||||||
|
MemoryMarshal.TryWrite(buffer, in value);
|
||||||
|
#else
|
||||||
MemoryMarshal.TryWrite(buffer, ref value);
|
MemoryMarshal.TryWrite(buffer, ref value);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (BitConverter.IsLittleEndian) buffer.Reverse();
|
if (BitConverter.IsLittleEndian) buffer.Reverse();
|
||||||
Write(buffer);
|
Write(buffer);
|
||||||
@ -89,7 +93,11 @@ public sealed class ProtocolWriter : BinaryWriter
|
|||||||
public override void Write(float value)
|
public override void Write(float value)
|
||||||
{
|
{
|
||||||
Span<byte> buffer = stackalloc byte[4];
|
Span<byte> buffer = stackalloc byte[4];
|
||||||
|
#if NET8_0_OR_GREATER
|
||||||
|
MemoryMarshal.TryWrite(buffer, in value);
|
||||||
|
#else
|
||||||
MemoryMarshal.TryWrite(buffer, ref value);
|
MemoryMarshal.TryWrite(buffer, ref value);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (BitConverter.IsLittleEndian) buffer.Reverse();
|
if (BitConverter.IsLittleEndian) buffer.Reverse();
|
||||||
Write(buffer);
|
Write(buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user