File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 2424namespace pocketmine \nbt ;
2525
2626use pmmp \encoding \BE ;
27+ use function array_values ;
28+ use function assert ;
2729use function count ;
30+ use function pack ;
31+ use function unpack ;
2832
2933class BigEndianNbtSerializer extends BaseNbtSerializer{
3034
@@ -77,11 +81,14 @@ public function readIntArray() : array{
7781 if ($ len < 0 ){
7882 throw new NbtDataException ("Array length cannot be less than zero ( $ len < 0) " );
7983 }
80- return BE ::readSignedIntArray ($ this ->reader , $ len );
84+ /** @var array<int>|false $unpacked */
85+ $ unpacked = unpack ("N* " , $ this ->reader ->readByteArray ($ len * 4 ));
86+ assert ($ unpacked !== false , "The formatting string is valid, and we gave a multiple of 4 bytes " );
87+ return array_values ($ unpacked );
8188 }
8289
8390 public function writeIntArray (array $ array ) : void {
8491 $ this ->writeInt (count ($ array ));
85- BE :: writeSignedIntArray ( $ this ->writer , $ array );
92+ $ this ->writer -> writeByteArray ( pack ( " N* " , ... $ array) );
8693 }
8794}
Original file line number Diff line number Diff line change 2424namespace pocketmine \nbt ;
2525
2626use pmmp \encoding \LE ;
27+ use function array_values ;
28+ use function assert ;
2729use function count ;
30+ use function pack ;
31+ use function unpack ;
2832
2933class LittleEndianNbtSerializer extends BaseNbtSerializer{
3034
@@ -77,11 +81,14 @@ public function readIntArray() : array{
7781 if ($ len < 0 ){
7882 throw new NbtDataException ("Array length cannot be less than zero ( $ len < 0) " );
7983 }
80- return LE ::readSignedIntArray ($ this ->reader , $ len );
84+ /** @var array<int>|false $unpacked */
85+ $ unpacked = unpack ("V* " , $ this ->reader ->readByteArray ($ len * 4 ));
86+ assert ($ unpacked !== false , "The formatting string is valid, and we gave a multiple of 4 bytes " );
87+ return array_values ($ unpacked );
8188 }
8289
8390 public function writeIntArray (array $ array ) : void {
8491 $ this ->writeInt (count ($ array ));
85- LE :: writeSignedIntArray ( $ this ->writer , $ array );
92+ $ this ->writer -> writeByteArray ( pack ( " V* " , ... $ array) );
8693 }
8794}
You can’t perform that action at this time.
0 commit comments