@@ -1510,7 +1510,7 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int tot
15101510
15111511 if ( writeDataSizeToSnapshot )
15121512 {
1513- AddSnapshotDataSize ( bytesToRead ) ;
1513+ SetSnapshotDataSize ( bytesToRead ) ;
15141514 }
15151515
15161516 AssertValidState ( ) ;
@@ -2056,7 +2056,7 @@ internal TdsOperationStatus TryReadPlpLength(bool returnPlpNullIfNull, out ulong
20562056 // bool firstchunk = false;
20572057 bool isNull = false ;
20582058
2059- Debug . Assert ( _longlenleft == 0 , "Out of sync length read request" ) ;
2059+ Debug . Assert ( _longlenleft == 0 , "Out of synch length read request" ) ;
20602060 if ( _longlen == 0 )
20612061 {
20622062 // First chunk is being read. Find out what type of chunk it is
@@ -2137,7 +2137,6 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
21372137 }
21382138 return TryReadPlpBytes ( ref buff , offset , len , out totalBytesRead , canContinue , canContinue , compatibilityMode ) ;
21392139 }
2140-
21412140 // Reads the requested number of bytes from a plp data stream, or the entire data if
21422141 // requested length is -1 or larger than the actual length of data. First call to this method
21432142 // should be preceeded by a call to ReadPlpLength or ReadDataLength.
@@ -2253,14 +2252,14 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22532252 SetSnapshotStorage ( buff ) ;
22542253 if ( writeDataSizeToSnapshot )
22552254 {
2256- AddSnapshotDataSize ( bytesRead ) ;
2255+ SetSnapshotDataSize ( bytesRead ) ;
22572256 }
22582257 }
22592258 return result ;
22602259 }
22612260 if ( writeDataSizeToSnapshot && canContinue )
22622261 {
2263- AddSnapshotDataSize ( bytesRead ) ;
2262+ SetSnapshotDataSize ( bytesRead ) ;
22642263 }
22652264
22662265 if ( _longlenleft == 0 )
@@ -2278,7 +2277,10 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22782277 else if ( canContinue && result == TdsOperationStatus . NeedMoreData )
22792278 {
22802279 SetSnapshotStorage ( buff ) ;
2281- // data bytes read from the current packet must be 0 here so do not save the snapshot data size
2280+ if ( writeDataSizeToSnapshot )
2281+ {
2282+ SetSnapshotDataSize ( bytesRead ) ;
2283+ }
22822284 }
22832285 return result ;
22842286 }
@@ -2292,12 +2294,6 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
22922294 break ;
22932295 }
22942296 }
2295-
2296- if ( canContinue )
2297- {
2298- SetSnapshotStorage ( null ) ;
2299- ClearSnapshotDataSize ( ) ;
2300- }
23012297 return TdsOperationStatus . Done ;
23022298 }
23032299
@@ -3533,6 +3529,9 @@ internal void ResetSnapshot()
35333529 {
35343530 StateSnapshot snapshot = _snapshot ;
35353531 _snapshot = null ;
3532+ // TODO(GH-3385): Not sure what this is trying to assert, but it
3533+ // currently fails the DataReader tests.
3534+ // Debug.Assert(snapshot._storage == null);
35363535 snapshot . Clear ( ) ;
35373536 Interlocked . CompareExchange ( ref _cachedSnapshot , snapshot , null ) ;
35383537 }
@@ -3590,6 +3589,9 @@ internal object TryTakeSnapshotStorage()
35903589 internal void SetSnapshotStorage ( object buffer )
35913590 {
35923591 Debug . Assert ( _snapshot != null , "should not access snapshot accessor functions without first checking that the snapshot is available" ) ;
3592+ // TODO(GH-3385): Not sure what this is trying to assert, but it
3593+ // currently fails the DataReader tests.
3594+ // Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
35933595 if ( _snapshot != null )
35943596 {
35953597 _snapshot . _storage = buffer ;
@@ -3601,18 +3603,12 @@ internal void SetSnapshotStorage(object buffer)
36013603 /// countOfBytesCopiedFromCurrentPacket to be calculated
36023604 /// </summary>
36033605 /// <param name="countOfBytesCopiedFromCurrentPacket"></param>
3604- internal void AddSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
3606+ internal void SetSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
36053607 {
36063608 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to store packet data size" ) ;
36073609 _snapshot . SetPacketDataSize ( countOfBytesCopiedFromCurrentPacket ) ;
36083610 }
36093611
3610- internal void ClearSnapshotDataSize ( )
3611- {
3612- Debug . Assert ( _snapshot != null , "_snapshot must exist to store packet data size" ) ;
3613- _snapshot ? . ClearPacketDataSize ( ) ;
3614- }
3615-
36163612 internal int GetSnapshotTotalSize ( )
36173613 {
36183614 Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to read total size" ) ;
@@ -4309,16 +4305,6 @@ internal void SetPacketDataSize(int size)
43094305 target . RunningDataSize = total + size ;
43104306 }
43114307
4312- internal void ClearPacketDataSize ( )
4313- {
4314- PacketData current = _firstPacket ;
4315- while ( current != null )
4316- {
4317- current . RunningDataSize = 0 ;
4318- current = current . NextPacket ;
4319- }
4320- }
4321-
43224308 internal int GetPacketDataOffset ( )
43234309 {
43244310 int offset = 0 ;
@@ -4368,6 +4354,9 @@ private void ClearPackets()
43684354
43694355 private void ClearState ( )
43704356 {
4357+ // TODO(GH-3385): Not sure what this is trying to assert, but it
4358+ // currently fails the DataReader tests.
4359+ // Debug.Assert(_storage == null);
43714360 _storage = null ;
43724361 _replayStateData . Clear ( _stateObj ) ;
43734362 _continueStateData ? . Clear ( _stateObj , trackStack : false ) ;
0 commit comments