@@ -1512,7 +1512,7 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int tot
15121512
15131513 if ( writeDataSizeToSnapshot )
15141514 {
1515- SetSnapshotDataSize ( bytesToRead ) ;
1515+ AddSnapshotDataSize ( bytesToRead ) ;
15161516 }
15171517
15181518 AssertValidState ( ) ;
@@ -2058,7 +2058,7 @@ internal TdsOperationStatus TryReadPlpLength(bool returnPlpNullIfNull, out ulong
20582058 // bool firstchunk = false;
20592059 bool isNull = false ;
20602060
2061- Debug . Assert ( _longlenleft == 0 , "Out of synch length read request" ) ;
2061+ Debug . Assert ( _longlenleft == 0 , "Out of sync length read request" ) ;
20622062 if ( _longlen == 0 )
20632063 {
20642064 // First chunk is being read. Find out what type of chunk it is
@@ -2139,6 +2139,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
21392139 }
21402140 return TryReadPlpBytes ( ref buff , offset , len , out totalBytesRead , canContinue , canContinue , compatibilityMode ) ;
21412141 }
2142+
21422143 // Reads the requested number of bytes from a plp data stream, or the entire data if
21432144 // requested length is -1 or larger than the actual length of data. First call to this method
21442145 // should be preceeded by a call to ReadPlpLength or ReadDataLength.
@@ -2254,14 +2255,14 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22542255 SetSnapshotStorage ( buff ) ;
22552256 if ( writeDataSizeToSnapshot )
22562257 {
2257- SetSnapshotDataSize ( bytesRead ) ;
2258+ AddSnapshotDataSize ( bytesRead ) ;
22582259 }
22592260 }
22602261 return result ;
22612262 }
22622263 if ( writeDataSizeToSnapshot && canContinue )
22632264 {
2264- SetSnapshotDataSize ( bytesRead ) ;
2265+ AddSnapshotDataSize ( bytesRead ) ;
22652266 }
22662267
22672268 if ( _longlenleft == 0 )
@@ -2279,10 +2280,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22792280 else if ( canContinue && result == TdsOperationStatus . NeedMoreData )
22802281 {
22812282 SetSnapshotStorage ( buff ) ;
2282- if ( writeDataSizeToSnapshot )
2283- {
2284- SetSnapshotDataSize ( bytesRead ) ;
2285- }
2283+ // data bytes read from the current packet must be 0 here so do not save the snapshot data size
22862284 }
22872285 return result ;
22882286 }
@@ -2296,6 +2294,12 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22962294 break ;
22972295 }
22982296 }
2297+
2298+ if ( canContinue )
2299+ {
2300+ SetSnapshotStorage ( null ) ;
2301+ ClearSnapshotDataSize ( ) ;
2302+ }
22992303 return TdsOperationStatus . Done ;
23002304 }
23012305
@@ -3531,9 +3535,6 @@ internal void ResetSnapshot()
35313535 {
35323536 StateSnapshot snapshot = _snapshot ;
35333537 _snapshot = null ;
3534- // TODO(GH-3385): Not sure what this is trying to assert, but it
3535- // currently fails the DataReader tests.
3536- // Debug.Assert(snapshot._storage == null);
35373538 snapshot . Clear ( ) ;
35383539 Interlocked . CompareExchange ( ref _cachedSnapshot , snapshot , null ) ;
35393540 }
@@ -3591,9 +3592,6 @@ internal object TryTakeSnapshotStorage()
35913592 internal void SetSnapshotStorage ( object buffer )
35923593 {
35933594 Debug . Assert ( _snapshot != null , "should not access snapshot accessor functions without first checking that the snapshot is available" ) ;
3594- // TODO(GH-3385): Not sure what this is trying to assert, but it
3595- // currently fails the DataReader tests.
3596- // Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
35973595 if ( _snapshot != null )
35983596 {
35993597 _snapshot . _storage = buffer ;
@@ -3605,12 +3603,18 @@ internal void SetSnapshotStorage(object buffer)
36053603 /// countOfBytesCopiedFromCurrentPacket to be calculated
36063604 /// </summary>
36073605 /// <param name="countOfBytesCopiedFromCurrentPacket"></param>
3608- internal void SetSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
3606+ internal void AddSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
36093607 {
36103608 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to store packet data size" ) ;
36113609 _snapshot . SetPacketDataSize ( countOfBytesCopiedFromCurrentPacket ) ;
36123610 }
36133611
3612+ internal void ClearSnapshotDataSize ( )
3613+ {
3614+ Debug . Assert ( _snapshot != null , "_snapshot must exist to store packet data size" ) ;
3615+ _snapshot ? . ClearPacketDataSize ( ) ;
3616+ }
3617+
36143618 internal int GetSnapshotTotalSize ( )
36153619 {
36163620 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to read total size" ) ;
@@ -4307,6 +4311,16 @@ internal void SetPacketDataSize(int size)
43074311 target . RunningDataSize = total + size ;
43084312 }
43094313
4314+ internal void ClearPacketDataSize ( )
4315+ {
4316+ PacketData current = _firstPacket ;
4317+ while ( current != null )
4318+ {
4319+ current . RunningDataSize = 0 ;
4320+ current = current . NextPacket ;
4321+ }
4322+ }
4323+
43104324 internal int GetPacketDataOffset ( )
43114325 {
43124326 int offset = 0 ;
@@ -4356,9 +4370,6 @@ private void ClearPackets()
43564370
43574371 private void ClearState ( )
43584372 {
4359- // TODO(GH-3385): Not sure what this is trying to assert, but it
4360- // currently fails the DataReader tests.
4361- // Debug.Assert(_storage == null);
43624373 _storage = null ;
43634374 _replayStateData . Clear ( _stateObj ) ;
43644375 _continueStateData ? . Clear ( _stateObj , trackStack : false ) ;
0 commit comments