mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
PacketBatch: get rid of putPacket()
This commit is contained in:
parent
2fcee432c1
commit
798efc370c
@ -37,11 +37,6 @@ class PacketBatch{
|
||||
$this->serializer = new PacketSerializer($buffer ?? "");
|
||||
}
|
||||
|
||||
public function putPacket(Packet $packet) : void{
|
||||
$packet->encode();
|
||||
$this->serializer->putString($packet->getSerializer()->getBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BinaryDataException
|
||||
*/
|
||||
@ -72,7 +67,8 @@ class PacketBatch{
|
||||
public static function fromPackets(Packet ...$packets) : self{
|
||||
$result = new self();
|
||||
foreach($packets as $packet){
|
||||
$result->putPacket($packet);
|
||||
$packet->encode();
|
||||
$result->serializer->putString($packet->getSerializer()->getBuffer());
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
@ -23,21 +23,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\mcpe\protocol\serializer;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\Packet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use pocketmine\network\mcpe\protocol\PacketDecodeException;
|
||||
use pocketmine\network\mcpe\protocol\PacketPool;
|
||||
use pocketmine\network\mcpe\protocol\serializer\PacketBatch;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use pocketmine\network\mcpe\protocol\TestPacket;
|
||||
use function array_fill;
|
||||
|
||||
class PacketBatchTest extends TestCase{
|
||||
|
||||
public function testDecodeTooBig() : void{
|
||||
$limit = 10;
|
||||
$write = new PacketBatch();
|
||||
for($i = 0; $i < $limit + 1; $i++){
|
||||
$write->putPacket(new TestPacket());
|
||||
}
|
||||
$write = PacketBatch::fromPackets(...array_fill(0, $limit + 1, new TestPacket()));
|
||||
$read = new PacketBatch($write->getBuffer());
|
||||
$this->expectException(PacketDecodeException::class);
|
||||
$readCount = 0;
|
||||
@ -48,10 +45,7 @@ class PacketBatchTest extends TestCase{
|
||||
|
||||
public function testDecodeAtLimit() : void{
|
||||
$limit = 10;
|
||||
$write = new PacketBatch();
|
||||
for($i = 0; $i < $limit; $i++){
|
||||
$write->putPacket(new TestPacket());
|
||||
}
|
||||
$write = PacketBatch::fromPackets(...array_fill(0, $limit, new TestPacket()));
|
||||
$read = new PacketBatch($write->getBuffer());
|
||||
$readCount = 0;
|
||||
foreach($read->getPackets(PacketPool::getInstance(), $limit) as $packet){
|
||||
|
Loading…
x
Reference in New Issue
Block a user