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 1
1
using System ;
2
2
using System . Collections . Generic ;
3
- using System . Diagnostics ;
4
3
using System . Reflection ;
5
4
using System . Runtime . InteropServices ;
6
5
using System . Text ;
@@ -114,6 +113,26 @@ public void PushArray<T>(T[] t, bool knownSize = false)
114
113
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 ) ;
115
114
}
116
115
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.
117
136
public long Finalize ( ref byte [ ] buffer )
118
137
{
119
138
if ( buffer == null )
@@ -145,7 +164,7 @@ public long Finalize(ref byte[] buffer)
145
164
public long GetFinalizeSize ( )
146
165
{
147
166
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 ] ) ;
149
168
return ( ( bitCount / 8 ) + ( bitCount % 8 == 0 ? 0 : 1 ) ) ;
150
169
}
151
170
You can’t perform that action at this time.
0 commit comments