PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
ChainedSubCommandRawData.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\command\raw;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
21use function count;
22
24
29 public function __construct(
30 private string $name,
31 private array $valueData
32 ){}
33
34 public function getName() : string{ return $this->name; }
35
40 public function getValueData() : array{ return $this->valueData; }
41
42 public static function read(ByteBufferReader $in) : self{
43 $name = CommonTypes::getString($in);
44
45 $valueData = [];
46 for($i = 0, $size = VarInt::readUnsignedInt($in); $i < $size; $i++){
47 $valueData[] = ChainedSubCommandValueRawData::read($in);
48 }
49
50 return new self($name, $valueData);
51 }
52
53 public function write(ByteBufferWriter $out) : void{
54 CommonTypes::putString($out, $this->name);
55
56 VarInt::writeUnsignedInt($out, count($this->valueData));
57 foreach($this->valueData as $valueDatum){
58 $valueDatum->write($out);
59 }
60 }
61
62}