@@ -284,6 +284,22 @@ internal ReadOnlySequence<byte> RawSequence()
284284 return default ;
285285 }
286286
287+ // Linearizes a Sequence payload into the supplied buffer (which must be at least _length long),
288+ // walking the segments directly via the iterator - i.e. without paying to build a ReadOnlySequence -
289+ // and returns the populated portion of the buffer.
290+ private ReadOnlySpan < byte > CopyRawSequence ( Span < byte > destination )
291+ {
292+ var iterator = RawSequenceIterator ( ) ;
293+ int offset = 0 ;
294+ while ( iterator . TryNext ( out var memory ) )
295+ {
296+ memory . Span . CopyTo ( destination . Slice ( offset ) ) ;
297+ offset += memory . Length ;
298+ }
299+ Debug . Assert ( offset == _length , "linearized length mismatch" ) ;
300+ return destination . Slice ( 0 , offset ) ;
301+ }
302+
287303 internal ReadOnlySpan < byte > RawSpan ( )
288304 {
289305 if ( _obj is byte [ ] b ) return new ReadOnlySpan < byte > ( b , _index , _length ) ;
@@ -1346,6 +1362,15 @@ public bool TryParse(out long val)
13461362 return Format . TryParseInt64 ( RawString ( ) , out val ) ;
13471363 case StorageType . MemoryManager or StorageType . ByteArray :
13481364 return Format . TryParseInt64 ( RawSpan ( ) , out val ) ;
1365+ case StorageType . Sequence :
1366+ // longer than the largest possible Int64 text => cannot be an Int64; otherwise
1367+ // linearize onto the stack and reuse the span-based parse (matching the ByteArray path)
1368+ if ( _length <= Format . MaxInt64TextLen )
1369+ {
1370+ Span < byte > buffer = stackalloc byte [ Format . MaxInt64TextLen ] ;
1371+ return Format . TryParseInt64 ( CopyRawSequence ( buffer ) , out val ) ;
1372+ }
1373+ break ;
13491374 case StorageType . Double :
13501375 var d = OverlappedValueDouble ;
13511376 try
@@ -1406,6 +1431,15 @@ public bool TryParse(out double val)
14061431 return Format . TryParseDouble ( RawString ( ) , out val ) ;
14071432 case StorageType . MemoryManager or StorageType . ByteArray :
14081433 return TryParseDouble ( RawSpan ( ) , out val ) ;
1434+ case StorageType . Sequence :
1435+ // longer than the largest possible double text => cannot be a double; otherwise
1436+ // linearize onto the stack and reuse the span-based parse (matching the ByteArray path)
1437+ if ( _length <= Format . MaxDoubleTextLen )
1438+ {
1439+ Span < byte > buffer = stackalloc byte [ Format . MaxDoubleTextLen ] ;
1440+ return TryParseDouble ( CopyRawSequence ( buffer ) , out val ) ;
1441+ }
1442+ break ;
14091443 case StorageType . Null :
14101444 // in redis-land 0 approx. equal null; so roll with it
14111445 val = 0 ;
0 commit comments