55
66namespace PCL . Core . Helper ;
77
8- public class VarInt
8+ public static class VarInt
99{
1010 /// <summary>
1111 /// 将无符号长整数编码为VarInt字节序列
@@ -92,11 +92,11 @@ public static uint DecodeUInt(byte[] bytes, out int readLength)
9292 /// 从流中读取并解码无符号长整数,并将流前进所读取的字节数
9393 /// </summary>
9494 /// <param name="stream">输入流</param>
95- /// <param name="token"> </param>
95+ /// <param name="cancellationToken">要监视取消请求的标记 </param>
9696 /// <returns>解码后的64位无符号整数</returns>
9797 /// <exception cref="EndOfStreamException">流提前结束</exception>
9898 /// <exception cref="FormatException">VarInt格式无效</exception>
99- public async static Task < ulong > ReadFromStream ( Stream stream , CancellationToken token = default )
99+ public static async Task < ulong > ReadFromStream ( Stream stream , CancellationToken cancellationToken = default )
100100 {
101101 ulong result = 0 ;
102102 int shift = 0 ;
@@ -105,7 +105,7 @@ public async static Task<ulong> ReadFromStream(Stream stream, CancellationToken
105105 var buffer = new byte [ 1 ] ;
106106 while ( true )
107107 {
108- int readLength = await stream . ReadAsync ( buffer , 0 , 1 , token ) ;
108+ int readLength = await stream . ReadAsync ( buffer , 0 , 1 , cancellationToken ) ;
109109 if ( readLength == 0 )
110110 throw new EndOfStreamException ( ) ;
111111
@@ -128,11 +128,11 @@ public async static Task<ulong> ReadFromStream(Stream stream, CancellationToken
128128 /// 从流中读取并解码无符号整数,并将流前进所读取的字节数
129129 /// </summary>
130130 /// <param name="stream">输入流</param>
131- /// <param name="token "></param>
131+ /// <param name="cancellationToken "></param>
132132 /// <returns>解码后的32位无符号整数</returns>
133- public async static Task < uint > ReadUIntFromStream ( Stream stream , CancellationToken token = default )
133+ public static async Task < uint > ReadUIntFromStream ( Stream stream , CancellationToken cancellationToken = default )
134134 {
135- ulong result = await ReadFromStream ( stream , token ) ;
135+ ulong result = await ReadFromStream ( stream , cancellationToken ) ;
136136 if ( result > uint . MaxValue )
137137 throw new OverflowException ( "Decoded value exceeds UInt32 range" ) ;
138138 return ( uint ) result ;
0 commit comments