@@ -142,7 +142,7 @@ private int WriteLength(int length, LengthFormat lengthFormat)
142142 /// <exception cref="OperationCanceledException">The operation has been canceled.</exception>
143143 public async ValueTask WriteAsync ( ReadOnlyMemory < byte > input , LengthFormat lengthFormat , CancellationToken token = default )
144144 {
145- if ( FreeCapacity < Leb128 < int > . MaxSizeInBytes )
145+ if ( FreeCapacity < Leb128 < uint > . MaxSizeInBytes )
146146 await FlushAsync ( token ) . ConfigureAwait ( false ) ;
147147
148148 WriteLength ( input . Length , lengthFormat ) ;
@@ -164,7 +164,7 @@ public async ValueTask<long> EncodeAsync(ReadOnlyMemory<char> chars, EncodingCon
164164 long result ;
165165 if ( lengthFormat . HasValue )
166166 {
167- if ( FreeCapacity < Leb128 < int > . MaxSizeInBytes )
167+ if ( FreeCapacity < Leb128 < uint > . MaxSizeInBytes )
168168 await FlushAsync ( token ) . ConfigureAwait ( false ) ;
169169
170170 result = WriteLength ( context . Encoding . GetByteCount ( chars . Span ) , lengthFormat . GetValueOrDefault ( ) ) ;
@@ -256,7 +256,7 @@ private bool TryFormat<T>(T value, LengthFormat? lengthFormat, ReadOnlySpan<char
256256 {
257257 null => 0 ,
258258 LengthFormat . BigEndian or LengthFormat . LittleEndian => sizeof ( int ) ,
259- LengthFormat . Compressed => Leb128 < int > . MaxSizeInBytes ,
259+ LengthFormat . Compressed => Leb128 < uint > . MaxSizeInBytes ,
260260 _ => throw new ArgumentOutOfRangeException ( nameof ( lengthFormat ) ) ,
261261 } ;
262262
@@ -289,7 +289,7 @@ private async ValueTask<int> FormatSlowAsync<T>(T value, LengthFormat? lengthFor
289289 if ( ! TryFormat ( value , lengthFormat , format , provider , out var bytesWritten ) )
290290 {
291291 const int maxBufferSize = int . MaxValue / 2 ;
292- for ( var bufferSize = MaxBufferSize + Leb128 < int > . MaxSizeInBytes ; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException ( ) )
292+ for ( var bufferSize = MaxBufferSize + Leb128 < uint > . MaxSizeInBytes ; ; bufferSize = bufferSize <= maxBufferSize ? bufferSize << 1 : throw new InsufficientMemoryException ( ) )
293293 {
294294 using var buffer = allocator . AllocateAtLeast ( bufferSize ) ;
295295 if ( value . TryFormat ( buffer . Span , out bytesWritten , format , provider ) )
0 commit comments