Cleaned up some bad code in DataPacket, added encode/decodeHeader and made encode/decodePayload protected

This commit is contained in:
Dylan K. Taylor
2017-08-05 11:40:14 +01:00
parent 8a151dc373
commit 7886918140
110 changed files with 249 additions and 237 deletions

View File

@ -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));
}