mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 02:08:21 +00:00
Cleaned up some bad code in DataPacket, added encode/decodeHeader and made encode/decodePayload protected
This commit is contained in:
@ -48,23 +48,12 @@ class BatchPacket extends DataPacket{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function decode(){
|
||||
$this->offset = 1;
|
||||
$this->decodePayload();
|
||||
protected function decodeHeader(){
|
||||
$pid = $this->getByte();
|
||||
assert($pid === static::NETWORK_ID);
|
||||
}
|
||||
|
||||
public function encode(){
|
||||
$this->reset();
|
||||
$this->encodePayload();
|
||||
$this->isEncoded = true;
|
||||
}
|
||||
|
||||
public function reset(){
|
||||
$this->buffer = "\xfe";
|
||||
$this->offset = 0;
|
||||
}
|
||||
|
||||
public function decodePayload(){
|
||||
protected function decodePayload(){
|
||||
$data = $this->getRemaining();
|
||||
try{
|
||||
$this->payload = zlib_decode($data, 1024 * 1024 * 64); //Max 64MB
|
||||
@ -73,7 +62,11 @@ class BatchPacket extends DataPacket{
|
||||
}
|
||||
}
|
||||
|
||||
public function encodePayload(){
|
||||
protected function encodeHeader(){
|
||||
$this->putByte(static::NETWORK_ID);
|
||||
}
|
||||
|
||||
protected function encodePayload(){
|
||||
$this->put(zlib_encode($this->payload, ZLIB_ENCODING_DEFLATE, $this->compressionLevel));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user