From 32fecb5ace202ed40d1178a194f705b1a6a7054c Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Mon, 12 Feb 2024 17:35:44 +0000 Subject: [PATCH] fix: pass in not ref with net8.0 to MemoryMarshal.TryWrite --- TcpDotNet/Protocol/ProtocolWriter.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/TcpDotNet/Protocol/ProtocolWriter.cs b/TcpDotNet/Protocol/ProtocolWriter.cs index 76280fe..138bee6 100644 --- a/TcpDotNet/Protocol/ProtocolWriter.cs +++ b/TcpDotNet/Protocol/ProtocolWriter.cs @@ -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 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 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);