mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-11 00:09:39 +00:00
DataPacket: encode() and decode() are now final, encodePayload() and decodePayload() are now abstract
This commit is contained in:
parent
60687d8d6c
commit
c559dfccfe
@ -65,7 +65,7 @@ abstract class DataPacket extends NetworkBinaryStream{
|
|||||||
* @throws \OutOfBoundsException
|
* @throws \OutOfBoundsException
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
public function decode() : void{
|
final public function decode() : void{
|
||||||
$this->rewind();
|
$this->rewind();
|
||||||
$this->decodeHeader();
|
$this->decodeHeader();
|
||||||
$this->decodePayload();
|
$this->decodePayload();
|
||||||
@ -83,16 +83,14 @@ abstract class DataPacket extends NetworkBinaryStream{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note for plugin developers: If you're adding your own packets, you should perform decoding in here.
|
* Decodes the packet body, without the packet ID or other generic header fields.
|
||||||
*
|
*
|
||||||
* @throws \OutOfBoundsException
|
* @throws \OutOfBoundsException
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
*/
|
*/
|
||||||
protected function decodePayload() : void{
|
abstract protected function decodePayload() : void;
|
||||||
|
|
||||||
}
|
final public function encode() : void{
|
||||||
|
|
||||||
public function encode() : void{
|
|
||||||
$this->reset();
|
$this->reset();
|
||||||
$this->encodeHeader();
|
$this->encodeHeader();
|
||||||
$this->encodePayload();
|
$this->encodePayload();
|
||||||
@ -104,11 +102,9 @@ abstract class DataPacket extends NetworkBinaryStream{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note for plugin developers: If you're adding your own packets, you should perform encoding in here.
|
* Encodes the packet body, without the packet ID or other generic header fields.
|
||||||
*/
|
*/
|
||||||
protected function encodePayload() : void{
|
abstract protected function encodePayload() : void;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs handling for this packet. Usually you'll want an appropriately named method in the session handler for
|
* Performs handling for this packet. Usually you'll want an appropriately named method in the session handler for
|
||||||
|
@ -44,12 +44,19 @@ class UnknownPacket extends DataPacket{
|
|||||||
return "unknown packet";
|
return "unknown packet";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function decode() : void{
|
protected function decodeHeader() : void{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function decodePayload() : void{
|
||||||
$this->payload = $this->getRemaining();
|
$this->payload = $this->getRemaining();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function encode() : void{
|
protected function encodeHeader() : void{
|
||||||
//Do not reset the buffer, this class does not have a valid NETWORK_ID constant.
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function encodePayload() : void{
|
||||||
$this->put($this->payload);
|
$this->put($this->payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user