@@ -48,6 +48,7 @@ internal class XdrStream : Stream
4848 private long _position ;
4949 private List < byte > _outputBuffer ;
5050 private Queue < byte > _inputBuffer ;
51+ private byte [ ] _smallBuffer ;
5152 private Ionic . Zlib . ZlibCodec _deflate ;
5253 private Ionic . Zlib . ZlibCodec _inflate ;
5354 private byte [ ] _compressionBuffer ;
@@ -121,6 +122,7 @@ public XdrStream(Stream innerStream, Charset charset, bool compression, bool own
121122 _position = 0 ;
122123 _outputBuffer = new List < byte > ( PreferredBufferSize ) ;
123124 _inputBuffer = new Queue < byte > ( PreferredBufferSize ) ;
125+ _smallBuffer = new byte [ 8 ] ;
124126 if ( _compression )
125127 {
126128 _deflate = new Ionic . Zlib . ZlibCodec ( Ionic . Zlib . CompressionMode . Compress ) ;
@@ -334,9 +336,8 @@ private void ResetOperation()
334336
335337 #region XDR Read Methods
336338
337- public byte [ ] ReadBytes ( byte [ ] buffer )
339+ public byte [ ] ReadBytes ( byte [ ] buffer , int count )
338340 {
339- var count = buffer . Length ;
340341 if ( count > 0 )
341342 {
342343 var toRead = count ;
@@ -353,9 +354,8 @@ public byte[] ReadBytes(byte[] buffer)
353354 }
354355 return buffer ;
355356 }
356- public async Task < byte [ ] > ReadBytesAsync ( byte [ ] buffer )
357+ public async Task < byte [ ] > ReadBytesAsync ( byte [ ] buffer , int count )
357358 {
358- var count = buffer . Length ;
359359 if ( count > 0 )
360360 {
361361 var toRead = count ;
@@ -376,7 +376,7 @@ public async Task<byte[]> ReadBytesAsync(byte[] buffer)
376376 public byte [ ] ReadOpaque ( int length )
377377 {
378378 var buffer = new byte [ length ] ;
379- ReadBytes ( buffer ) ;
379+ ReadBytes ( buffer , length ) ;
380380 var padLength = ( ( 4 - length ) & 3 ) ;
381381 if ( padLength > 0 )
382382 {
@@ -417,26 +417,24 @@ public short ReadInt16()
417417 return Convert . ToInt16 ( ReadInt32 ( ) ) ;
418418 }
419419
420- private byte [ ] int32Buffer = new byte [ 4 ] ;
421420 public int ReadInt32 ( )
422421 {
423- Array . Clear ( int32Buffer , 0 , 4 ) ;
424- ReadBytes ( int32Buffer ) ;
425- return IPAddress . HostToNetworkOrder ( BitConverter . ToInt32 ( int32Buffer , 0 ) ) ;
422+ Array . Clear ( _smallBuffer , 0 , 4 ) ;
423+ ReadBytes ( _smallBuffer , 4 ) ;
424+ return IPAddress . HostToNetworkOrder ( BitConverter . ToInt32 ( _smallBuffer , 0 ) ) ;
426425 }
427426 public async Task < int > ReadInt32Async ( )
428427 {
429- Array . Clear ( int32Buffer , 0 , 4 ) ;
430- await ReadBytesAsync ( int32Buffer ) . ConfigureAwait ( false ) ;
431- return IPAddress . HostToNetworkOrder ( BitConverter . ToInt32 ( int32Buffer , 0 ) ) ;
428+ Array . Clear ( _smallBuffer , 0 , 4 ) ;
429+ await ReadBytesAsync ( _smallBuffer , 4 ) . ConfigureAwait ( false ) ;
430+ return IPAddress . HostToNetworkOrder ( BitConverter . ToInt32 ( _smallBuffer , 0 ) ) ;
432431 }
433432
434- private byte [ ] int64Buffer = new byte [ 8 ] ;
435433 public long ReadInt64 ( )
436434 {
437- Array . Clear ( int64Buffer , 0 , 8 ) ;
438- ReadBytes ( int64Buffer ) ;
439- return IPAddress . HostToNetworkOrder ( BitConverter . ToInt64 ( int64Buffer , 0 ) ) ;
435+ Array . Clear ( _smallBuffer , 0 , 8 ) ;
436+ ReadBytes ( _smallBuffer , 8 ) ;
437+ return IPAddress . HostToNetworkOrder ( BitConverter . ToInt64 ( _smallBuffer , 0 ) ) ;
440438 }
441439
442440 public Guid ReadGuid ( )
0 commit comments