PocketMine-MP 5.44.4 git-6a7cc02e9dff59b69241aa0bcffdb9903ce86beb
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 decodeTransaction(ByteBufferReader $in) : void{
42 $actionCount = VarInt::readUnsignedInt($in);
43 $this->actions = [];
44 for($i = 0; $i < $actionCount; ++$i){
45 $this->actions[] = (new NetworkInventoryAction())->readTransaction($in);
46 }
47 $this->decodeData($in);
48 }
49
54 final public function decodeAuthInput(ByteBufferReader $in) : void{
55 $actionCount = VarInt::readUnsignedInt($in);
56 $this->actions = [];
57 for($i = 0; $i < $actionCount; ++$i){
58 $this->actions[] = (new NetworkInventoryAction())->readAuthInput($in);
59 }
60 $this->decodeData($in);
61 }
62
67 abstract protected function decodeData(ByteBufferReader $in) : void;
68
69 final public function encodeTransaction(ByteBufferWriter $out) : void{
70 VarInt::writeUnsignedInt($out, count($this->actions));
71 foreach($this->actions as $action){
72 $action->writeTransaction($out);
73 }
74 $this->encodeData($out);
75 }
76
77 final public function encodeAuthInput(ByteBufferWriter $out) : void{
78 VarInt::writeUnsignedInt($out, count($this->actions));
79 foreach($this->actions as $action){
80 $action->writeAuthInput($out);
81 }
82 $this->encodeData($out);
83 }
84
85 abstract protected function encodeData(ByteBufferWriter $out) : void;
86}