@@ -110,10 +110,10 @@ private void Push<T>(T b)
110
110
public void WriteUShort ( ushort s ) => Push ( s ) ;
111
111
public void WriteUInt ( uint i ) => Push ( i ) ;
112
112
public void WriteULong ( ulong l ) => Push ( l ) ;
113
- public void WriteSByte ( sbyte b ) => Push ( ZigZagEncode ( b , 8 ) ) ;
114
- public void WriteShort ( short s ) => Push ( ZigZagEncode ( s , 8 ) ) ;
115
- public void WriteInt ( int i ) => Push ( ZigZagEncode ( i , 8 ) ) ;
116
- public void WriteLong ( long l ) => Push ( ZigZagEncode ( l , 8 ) ) ;
113
+ public void WriteSByte ( sbyte b ) => Push ( ZigZagEncode ( b ) ) ;
114
+ public void WriteShort ( short s ) => Push ( ZigZagEncode ( s ) ) ;
115
+ public void WriteInt ( int i ) => Push ( ZigZagEncode ( i ) ) ;
116
+ public void WriteLong ( long l ) => Push ( ZigZagEncode ( l ) ) ;
117
117
public void WriteString ( string s ) => Push ( s ) ;
118
118
public void WriteAlignBits ( ) => Push < object > ( null ) ;
119
119
public void WriteFloatArray ( float [ ] f , bool known = false ) => PushArray ( f , known ) ;
@@ -149,16 +149,16 @@ private void PushArray<T>(T[] t, bool knownSize = false)
149
149
{
150
150
if ( ! knownSize ) Push ( ( uint ) t . Length ) ;
151
151
bool signed = IsSigned ( t . GetType ( ) . GetElementType ( ) ) ;
152
- int size = Marshal . SizeOf ( t . GetType ( ) . GetElementType ( ) ) ;
153
- foreach ( T t1 in t ) Push ( signed ? ( object ) ZigZagEncode ( t1 as long ? ?? t1 as int ? ?? t1 as short ? ?? t1 as sbyte ? ?? 0 , size ) : ( object ) t1 ) ;
152
+ // int size = Marshal.SizeOf(t.GetType().GetElementType());
153
+ foreach ( T t1 in t ) Push ( signed ? ( object ) ZigZagEncode ( t1 as long ? ?? t1 as int ? ?? t1 as short ? ?? t1 as sbyte ? ?? 0 ) : ( object ) t1 ) ;
154
154
}
155
155
156
156
private void PushArray < T > ( T [ ] t , int startIndex , int length , bool knownSize = false )
157
157
{
158
158
if ( ! knownSize ) Push ( ( uint ) t . Length ) ;
159
159
bool signed = IsSigned ( t . GetType ( ) . GetElementType ( ) ) ;
160
- int size = Marshal . SizeOf ( t . GetType ( ) . GetElementType ( ) ) ;
161
- for ( int i = startIndex ; i < length ; i ++ ) Push ( signed ? ( object ) ZigZagEncode ( t [ i ] as long ? ?? t [ i ] as int ? ?? t [ i ] as short ? ?? t [ i ] as sbyte ? ?? 0 , size ) : ( object ) t [ i ] ) ;
160
+ // int size = Marshal.SizeOf(t.GetType().GetElementType());
161
+ for ( int i = startIndex ; i < length ; i ++ ) Push ( signed ? ( object ) ZigZagEncode ( t [ i ] as long ? ?? t [ i ] as int ? ?? t [ i ] as short ? ?? t [ i ] as sbyte ? ?? 0 ) : ( object ) t [ i ] ) ;
162
162
}
163
163
164
164
/// <summary>
@@ -359,7 +359,7 @@ private static Type GetUnsignedType(Type t) =>
359
359
t == typeof ( long ) ? typeof ( ulong ) :
360
360
null ;
361
361
362
- public static ulong ZigZagEncode ( long d , int bytes ) => ( ulong ) ( ( ( d >> ( bytes * 8 - 1 ) ) & 1 ) | ( d << 1 ) ) ;
362
+ public static ulong ZigZagEncode ( long d ) => ( ulong ) ( ( ( d >> 63 ) & 1 ) | ( d << 1 ) ) ;
363
363
364
364
public static long GetBitCount < T > ( T t )
365
365
{
0 commit comments