1
0
mirror of https://github.com/oliverbooth/TcpDotNet synced 2024-11-09 23:25:42 +00:00

fix: pass in not ref with net8.0 to MemoryMarshal.TryWrite

This commit is contained in:
Oliver Booth 2024-02-12 17:35:44 +00:00
parent ed279cfd69
commit 32fecb5ace
Signed by: oliverbooth
GPG Key ID: E60B570D1B7557B5

View File

@ -1,4 +1,4 @@
using System.Net;
using System.Net;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
@ -38,7 +38,11 @@ public sealed class ProtocolWriter : BinaryWriter
public override void Write(double value)
{
Span<byte> buffer = stackalloc byte[8];
#if NET8_0_OR_GREATER
MemoryMarshal.TryWrite(buffer, in value);
#else
MemoryMarshal.TryWrite(buffer, ref value);
#endif
if (BitConverter.IsLittleEndian) buffer.Reverse();
Write(buffer);
@ -89,7 +93,11 @@ public sealed class ProtocolWriter : BinaryWriter
public override void Write(float value)
{
Span<byte> buffer = stackalloc byte[4];
#if NET8_0_OR_GREATER
MemoryMarshal.TryWrite(buffer, in value);
#else
MemoryMarshal.TryWrite(buffer, ref value);
#endif
if (BitConverter.IsLittleEndian) buffer.Reverse();
Write(buffer);