PocketMine-MP 5.18.2 git-00e39821f06a4b6d728d35053c2621dbb19369ff
raklib/src/protocol/Packet.php
1<?php
2
3/*
4 * This file is part of RakLib.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/RakLib>
6 *
7 * RakLib is not affiliated with Jenkins Software LLC nor RakNet.
8 *
9 * RakLib is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 */
14
15declare(strict_types=1);
16
17namespace raklib\protocol;
18
20
21abstract class Packet{
23 public static $ID = -1;
24
25 public function encode(PacketSerializer $out) : void{
26 $this->encodeHeader($out);
27 $this->encodePayload($out);
28 }
29
30 protected function encodeHeader(PacketSerializer $out) : void{
31 $out->putByte(static::$ID);
32 }
33
34 abstract protected function encodePayload(PacketSerializer $out) : void;
35
39 public function decode(PacketSerializer $in) : void{
40 $this->decodeHeader($in);
41 $this->decodePayload($in);
42 }
43
47 protected function decodeHeader(PacketSerializer $in) : void{
48 $in->getByte(); //PID
49 }
50
54 abstract protected function decodePayload(PacketSerializer $in) : void;
55}
decodePayload(PacketSerializer $in)
decodeHeader(PacketSerializer $in)