PacketBatch no longer extends NetworkBinaryStream

this removes a whole bunch of crap from its API that shouldn't have been exposed. In the future we should look at splitting this into reader/writer halves, but for now this is a step in the right direction.
This commit is contained in:
Dylan K. Taylor 2020-05-18 17:35:30 +01:00
parent e96b082a54
commit 486ce140d8

View File

@ -27,18 +27,25 @@ use pocketmine\network\mcpe\protocol\Packet;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\utils\BinaryDataException;
class PacketBatch extends NetworkBinaryStream{
class PacketBatch{
/** @var NetworkBinaryStream */
private $binaryStream;
public function __construct(?string $buffer = null){
$this->binaryStream = new NetworkBinaryStream($buffer ?? "");
}
public function putPacket(Packet $packet) : void{
$packet->encode();
$this->putString($packet->getBinaryStream()->getBuffer());
$this->binaryStream->putString($packet->getBinaryStream()->getBuffer());
}
/**
* @throws BinaryDataException
*/
public function getPacket(PacketPool $packetPool) : Packet{
return $packetPool->getPacket($this->getString());
return $packetPool->getPacket($this->binaryStream->getString());
}
/**
@ -55,4 +62,12 @@ class PacketBatch extends NetworkBinaryStream{
}
return $result;
}
public function getBuffer() : string{
return $this->binaryStream->getBuffer();
}
public function feof() : bool{
return $this->binaryStream->feof();
}
}