Skip to content

Commit

Permalink
Add ifdef for missing BitConverter.Int32BitsToSingle on ns2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NinoFloris committed Mar 28, 2024
1 parent 1b93828 commit 6927b98
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Npgsql/Internal/NpgsqlReadBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,20 @@ public ulong ReadUInt64()
public float ReadSingle()
{
CheckBounds(sizeof(float));
#if NETSTANDARD2_0
float result;
if (BitConverter.IsLittleEndian)
{
var value = BinaryPrimitives.ReverseEndianness(Unsafe.ReadUnaligned<int>(ref Buffer[ReadPosition]));
result = Unsafe.As<int, float>(ref value);
}
else
result = Unsafe.ReadUnaligned<float>(ref Buffer[ReadPosition]);
#else
var result = BitConverter.IsLittleEndian
? BitConverter.Int32BitsToSingle(BinaryPrimitives.ReverseEndianness(Unsafe.ReadUnaligned<int>(ref Buffer[ReadPosition])))
: Unsafe.ReadUnaligned<float>(ref Buffer[ReadPosition]);
#endif
ReadPosition += sizeof(float);
return result;
}
Expand Down

0 comments on commit 6927b98

Please sign in to comment.