PocketMine-MP 5.39.3 git-66148f13a91e4af6778ba9f200ca25ad8a04a584
Loading...
Searching...
No Matches
CommandEnumRawData.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\LE;
20use pmmp\encoding\VarInt;
22use function count;
23
25
30 public function __construct(
31 private string $name,
32 private array $valueIndexes
33 ){}
34
35 public function getName() : string{ return $this->name; }
36
41 public function getValueIndexes() : array{ return $this->valueIndexes; }
42
43 public static function read(ByteBufferReader $in) : self{
44 $name = CommonTypes::getString($in);
45 $valueIndexes = [];
46 $size = VarInt::readUnsignedInt($in);
47
48 for($i = 0; $i < $size; $i++){
49 $valueIndexes[] = LE::readUnsignedInt($in);
50 }
51
52 return new self($name, $valueIndexes);
53 }
54
55 public function write(ByteBufferWriter $out) : void{
56 CommonTypes::putString($out, $this->name);
57 VarInt::writeUnsignedInt($out, count($this->valueIndexes));
58
59 foreach($this->valueIndexes as $index){
60 LE::writeUnsignedInt($out, $index);
61 }
62 }
63}
__construct(private string $name, private array $valueIndexes)