mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 10:49:10 +00:00
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
namespace pocketmine\network\protocol;
|
|
|
|
#include <rules/DataPacket.h>
|
|
|
|
#ifndef COMPILE
|
|
|
|
#endif
|
|
|
|
|
|
use pocketmine\utils\BinaryStream;
|
|
use pocketmine\utils\Utils;
|
|
|
|
|
|
abstract class DataPacket extends BinaryStream{
|
|
|
|
const NETWORK_ID = 0;
|
|
|
|
public $isEncoded = false;
|
|
|
|
public function pid(){
|
|
return $this::NETWORK_ID;
|
|
}
|
|
|
|
abstract public function encode();
|
|
|
|
abstract public function decode();
|
|
|
|
public function reset(){
|
|
$this->buffer = chr($this::NETWORK_ID);
|
|
$this->offset = 0;
|
|
}
|
|
|
|
public function clean(){
|
|
$this->buffer = null;
|
|
$this->isEncoded = false;
|
|
$this->offset = 0;
|
|
return $this;
|
|
}
|
|
|
|
public function __debugInfo(){
|
|
$data = [];
|
|
foreach($this as $k => $v){
|
|
if($k === "buffer"){
|
|
$data[$k] = bin2hex($v);
|
|
}elseif(is_string($v) or (is_object($v) and method_exists($v, "__toString"))){
|
|
$data[$k] = Utils::printable((string) $v);
|
|
}else{
|
|
$data[$k] = $v;
|
|
}
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|