@@ -1488,7 +1488,7 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int tot
14881488
14891489 if ( writeDataSizeToSnapshot )
14901490 {
1491- SetSnapshotDataSize ( bytesToRead ) ;
1491+ AddSnapshotDataSize ( bytesToRead ) ;
14921492 }
14931493
14941494 AssertValidState ( ) ;
@@ -2034,7 +2034,7 @@ internal TdsOperationStatus TryReadPlpLength(bool returnPlpNullIfNull, out ulong
20342034 // bool firstchunk = false;
20352035 bool isNull = false ;
20362036
2037- Debug . Assert ( _longlenleft == 0 , "Out of synch length read request" ) ;
2037+ Debug . Assert ( _longlenleft == 0 , "Out of sync length read request" ) ;
20382038 if ( _longlen == 0 )
20392039 {
20402040 // First chunk is being read. Find out what type of chunk it is
@@ -2115,6 +2115,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
21152115 }
21162116 return TryReadPlpBytes ( ref buff , offset , len , out totalBytesRead , canContinue , canContinue , compatibilityMode ) ;
21172117 }
2118+
21182119 // Reads the requested number of bytes from a plp data stream, or the entire data if
21192120 // requested length is -1 or larger than the actual length of data. First call to this method
21202121 // should be preceeded by a call to ReadPlpLength or ReadDataLength.
@@ -2230,14 +2231,14 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22302231 SetSnapshotStorage ( buff ) ;
22312232 if ( writeDataSizeToSnapshot )
22322233 {
2233- SetSnapshotDataSize ( bytesRead ) ;
2234+ AddSnapshotDataSize ( bytesRead ) ;
22342235 }
22352236 }
22362237 return result ;
22372238 }
22382239 if ( writeDataSizeToSnapshot && canContinue )
22392240 {
2240- SetSnapshotDataSize ( bytesRead ) ;
2241+ AddSnapshotDataSize ( bytesRead ) ;
22412242 }
22422243
22432244 if ( _longlenleft == 0 )
@@ -2255,10 +2256,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22552256 else if ( canContinue && result == TdsOperationStatus . NeedMoreData )
22562257 {
22572258 SetSnapshotStorage ( buff ) ;
2258- if ( writeDataSizeToSnapshot )
2259- {
2260- SetSnapshotDataSize ( bytesRead ) ;
2261- }
2259+ // data bytes read from the current packet must be 0 here so do not save the snapshot data size
22622260 }
22632261 return result ;
22642262 }
@@ -2272,6 +2270,12 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22722270 break ;
22732271 }
22742272 }
2273+
2274+ if ( canContinue )
2275+ {
2276+ SetSnapshotStorage ( null ) ;
2277+ ClearSnapshotDataSize ( ) ;
2278+ }
22752279 return TdsOperationStatus . Done ;
22762280 }
22772281
@@ -3507,9 +3511,6 @@ internal void ResetSnapshot()
35073511 {
35083512 StateSnapshot snapshot = _snapshot ;
35093513 _snapshot = null ;
3510- // TODO(GH-3385): Not sure what this is trying to assert, but it
3511- // currently fails the DataReader tests.
3512- // Debug.Assert(snapshot._storage == null);
35133514 snapshot . Clear ( ) ;
35143515 Interlocked . CompareExchange ( ref _cachedSnapshot , snapshot , null ) ;
35153516 }
@@ -3567,9 +3568,6 @@ internal object TryTakeSnapshotStorage()
35673568 internal void SetSnapshotStorage ( object buffer )
35683569 {
35693570 Debug . Assert ( _snapshot != null , "should not access snapshot accessor functions without first checking that the snapshot is available" ) ;
3570- // TODO(GH-3385): Not sure what this is trying to assert, but it
3571- // currently fails the DataReader tests.
3572- // Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
35733571 if ( _snapshot != null )
35743572 {
35753573 _snapshot . _storage = buffer ;
@@ -3581,12 +3579,18 @@ internal void SetSnapshotStorage(object buffer)
35813579 /// countOfBytesCopiedFromCurrentPacket to be calculated
35823580 /// </summary>
35833581 /// <param name="countOfBytesCopiedFromCurrentPacket"></param>
3584- internal void SetSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
3582+ internal void AddSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
35853583 {
35863584 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to store packet data size" ) ;
35873585 _snapshot . SetPacketDataSize ( countOfBytesCopiedFromCurrentPacket ) ;
35883586 }
35893587
3588+ internal void ClearSnapshotDataSize ( )
3589+ {
3590+ Debug . Assert ( _snapshot != null , "_snapshot must exist to store packet data size" ) ;
3591+ _snapshot ? . ClearPacketDataSize ( ) ;
3592+ }
3593+
35903594 internal int GetSnapshotTotalSize ( )
35913595 {
35923596 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to read total size" ) ;
@@ -4283,6 +4287,16 @@ internal void SetPacketDataSize(int size)
42834287 target . RunningDataSize = total + size ;
42844288 }
42854289
4290+ internal void ClearPacketDataSize ( )
4291+ {
4292+ PacketData current = _firstPacket ;
4293+ while ( current != null )
4294+ {
4295+ current . RunningDataSize = 0 ;
4296+ current = current . NextPacket ;
4297+ }
4298+ }
4299+
42864300 internal int GetPacketDataOffset ( )
42874301 {
42884302 int offset = 0 ;
@@ -4332,9 +4346,6 @@ private void ClearPackets()
43324346
43334347 private void ClearState ( )
43344348 {
4335- // TODO(GH-3385): Not sure what this is trying to assert, but it
4336- // currently fails the DataReader tests.
4337- // Debug.Assert(_storage == null);
43384349 _storage = null ;
43394350 _replayStateData . Clear ( _stateObj ) ;
43404351 _continueStateData ? . Clear ( _stateObj , trackStack : false ) ;
0 commit comments