@@ -110,10 +110,10 @@ private void Push<T>(T b)
110110 public void WriteUShort ( ushort s ) => Push ( s ) ;
111111 public void WriteUInt ( uint i ) => Push ( i ) ;
112112 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 ) ) ;
117117 public void WriteString ( string s ) => Push ( s ) ;
118118 public void WriteAlignBits ( ) => Push < object > ( null ) ;
119119 public void WriteFloatArray ( float [ ] f , bool known = false ) => PushArray ( f , known ) ;
@@ -149,16 +149,16 @@ private void PushArray<T>(T[] t, bool knownSize = false)
149149 {
150150 if ( ! knownSize ) Push ( ( uint ) t . Length ) ;
151151 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 ) ;
154154 }
155155
156156 private void PushArray < T > ( T [ ] t , int startIndex , int length , bool knownSize = false )
157157 {
158158 if ( ! knownSize ) Push ( ( uint ) t . Length ) ;
159159 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 ] ) ;
162162 }
163163
164164 /// <summary>
@@ -359,7 +359,7 @@ private static Type GetUnsignedType(Type t) =>
359359 t == typeof ( long ) ? typeof ( ulong ) :
360360 null ;
361361
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 ) ) ;
363363
364364 public static long GetBitCount < T > ( T t )
365365 {
0 commit comments