make more use of igbinary_serialize() and igbinary_unserialize()

This commit is contained in:
Dylan K. Taylor 2020-06-17 23:03:03 +01:00
parent 6f4d4be3da
commit 82b3e3398b
4 changed files with 18 additions and 18 deletions

View File

@ -32,9 +32,9 @@ use pocketmine\network\mcpe\protocol\types\login\JwtChainLinkBody;
use pocketmine\network\mcpe\protocol\types\login\JwtHeader; use pocketmine\network\mcpe\protocol\types\login\JwtHeader;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use function base64_decode; use function base64_decode;
use function serialize; use function igbinary_serialize;
use function igbinary_unserialize;
use function time; use function time;
use function unserialize;
class ProcessLoginTask extends AsyncTask{ class ProcessLoginTask extends AsyncTask{
private const TLS_KEY_ON_COMPLETION = "completion"; private const TLS_KEY_ON_COMPLETION = "completion";
@ -73,7 +73,7 @@ class ProcessLoginTask extends AsyncTask{
*/ */
public function __construct(array $chainJwts, string $clientDataJwt, bool $authRequired, \Closure $onCompletion){ public function __construct(array $chainJwts, string $clientDataJwt, bool $authRequired, \Closure $onCompletion){
$this->storeLocal(self::TLS_KEY_ON_COMPLETION, $onCompletion); $this->storeLocal(self::TLS_KEY_ON_COMPLETION, $onCompletion);
$this->chain = serialize($chainJwts); $this->chain = igbinary_serialize($chainJwts);
$this->clientDataJwt = $clientDataJwt; $this->clientDataJwt = $clientDataJwt;
$this->authRequired = $authRequired; $this->authRequired = $authRequired;
} }
@ -89,7 +89,7 @@ class ProcessLoginTask extends AsyncTask{
private function validateChain() : PublicKeyInterface{ private function validateChain() : PublicKeyInterface{
/** @var string[] $chain */ /** @var string[] $chain */
$chain = unserialize($this->chain); $chain = igbinary_unserialize($this->chain);
$currentKey = null; $currentKey = null;
$first = true; $first = true;

View File

@ -24,11 +24,11 @@ declare(strict_types=1);
namespace pocketmine\scheduler; namespace pocketmine\scheduler;
use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\AssumptionFailedError;
use function igbinary_serialize;
use function igbinary_unserialize;
use function is_scalar; use function is_scalar;
use function is_string; use function is_string;
use function serialize;
use function spl_object_id; use function spl_object_id;
use function unserialize;
/** /**
* Class used to run async tasks in other threads. * Class used to run async tasks in other threads.
@ -109,7 +109,7 @@ abstract class AsyncTask extends \Threaded{
public function getResult(){ public function getResult(){
if($this->serialized){ if($this->serialized){
if(!is_string($this->result)) throw new AssumptionFailedError("Result expected to be a serialized string"); if(!is_string($this->result)) throw new AssumptionFailedError("Result expected to be a serialized string");
return unserialize($this->result); return igbinary_unserialize($this->result);
} }
return $this->result; return $this->result;
} }
@ -130,7 +130,7 @@ abstract class AsyncTask extends \Threaded{
* @param mixed $result * @param mixed $result
*/ */
public function setResult($result) : void{ public function setResult($result) : void{
$this->result = ($this->serialized = !is_scalar($result)) ? serialize($result) : $result; $this->result = ($this->serialized = !is_scalar($result)) ? igbinary_serialize($result) : $result;
} }
public function setSubmitted() : void{ public function setSubmitted() : void{
@ -161,7 +161,7 @@ abstract class AsyncTask extends \Threaded{
* @param mixed $progress A value that can be safely serialize()'ed. * @param mixed $progress A value that can be safely serialize()'ed.
*/ */
public function publishProgress($progress) : void{ public function publishProgress($progress) : void{
$this->progressUpdates[] = serialize($progress); $this->progressUpdates[] = igbinary_serialize($progress);
} }
/** /**
@ -170,7 +170,7 @@ abstract class AsyncTask extends \Threaded{
public function checkProgressUpdates() : void{ public function checkProgressUpdates() : void{
while($this->progressUpdates->count() !== 0){ while($this->progressUpdates->count() !== 0){
$progress = $this->progressUpdates->shift(); $progress = $this->progressUpdates->shift();
$this->onProgressUpdate(unserialize($progress)); $this->onProgressUpdate(igbinary_unserialize($progress));
} }
} }

View File

@ -25,8 +25,8 @@ namespace pocketmine\scheduler;
use pocketmine\utils\Internet; use pocketmine\utils\Internet;
use pocketmine\utils\InternetException; use pocketmine\utils\InternetException;
use function serialize; use function igbinary_serialize;
use function unserialize; use function igbinary_unserialize;
/** /**
* Executes a consecutive list of cURL operations. * Executes a consecutive list of cURL operations.
@ -48,12 +48,12 @@ class BulkCurlTask extends AsyncTask{
* @phpstan-param list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations * @phpstan-param list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations
*/ */
public function __construct(array $operations){ public function __construct(array $operations){
$this->operations = serialize($operations); $this->operations = igbinary_serialize($operations);
} }
public function onRun() : void{ public function onRun() : void{
/** @phpstan-var list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations */ /** @phpstan-var list<array{page: string, timeout?: float, extraHeaders?: list<string>, extraOpts?: array<int, mixed>}> $operations */
$operations = unserialize($this->operations); $operations = igbinary_unserialize($this->operations);
$results = []; $results = [];
foreach($operations as $op){ foreach($operations as $op){
try{ try{

View File

@ -26,8 +26,8 @@ namespace pocketmine\world\generator;
use pocketmine\scheduler\AsyncTask; use pocketmine\scheduler\AsyncTask;
use pocketmine\world\biome\Biome; use pocketmine\world\biome\Biome;
use pocketmine\world\World; use pocketmine\world\World;
use function serialize; use function igbinary_serialize;
use function unserialize; use function igbinary_unserialize;
class GeneratorRegisterTask extends AsyncTask{ class GeneratorRegisterTask extends AsyncTask{
@ -48,7 +48,7 @@ class GeneratorRegisterTask extends AsyncTask{
*/ */
public function __construct(World $world, string $generatorClass, array $generatorSettings = []){ public function __construct(World $world, string $generatorClass, array $generatorSettings = []){
$this->generatorClass = $generatorClass; $this->generatorClass = $generatorClass;
$this->settings = serialize($generatorSettings); $this->settings = igbinary_serialize($generatorSettings);
$this->seed = $world->getSeed(); $this->seed = $world->getSeed();
$this->worldId = $world->getId(); $this->worldId = $world->getId();
$this->worldHeight = $world->getWorldHeight(); $this->worldHeight = $world->getWorldHeight();
@ -63,7 +63,7 @@ class GeneratorRegisterTask extends AsyncTask{
* @var Generator $generator * @var Generator $generator
* @see Generator::__construct() * @see Generator::__construct()
*/ */
$generator = new $this->generatorClass($manager, $this->seed, unserialize($this->settings)); $generator = new $this->generatorClass($manager, $this->seed, igbinary_unserialize($this->settings));
$this->worker->saveToThreadStore("generation.world{$this->worldId}.generator", $generator); $this->worker->saveToThreadStore("generation.world{$this->worldId}.generator", $generator);
} }
} }