PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
ClientCacheMissResponsePacket.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;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
23use function count;
24
26 public const NETWORK_ID = ProtocolInfo::CLIENT_CACHE_MISS_RESPONSE_PACKET;
27
29 private array $blobs = [];
30
35 public static function create(array $blobs) : self{
36 $result = new self;
37 $result->blobs = $blobs;
38 return $result;
39 }
40
44 public function getBlobs() : array{
45 return $this->blobs;
46 }
47
48 protected function decodePayload(ByteBufferReader $in) : void{
49 for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; ++$i){
50 $hash = LE::readUnsignedLong($in);
51 $payload = CommonTypes::getString($in);
52 $this->blobs[] = new ChunkCacheBlob($hash, $payload);
53 }
54 }
55
56 protected function encodePayload(ByteBufferWriter $out) : void{
57 VarInt::writeUnsignedInt($out, count($this->blobs));
58 foreach($this->blobs as $blob){
59 LE::writeUnsignedLong($out, $blob->getHash());
60 CommonTypes::putString($out, $blob->getPayload());
61 }
62 }
63
64 public function handle(PacketHandlerInterface $handler) : bool{
65 return $handler->handleClientCacheMissResponse($this);
66 }
67}