Skip to content

Commit

Permalink
update common code tdsstateparserobject
Browse files Browse the repository at this point in the history
revert some changes

Update TdsParserStateObject.cs

change bitconvertercompat to bitconvertercompatible
  • Loading branch information
saitama951 committed Dec 7, 2023
1 parent 6425b2a commit 499bae3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 16 deletions.
Expand Up @@ -33,6 +33,9 @@
<Compile Include="..\..\src\Microsoft\Data\Common\AdapterUtil.cs">
<Link>Microsoft\Data\Common\AdapterUtil.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Common\BitConverterCompatible.cs">
<Link>Microsoft\Data\Common\BitConverterCompatible.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Common\DbConnectionOptions.Common.cs">
<Link>Microsoft\Data\Common\DbConnectionOptions.Common.cs</Link>
</Compile>
Expand Down Expand Up @@ -623,7 +626,6 @@
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.cs" />
<Compile Include="Microsoft\Data\SqlClient\AAsyncCallContext.cs" />
<Compile Include="Microsoft\Data\SqlClient\AlwaysEncryptedHelperClasses.cs" />
<Compile Include="Microsoft\Data\SqlClient\BitConverterCompat.cs"/>
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
<Compile Include="Microsoft\Data\SqlClient\Reliability\SqlConfigurableRetryLogicManager.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\ConcurrentQueueSemaphore.cs" />
Expand Down Expand Up @@ -1009,4 +1011,4 @@
<Import Project="$(ToolsDir)targets\ResolveContract.targets" Condition="'$(OSGroup)' == 'AnyOS'" />
<Import Project="$(ToolsDir)targets\NotSupported.targets" Condition="'$(OSGroup)' == 'AnyOS'" />
<Import Project="..\..\src\tools\targets\GenerateResourceStringsSource.targets" />
</Project>
</Project>
Expand Up @@ -14,7 +14,7 @@ internal sealed partial class TdsParser

internal static void FillDoubleBytes(double value, Span<byte> buffer) => BinaryPrimitives.TryWriteInt64LittleEndian(buffer, BitConverter.DoubleToInt64Bits(value));

internal static void FillFloatBytes(float value, Span<byte> buffer) => BinaryPrimitives.TryWriteInt32LittleEndian(buffer, BitConverterCompat.SingleToInt32Bits(value));
internal static void FillFloatBytes(float value, Span<byte> buffer) => BinaryPrimitives.TryWriteInt32LittleEndian(buffer, BitConverterCompatible.SingleToInt32Bits(value));

internal static Guid ConstructGuid(ReadOnlySpan<byte> bytes)
{
Expand Down
Expand Up @@ -1781,7 +1781,7 @@ internal byte[] SerializeFloat(float v)
}

var bytes = new byte[4];
BinaryPrimitives.WriteInt32LittleEndian(bytes, BitConverterCompat.SingleToInt32Bits(v));
BinaryPrimitives.WriteInt32LittleEndian(bytes, BitConverterCompatible.SingleToInt32Bits(v));
return bytes;
}

Expand Down Expand Up @@ -5842,7 +5842,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
return false;
}

singleValue = BitConverterCompat.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes));
singleValue = BitConverterCompatible.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(unencryptedBytes));
value.Single = singleValue;
break;

Expand Down
Expand Up @@ -279,7 +279,6 @@ internal void StartSession(object cancellationOwner)
_cancellationOwner.Target = cancellationOwner;
}


/////////////////////////////////////////
// Value Skip Logic //
/////////////////////////////////////////
Expand Down
Expand Up @@ -95,6 +95,9 @@
<Compile Include="..\..\src\Microsoft\Data\Common\AdapterUtil.Windows.cs">
<Link>Microsoft\Data\Common\AdapterUtil.Windows.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Common\BitConverterCompatible.cs">
<Link>Microsoft\Data\Common\BitConverterCompatible.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\Common\DbConnectionStringCommon.cs">
<Link>Microsoft\Data\Common\DbConnectionStringCommon.cs</Link>
</Compile>
Expand Down
Expand Up @@ -4,7 +4,7 @@

namespace Microsoft.Data.SqlClient
{
internal static class BitConverterCompat
internal static class BitConverterCompatible
{
public static unsafe int SingleToInt32Bits(float value)
{
Expand Down
Expand Up @@ -1373,7 +1373,7 @@ internal bool TryReadInt64(out long value)
Debug.Assert(_bTmpRead + bytesRead == 8, "TryReadByteArray returned true without reading all data required");
_bTmpRead = 0;
AssertValidState();
value = BitConverter.ToInt64(_bTmp, 0);
value = BinaryPrimitives.ReadInt64LittleEndian(_bTmp);
return true;
}
}
Expand All @@ -1382,7 +1382,7 @@ internal bool TryReadInt64(out long value)
// The entire long is in the packet and in the buffer, so just return it
// and take care of the counters.

value = BitConverter.ToInt64(_inBuff, _inBytesUsed);
value = BinaryPrimitives.ReadInt64LittleEndian(_inBuff.AsSpan(_inBytesUsed));

_inBytesUsed += 8;
_inBytesPacket -= 8;
Expand Down Expand Up @@ -1452,7 +1452,7 @@ internal bool TryReadUInt32(out uint value)
Debug.Assert(_bTmpRead + bytesRead == 4, "TryReadByteArray returned true without reading all data required");
_bTmpRead = 0;
AssertValidState();
value = BitConverter.ToUInt32(_bTmp, 0);
value = BinaryPrimitives.ReadUInt32LittleEndian(_bTmp);
return true;
}
}
Expand All @@ -1461,7 +1461,7 @@ internal bool TryReadUInt32(out uint value)
// The entire int is in the packet and in the buffer, so just return it
// and take care of the counters.

value = BitConverter.ToUInt32(_inBuff, _inBytesUsed);
value = BinaryPrimitives.ReadUInt32LittleEndian(_inBuff.AsSpan(_inBytesUsed));

_inBytesUsed += 4;
_inBytesPacket -= 4;
Expand All @@ -1487,15 +1487,15 @@ internal bool TryReadSingle(out float value)
}

AssertValidState();
value = BitConverter.ToSingle(_bTmp, 0);
value = BitConverterCompatible.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(_bTmp));
return true;
}
else
{
// The entire float is in the packet and in the buffer, so just return it
// and take care of the counters.

value = BitConverter.ToSingle(_inBuff, _inBytesUsed);
value = BitConverterCompatible.Int32BitsToSingle(BinaryPrimitives.ReadInt32LittleEndian(_inBuff.AsSpan(_inBytesUsed)));

_inBytesUsed += 4;
_inBytesPacket -= 4;
Expand All @@ -1521,15 +1521,15 @@ internal bool TryReadDouble(out double value)
}

AssertValidState();
value = BitConverter.ToDouble(_bTmp, 0);
value = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(_bTmp));
return true;
}
else
{
// The entire double is in the packet and in the buffer, so just return it
// and take care of the counters.

value = BitConverter.ToDouble(_inBuff, _inBytesUsed);
value = BitConverter.Int64BitsToDouble(BinaryPrimitives.ReadInt64LittleEndian(_inBuff.AsSpan(_inBytesUsed)));

_inBytesUsed += 8;
_inBytesPacket -= 8;
Expand Down
Expand Up @@ -705,7 +705,6 @@ internal void SetDateTimeOffset(DateTimeOffset value)
_stateObj.WriteByteArray(BitConverter.GetBytes(time), length - 5, 0); // time
_stateObj.WriteByteArray(BitConverter.GetBytes(days), 3, 0); // date
#endif

_stateObj.WriteByte((byte)(offset & 0xff)); // offset byte 1
_stateObj.WriteByte((byte)((offset >> 8) & 0xff)); // offset byte 2
}
Expand Down

0 comments on commit 499bae3

Please sign in to comment.