PocketMine-MP
5.21.2 git-b2aa6396c3cc2cafdd815eacc360e1ad89599899
Loading...
Searching...
No Matches
PacketBatch.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
13
declare(strict_types=1);
14
15
namespace
pocketmine\network\mcpe\protocol\serializer;
16
17
use
pocketmine\network\mcpe\protocol\Packet
;
18
use
pocketmine\network\mcpe\protocol\PacketDecodeException
;
19
use
pocketmine\network\mcpe\protocol\PacketPool
;
20
use
pocketmine\utils\BinaryDataException
;
21
use
pocketmine\utils\BinaryStream
;
22
use
function
strlen;
23
24
class
PacketBatch
{
25
26
private
function
__construct(){
27
//NOOP
28
}
29
34
final
public
static
function
decodeRaw
(
BinaryStream
$stream) : \
Generator
{
35
$c = 0;
36
while
(!$stream->
feof
()){
37
try
{
38
$length = $stream->
getUnsignedVarInt
();
39
$buffer = $stream->
get
($length);
40
}
catch
(
BinaryDataException
$e){
41
throw
new
PacketDecodeException
(
"Error decoding packet $c in batch: "
. $e->getMessage(), 0, $e);
42
}
43
yield $buffer;
44
$c++;
45
}
46
}
47
52
final
public
static
function
encodeRaw
(
BinaryStream
$stream, array $packets) : void{
53
foreach($packets as $packet){
54
$stream->
putUnsignedVarInt
(strlen($packet));
55
$stream->put($packet);
56
}
57
}
58
63
final
public
static
function
decodePackets
(
BinaryStream
$stream,
PacketPool
$packetPool) : \
Generator
{
64
$c = 0;
65
foreach
(self::decodeRaw($stream) as $packetBuffer){
66
$packet = $packetPool->
getPacket
($packetBuffer);
67
if
($packet !==
null
){
68
try
{
69
$packet->decode(PacketSerializer::decoder($packetBuffer, 0));
70
}
catch
(
PacketDecodeException
$e){
71
throw
new
PacketDecodeException
(
"Error decoding packet $c in batch: "
. $e->getMessage(), 0, $e);
72
}
73
yield $packet;
74
}
else
{
75
throw
new
PacketDecodeException
(
"Unknown packet $c in batch"
);
76
}
77
$c++;
78
}
79
}
80
85
final
public
static
function
encodePackets
(
BinaryStream
$stream, array $packets) : void{
86
foreach($packets as $packet){
87
$serializer = PacketSerializer::encoder();
88
$packet->encode($serializer);
89
$stream->
putUnsignedVarInt
(strlen($serializer->getBuffer()));
90
$stream->put($serializer->getBuffer());
91
}
92
}
93
}
pocketmine\network\mcpe\protocol\PacketDecodeException
Definition
PacketDecodeException.php:17
pocketmine\network\mcpe\protocol\PacketPool
Definition
PacketPool.php:20
pocketmine\network\mcpe\protocol\PacketPool\getPacket
getPacket(string $buffer)
Definition
PacketPool.php:253
pocketmine\network\mcpe\protocol\serializer\PacketBatch
Definition
PacketBatch.php:24
pocketmine\network\mcpe\protocol\serializer\PacketBatch\encodePackets
static encodePackets(BinaryStream $stream, array $packets)
Definition
PacketBatch.php:85
pocketmine\network\mcpe\protocol\serializer\PacketBatch\decodePackets
static decodePackets(BinaryStream $stream, PacketPool $packetPool)
Definition
PacketBatch.php:63
pocketmine\network\mcpe\protocol\serializer\PacketBatch\encodeRaw
static encodeRaw(BinaryStream $stream, array $packets)
Definition
PacketBatch.php:52
pocketmine\network\mcpe\protocol\serializer\PacketBatch\decodeRaw
static decodeRaw(BinaryStream $stream)
Definition
PacketBatch.php:34
pocketmine\utils\BinaryDataException
Definition
BinaryDataException.php:26
pocketmine\utils\BinaryStream
Definition
BinaryStream.php:31
pocketmine\utils\BinaryStream\get
get(int $len)
Definition
BinaryStream.php:67
pocketmine\utils\BinaryStream\feof
feof()
Definition
BinaryStream.php:372
pocketmine\utils\BinaryStream\getUnsignedVarInt
getUnsignedVarInt()
Definition
BinaryStream.php:307
pocketmine\utils\BinaryStream\putUnsignedVarInt
putUnsignedVarInt(int $v)
Definition
BinaryStream.php:314
pocketmine\world\generator\Generator
Definition
Generator.php:34
pocketmine\network\mcpe\protocol\Packet
Definition
bedrock-protocol/src/Packet.php:19
vendor
pocketmine
bedrock-protocol
src
serializer
PacketBatch.php
Generated by
1.12.0