0
0
mirror of https://github.com/pmmp/BedrockProtocol.git synced 2025-09-22 02:49:31 +00:00
Files
BedrockProtocol/tests/phpunit/DataPacketTest.php
Dylan T. 5ad5f12a1e Migrate encode & decode to use ext-encoding (really big commit) (#322)
- PacketSerializer is now gone
- All places which previously used ByteBufferReader and ByteBufferWriter instead of PacketSerializer/BinaryStream
- All helper methods previously in PacketSerializer are now provided as CommonTypes:: static methods instead

BinaryUtils is still required for now since there's a couple of places where it's still irreplaceable. But all encoding and decoding is now done using ext-encoding, which should yield significant performance improvements.

Stable version of NBT is still used for the time being as we don't want to be forced to fully switch over to ext-encoding right away. Doing network only is safer for now since there'll be no lasting damage done if there are growing pains. Proper integration of ext-encoding+NBT will come later. For now, this is enough to net some gains.
2025-09-21 00:05:42 +01:00

37 lines
996 B
PHP

<?php
/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe\protocol;
use PHPUnit\Framework\TestCase;
use pmmp\encoding\ByteBufferReader;
use pmmp\encoding\ByteBufferWriter;
class DataPacketTest extends TestCase{
public function testHeaderFidelity() : void{
$pk = new TestPacket();
$pk->senderSubId = 3;
$pk->recipientSubId = 2;
$serializer = new ByteBufferWriter();
$pk->encode($serializer);
$pk2 = new TestPacket();
$pk2->decode(new ByteBufferReader($serializer->getData()));
self::assertSame($pk2->senderSubId, 3);
self::assertSame($pk2->recipientSubId, 2);
}
}