@@ -64,7 +64,7 @@ public BitStream(byte[] target)
6464 {
6565 this . target = target ;
6666 Resizable = false ;
67- BitLength = ( ulong ) ( target . Length << 3 ) ;
67+ BitLength = ( ulong ) ( target . Length << 3 ) ;
6868 }
6969
7070 /// <summary>
@@ -96,15 +96,16 @@ public BitStream(byte[] target)
9696 /// <summary>
9797 /// Current buffer size. The buffer will not be resized (if possible) until Position is equal to Capacity and an attempt to write data is made.
9898 /// </summary>
99- public long Capacity {
99+ public long Capacity
100+ {
100101 get => target . LongLength ; // Optimized CeilingExact
101102 set
102103 {
103104 if ( value < Length ) throw new ArgumentOutOfRangeException ( "New capcity too small!" ) ;
104105 SetCapacity ( value ) ;
105106 }
106107 }
107-
108+
108109 /// <summary>
109110 /// The current length of data considered to be "written" to the buffer.
110111 /// </summary>
@@ -113,7 +114,7 @@ public long Capacity {
113114 /// <summary>
114115 /// The index that will be written to when any call to write data is made to this stream.
115116 /// </summary>
116- public override long Position { get => ( long ) ( BitPosition >> 3 ) ; set => BitPosition = ( ulong ) value << 3 ; }
117+ public override long Position { get => ( long ) ( BitPosition >> 3 ) ; set => BitPosition = ( ulong ) value << 3 ; }
117118
118119 /// <summary>
119120 /// Bit offset into the buffer that new data will be written to.
@@ -221,7 +222,7 @@ private void SetCapacity(long value)
221222 public override void SetLength ( long value )
222223 {
223224 if ( value < 0 ) throw new IndexOutOfRangeException ( "Cannot set a negative length!" ) ;
224- if ( value > Capacity ) Grow ( value - Capacity ) ;
225+ if ( value > Capacity ) Grow ( value - Capacity ) ;
225226 BitLength = ( ulong ) value << 3 ;
226227 }
227228
@@ -310,7 +311,7 @@ public void WriteDouble(double value)
310311 /// <param name="value">Value to write</param>
311312 public void WriteSinglePacked ( float value )
312313 {
313- lock ( holder_f )
314+ lock ( holder_f )
314315 lock ( holder_i )
315316 {
316317 holder_f [ 0 ] = value ;
@@ -356,8 +357,8 @@ public void WriteRangedSingle(float value, float minValue, float maxValue, int b
356357 {
357358 if ( bytes < 1 || bytes > 4 ) throw new ArgumentOutOfRangeException ( "Result must occupy between 1 and 4 bytes!" ) ;
358359 if ( value < minValue || value > maxValue ) throw new ArgumentOutOfRangeException ( "Given value does not match the given constraints!" ) ;
359- uint result = ( uint ) ( ( ( value + minValue ) / ( maxValue + minValue ) ) * ( ( 0x100 * bytes ) - 1 ) ) ;
360- for ( int i = 0 ; i < bytes ; ++ i ) _WriteByte ( ( byte ) ( result >> ( i << 3 ) ) ) ;
360+ uint result = ( uint ) ( ( ( value + minValue ) / ( maxValue + minValue ) ) * ( ( 0x100 * bytes ) - 1 ) ) ;
361+ for ( int i = 0 ; i < bytes ; ++ i ) _WriteByte ( ( byte ) ( result >> ( i << 3 ) ) ) ;
361362 }
362363
363364 /// <summary>
@@ -371,7 +372,7 @@ public void WriteRangedDouble(double value, double minValue, double maxValue, in
371372 {
372373 if ( bytes < 1 || bytes > 8 ) throw new ArgumentOutOfRangeException ( "Result must occupy between 1 and 8 bytes!" ) ;
373374 if ( value < minValue || value > maxValue ) throw new ArgumentOutOfRangeException ( "Given value does not match the given constraints!" ) ;
374- ulong result = ( ulong ) ( ( ( value + minValue ) / ( maxValue + minValue ) ) * ( ( 0x100 * bytes ) - 1 ) ) ;
375+ ulong result = ( ulong ) ( ( ( value + minValue ) / ( maxValue + minValue ) ) * ( ( 0x100 * bytes ) - 1 ) ) ;
375376 for ( int i = 0 ; i < bytes ; ++ i ) _WriteByte ( ( byte ) ( result >> ( i << 3 ) ) ) ;
376377 }
377378
@@ -383,7 +384,7 @@ public void WriteRangedDouble(double value, double minValue, double maxValue, in
383384 public void WriteRotation ( Quaternion rotation , int bytesPerAngle )
384385 {
385386 if ( bytesPerAngle < 1 || bytesPerAngle > 4 ) throw new ArgumentOutOfRangeException ( "Bytes per angle must be at least 1 byte and at most 4 bytes!" ) ;
386- if ( bytesPerAngle == 4 ) WriteVector3 ( rotation . eulerAngles ) ;
387+ if ( bytesPerAngle == 4 ) WriteVector3 ( rotation . eulerAngles ) ;
387388 else
388389 {
389390 Vector3 rot = rotation . eulerAngles ;
@@ -425,15 +426,15 @@ public double ReadDouble()
425426 return holder_d [ 0 ] ;
426427 }
427428 }
428-
429+
429430 /// <summary>
430431 /// Read a single-precision floating point value from the stream from a varint
431432 /// </summary>
432433 /// <returns>The read value</returns>
433434 public float ReadSinglePacked ( )
434435 {
435436 uint read = ReadUInt32Packed ( ) ;
436- lock ( holder_f )
437+ lock ( holder_f )
437438 lock ( holder_i )
438439 {
439440 holder_i [ 0 ] = BinaryHelpers . SwapEndian ( read ) ;
@@ -527,7 +528,7 @@ public void WriteNibble(byte value)
527528 value &= 0x0F ;
528529 int offset = ( int ) ( BitPosition & 7 ) , offset_inv = 8 - offset ;
529530 target [ Position ] = ( byte ) ( ( target [ Position ] & ( 0xFF >> offset_inv ) ) | ( byte ) ( value << offset ) ) ;
530- if ( offset > 4 ) target [ Position + 1 ] = ( byte ) ( ( target [ Position + 1 ] & ( 0xFF << ( offset & 3 ) ) ) | ( byte ) ( value >> offset_inv ) ) ;
531+ if ( offset > 4 ) target [ Position + 1 ] = ( byte ) ( ( target [ Position + 1 ] & ( 0xFF << ( offset & 3 ) ) ) | ( byte ) ( value >> offset_inv ) ) ;
531532 BitPosition += 4 ;
532533 }
533534 UpdateLength ( ) ;
@@ -546,13 +547,13 @@ public void WriteNibble(byte value)
546547 /// <param name="bitCount">Amount of bits to write</param>
547548 public void WriteBits ( ulong value , int bitCount )
548549 {
549- if ( BitPosition + ( ulong ) bitCount > ( ( ulong ) target . LongLength << 3 ) ) Grow ( Div8Ceil ( BitPosition + ( ulong ) bitCount ) ) ;
550+ if ( BitPosition + ( ulong ) bitCount > ( ( ulong ) target . LongLength << 3 ) ) Grow ( Div8Ceil ( BitPosition + ( ulong ) bitCount ) ) ;
550551 if ( bitCount > 64 ) throw new ArgumentOutOfRangeException ( "Cannot read more than 64 bits from a 64-bit value!" ) ;
551552 if ( bitCount < 0 ) throw new ArgumentOutOfRangeException ( "Cannot read fewer than 0 bits!" ) ;
552553 int count = - 8 ;
553- while ( bitCount > ( count += 8 ) ) _WriteULongByte ( value >> count ) ;
554+ while ( bitCount > ( count += 8 ) ) _WriteULongByte ( value >> count ) ;
554555 BitPosition += ( ulong ) count ;
555- if ( ( bitCount & 7 ) != 0 ) _WriteBits ( ( byte ) ( value >> count ) , bitCount & 7 ) ;
556+ if ( ( bitCount & 7 ) != 0 ) _WriteBits ( ( byte ) ( value >> count ) , bitCount & 7 ) ;
556557 UpdateLength ( ) ;
557558 }
558559 /// <summary>
@@ -570,7 +571,7 @@ private void _WriteBits(byte value, int bitCount)
570571 target [ Position ] = ( byte ) (
571572 ( target [ Position ] & ( 0xFF >> offset_inv ) ) | // Bits prior to value (lower)
572573 ( target [ Position ] & ( 0xFF << ( offset + bitCount ) ) ) | // Bits after value (higher)
573- ( value << offset ) // Bits to write
574+ ( value << offset ) // Bits to write
574575 ) ;
575576 if ( bitCount + offset > 8 )
576577 target [ Position + 1 ] = ( byte ) (
@@ -733,15 +734,15 @@ public void WriteUInt64Packed(ulong value)
733734 /// Read an unsigned long (UInt64) from the stream.
734735 /// </summary>
735736 /// <returns>Value read from stream.</returns>
736- public ulong ReadUInt64 ( ) => ( ulong ) (
737+ public ulong ReadUInt64 ( ) => (
737738 _ReadByte ( ) |
738- ( _ReadByte ( ) << 8 ) |
739- ( _ReadByte ( ) << 16 ) |
740- ( _ReadByte ( ) << 24 ) |
741- ( _ReadByte ( ) << 32 ) |
742- ( _ReadByte ( ) << 40 ) |
743- ( _ReadByte ( ) << 48 ) |
744- ( _ReadByte ( ) << 56 )
739+ ( ( ulong ) _ReadByte ( ) << 8 ) |
740+ ( ( ulong ) _ReadByte ( ) << 16 ) |
741+ ( ( ulong ) _ReadByte ( ) << 24 ) |
742+ ( ( ulong ) _ReadByte ( ) << 32 ) |
743+ ( ( ulong ) _ReadByte ( ) << 40 ) |
744+ ( ( ulong ) _ReadByte ( ) << 48 ) |
745+ ( ( ulong ) _ReadByte ( ) << 56 )
745746 ) ;
746747 /// <summary>
747748 /// Read a signed long (Int64) from the stream.
@@ -881,19 +882,19 @@ public override void WriteByte(byte value)
881882 /// <param name="count">How many bytes to read. Set to value less than one to read until ReadByte returns -1</param>
882883 public void CopyFrom ( Stream s , int count = - 1 )
883884 {
884- if ( s is BitStream b ) Write ( b . target , 0 , count < 0 ? ( int ) b . Length : count ) ;
885+ if ( s is BitStream b ) Write ( b . target , 0 , count < 0 ? ( int ) b . Length : count ) ;
885886 else
886887 {
887888 int read ;
888889 bool readToEnd = count < 0 ;
889- while ( ( readToEnd || count -- > 0 ) && ( read = s . ReadByte ( ) ) != - 1 )
890+ while ( ( readToEnd || count -- > 0 ) && ( read = s . ReadByte ( ) ) != - 1 )
890891 _WriteIntByte ( read ) ;
891892 UpdateLength ( ) ;
892893 }
893894 }
894-
895+
895896 // TODO: Implement CopyFrom() for BitStream with bitCount parameter
896-
897+
897898 /// <summary>
898899 /// Update length of data considered to be "written" to the stream.
899900 /// </summary>
0 commit comments