@@ -157,6 +157,10 @@ public function readUInt8() {
157
157
return ord ($ this ->read (1 ));
158
158
}
159
159
160
+ public function readUInt8Many ($ count ) {
161
+ return array_values (unpack ("C* " , $ this ->read ($ count )));
162
+ }
163
+
160
164
public function writeUInt8 ($ data ) {
161
165
return $ this ->write (chr ($ data ), 1 );
162
166
}
@@ -171,6 +175,10 @@ public function readInt8() {
171
175
return $ v ;
172
176
}
173
177
178
+ public function readInt8Many ($ count ) {
179
+ return array_values (unpack ("c* " , $ this ->read ($ count )));
180
+ }
181
+
174
182
public function writeInt8 ($ data ) {
175
183
if ($ data < 0 ) {
176
184
$ data += 0x100 ;
@@ -185,6 +193,10 @@ public function readUInt16() {
185
193
return $ a ["n " ];
186
194
}
187
195
196
+ public function readUInt16Many ($ count ) {
197
+ return array_values (unpack ("n* " , $ this ->read ($ count * 2 )));
198
+ }
199
+
188
200
public function readUFWord () {
189
201
return $ this ->readUInt16 ();
190
202
}
@@ -207,6 +219,17 @@ public function readInt16() {
207
219
return $ v ;
208
220
}
209
221
222
+ public function readInt16Many ($ count ) {
223
+ $ vals = array_values (unpack ("n* " , $ this ->read ($ count * 2 )));
224
+ foreach ($ vals as &$ v ) {
225
+ if ($ v >= 0x8000 ) {
226
+ $ v -= 0x10000 ;
227
+ }
228
+ }
229
+
230
+ return $ vals ;
231
+ }
232
+
210
233
public function readFWord () {
211
234
return $ this ->readInt16 ();
212
235
}
@@ -319,6 +342,18 @@ public function r($type) {
319
342
if ($ type [0 ] == self ::char) {
320
343
return $ this ->read ($ type [1 ]);
321
344
}
345
+ if ($ type [0 ] == self ::uint16) {
346
+ return $ this ->readUInt16Many ($ type [1 ]);
347
+ }
348
+ if ($ type [0 ] == self ::int16) {
349
+ return $ this ->readInt16Many ($ type [1 ]);
350
+ }
351
+ if ($ type [0 ] == self ::uint8) {
352
+ return $ this ->readUInt8Many ($ type [1 ]);
353
+ }
354
+ if ($ type [0 ] == self ::int8) {
355
+ return $ this ->readInt8Many ($ type [1 ]);
356
+ }
322
357
323
358
$ ret = array ();
324
359
for ($ i = 0 ; $ i < $ type [1 ]; $ i ++) {
0 commit comments