PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
TransactionData.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol\types\inventory;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\DataDecodeException;
20use pmmp\encoding\VarInt;
22use function count;
23
24abstract class TransactionData{
26 protected array $actions = [];
27
31 final public function getActions() : array{
32 return $this->actions;
33 }
34
35 abstract public function getTypeId() : int;
36
41 final public function decode(ByteBufferReader $in) : void{
42 $actionCount = VarInt::readUnsignedInt($in);
43 for($i = 0; $i < $actionCount; ++$i){
44 $this->actions[] = (new NetworkInventoryAction())->read($in);
45 }
46 $this->decodeData($in);
47 }
48
53 abstract protected function decodeData(ByteBufferReader $in) : void;
54
55 final public function encode(ByteBufferWriter $out) : void{
56 VarInt::writeUnsignedInt($out, count($this->actions));
57 foreach($this->actions as $action){
58 $action->write($out);
59 }
60 $this->encodeData($out);
61 }
62
63 abstract protected function encodeData(ByteBufferWriter $out) : void;
64}