Skip to content

Commit

Permalink
Align BitConverter/BinaryPrimitives usage netfx/netcore
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelZ committed Nov 2, 2024
1 parent 9d5ca32 commit a2a39e4
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Buffers;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
Expand Down Expand Up @@ -4396,8 +4397,8 @@ private TdsOperationStatus TryProcessFedAuthInfo(TdsParserStateObject stateObj,
uint currentOptionOffset = checked(i * optionSize);

byte id = tokenData[currentOptionOffset];
uint dataLen = BitConverter.ToUInt32(tokenData, checked((int)(currentOptionOffset + 1)));
uint dataOffset = BitConverter.ToUInt32(tokenData, checked((int)(currentOptionOffset + 5)));
uint dataLen = BinaryPrimitives.ReadUInt32LittleEndian(tokenData.AsSpan(checked((int)(currentOptionOffset + 1))));
uint dataOffset = BinaryPrimitives.ReadUInt32LittleEndian(tokenData.AsSpan(checked((int)(currentOptionOffset + 5))));
if (SqlClientEventSource.Log.IsAdvancedTraceOn())
{
SqlClientEventSource.Log.AdvancedTraceEvent("<sc.TdsParser.TryProcessFedAuthInfo> FedAuthInfoOpt: ID={0}, DataLen={1}, Offset={2}", id, dataLen.ToString(CultureInfo.InvariantCulture), dataOffset.ToString(CultureInfo.InvariantCulture));
Expand Down Expand Up @@ -6824,7 +6825,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

longValue = BitConverter.ToInt64(unencryptedBytes, 0);
longValue = BinaryPrimitives.ReadInt64LittleEndian(unencryptedBytes);

if (tdsType == TdsEnums.SQLBIT ||
tdsType == TdsEnums.SQLBITN)
Expand Down Expand Up @@ -6862,7 +6863,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

singleValue = BitConverter.ToSingle(unencryptedBytes, 0);
singleValue = BitConverterCompatible.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes));
value.Single = singleValue;
break;

Expand All @@ -6873,7 +6874,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

doubleValue = BitConverter.ToDouble(unencryptedBytes, 0);
doubleValue = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(unencryptedBytes));
value.Double = doubleValue;
break;

Expand All @@ -6890,8 +6891,8 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

mid = BitConverter.ToInt32(unencryptedBytes, 0);
lo = BitConverter.ToUInt32(unencryptedBytes, 4);
mid = BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes);
lo = BinaryPrimitives.ReadUInt32LittleEndian(unencryptedBytes.AsSpan(4));

long l = (((long)mid) << 0x20) + ((long)lo);
value.SetToMoney(l);
Expand Down Expand Up @@ -6928,8 +6929,8 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

daypart = BitConverter.ToInt32(unencryptedBytes, 0);
timepart = BitConverter.ToUInt32(unencryptedBytes, 4);
daypart = BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes);
timepart = BinaryPrimitives.ReadUInt32LittleEndian(unencryptedBytes.AsSpan(4));
value.SetToDateTime(daypart, (int)timepart);
break;

Expand Down

0 comments on commit a2a39e4

Please sign in to comment.