Skip to content

Commit

Permalink
6. Optional refactoring that reduces #if directives in merged TdsPars…
Browse files Browse the repository at this point in the history
…erStateObject.
  • Loading branch information
panoskj committed Oct 25, 2023
1 parent 7b47b65 commit 6b00579
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ internal struct SNIErrorDetails
// and surfacing objects to the user.
internal sealed partial class TdsParser
{
internal struct ReliabilitySection
{
/// <summary>
/// This is a no-op in netcore version. Only needed for merging with netfx codebase.
/// </summary>
[Conditional("NETFRAMEWORK")]
internal static void Assert(string message)
{
}
}

private static int _objectTypeCount; // EventSource counter
private readonly SqlClientLogger _logger = new SqlClientLogger();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,7 @@ internal bool TryProcessHeader()
// NOTE: This method (and all it calls) should be retryable without replaying a snapshot
internal bool TryPrepareBuffer()
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadBuffer"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_inBuff != null, "packet buffer should not be null!");

// Header spans packets, or we haven't read the header yet - process header
Expand Down Expand Up @@ -1146,9 +1144,7 @@ public bool TryReadByteArray(Span<byte> buff, int len)
// Every time you call this method increment the offset and decrease len by the value of totalRead
public bool TryReadByteArray(Span<byte> buff, int len, out int totalRead)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByteArray"); // you need to setup for a thread abort somewhere before you call this method
#endif
totalRead = 0;

#if DEBUG
Expand Down Expand Up @@ -1207,9 +1203,7 @@ public bool TryReadByteArray(Span<byte> buff, int len, out int totalRead)
// before the byte is returned.
internal bool TryReadByte(out byte value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadByte"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_inBytesUsed >= 0 && _inBytesUsed <= _inBytesRead, "ERROR - TDSParser: _inBytesUsed < 0 or _inBytesUsed > _inBytesRead");
value = 0;

Expand Down Expand Up @@ -1313,9 +1307,7 @@ internal bool TryReadInt16(out short value)

internal bool TryReadInt32(out int value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadInt32"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
Span<byte> buffer = stackalloc byte[4];
if (((_inBytesUsed + 4) > _inBytesRead) || (_inBytesPacket < 4))
Expand Down Expand Up @@ -1345,9 +1337,7 @@ internal bool TryReadInt32(out int value)
// This method is safe to call when doing async without snapshot
internal bool TryReadInt64(out long value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadInt64"); // you need to setup for a thread abort somewhere before you call this method
#endif
if ((_inBytesPacket == 0) || (_inBytesUsed == _inBytesRead))
{
if (!TryPrepareBuffer())
Expand Down Expand Up @@ -1426,9 +1416,7 @@ internal bool TryReadUInt16(out ushort value)
// This method is safe to call when doing async without replay
internal bool TryReadUInt32(out uint value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadUInt32"); // you need to setup for a thread abort somewhere before you call this method
#endif
if ((_inBytesPacket == 0) || (_inBytesUsed == _inBytesRead))
{
if (!TryPrepareBuffer())
Expand Down Expand Up @@ -1477,9 +1465,7 @@ internal bool TryReadUInt32(out uint value)

internal bool TryReadSingle(out float value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadSingle"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
if (((_inBytesUsed + 4) > _inBytesRead) || (_inBytesPacket < 4))
{
Expand Down Expand Up @@ -1513,9 +1499,7 @@ internal bool TryReadSingle(out float value)

internal bool TryReadDouble(out double value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadDouble"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
if (((_inBytesUsed + 8) > _inBytesRead) || (_inBytesPacket < 8))
{
Expand Down Expand Up @@ -1549,9 +1533,7 @@ internal bool TryReadDouble(out double value)

internal bool TryReadString(int length, out string value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadString"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");
int cBytes = length << 1;
byte[] buf;
Expand Down Expand Up @@ -1592,9 +1574,7 @@ internal bool TryReadString(int length, out string value)

internal bool TryReadStringWithEncoding(int length, System.Text.Encoding encoding, bool isPlp, out string value)
{
#if NETFRAMEWORK
TdsParser.ReliabilitySection.Assert("unreliable call to ReadStringWithEncoding"); // you need to setup for a thread abort somewhere before you call this method
#endif
Debug.Assert(_syncOverAsync || !_asyncReadWithoutSnapshot, "This method is not safe to call when doing sync over async");

if (null == encoding)
Expand Down

0 comments on commit 6b00579

Please sign in to comment.