File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
MLAPI/NetworkingManagerComponents/Binary Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3- using System . Diagnostics ;
43using System . Reflection ;
54using System . Runtime . InteropServices ;
65using System . Text ;
@@ -114,6 +113,26 @@ public void PushArray<T>(T[] t, bool knownSize = false)
114113 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 ) ;
115114 }
116115
116+ public byte [ ] Finalize ( )
117+ {
118+ long bitCount = 0 ;
119+ for ( int i = 0 ; i < collect . Count ; ++ i ) bitCount += collect [ i ] == null ? ( 8 - ( bitCount % 8 ) ) % 8 : GetBitCount ( collect [ i ] ) ;
120+ byte [ ] buffer = new byte [ ( ( bitCount / 8 ) + ( bitCount % 8 == 0 ? 0 : 1 ) ) ] ;
121+
122+ long bitOffset = 0 ;
123+ bool isAligned = true ;
124+ foreach ( var item in collect )
125+ if ( item == null )
126+ {
127+ bitOffset += ( 8 - ( bitOffset % 8 ) ) % 8 ;
128+ isAligned = true ;
129+ }
130+ else Serialize ( item , buffer , ref bitOffset , ref isAligned ) ;
131+
132+ return buffer ;
133+ }
134+
135+ //The ref is not needed. It's purley there to indicate that it's treated as a reference inside the method.
117136 public long Finalize ( ref byte [ ] buffer )
118137 {
119138 if ( buffer == null )
@@ -145,7 +164,7 @@ public long Finalize(ref byte[] buffer)
145164 public long GetFinalizeSize ( )
146165 {
147166 long bitCount = 0 ;
148- for ( int i = 0 ; i < collect . Count ; ++ i ) bitCount += collect [ i ] == null ? ( 8 - ( bitCount % 8 ) ) % 8 : GetBitCount ( collect [ i ] ) ;
167+ for ( int i = 0 ; i < collect . Count ; ++ i ) bitCount += collect [ i ] == null ? ( 8 - ( bitCount % 8 ) ) % 8 : GetBitCount ( collect [ i ] ) ;
149168 return ( ( bitCount / 8 ) + ( bitCount % 8 == 0 ? 0 : 1 ) ) ;
150169 }
151170
You can’t perform that action at this time.
0 commit comments