Moved network NBT serializer into network namespace

This commit is contained in:
Dylan K. Taylor 2018-12-29 20:12:00 +00:00
parent ac87319aed
commit 7b3115c00c
4 changed files with 85 additions and 6 deletions

8
composer.lock generated
View File

@ -310,12 +310,12 @@
"source": {
"type": "git",
"url": "https://github.com/pmmp/NBT.git",
"reference": "91b6a158d06032e9029b9a87be64a12c3b93aa14"
"reference": "a32760c1797280574c461e6c42502221de499d01"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/91b6a158d06032e9029b9a87be64a12c3b93aa14",
"reference": "91b6a158d06032e9029b9a87be64a12c3b93aa14",
"url": "https://api.github.com/repos/pmmp/NBT/zipball/a32760c1797280574c461e6c42502221de499d01",
"reference": "a32760c1797280574c461e6c42502221de499d01",
"shasum": ""
},
"require": {
@ -343,7 +343,7 @@
"source": "https://github.com/pmmp/NBT/tree/master",
"issues": "https://github.com/pmmp/NBT/issues"
},
"time": "2018-12-03T16:12:37+00:00"
"time": "2018-12-29T19:46:47+00:00"
},
{
"name": "pocketmine/raklib",

View File

@ -88,13 +88,13 @@ use pocketmine\level\Level;
use pocketmine\level\Position;
use pocketmine\math\Vector3;
use pocketmine\metadata\MetadataValue;
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\ByteTag;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\DoubleTag;
use pocketmine\nbt\tag\ListTag;
use pocketmine\network\mcpe\CompressBatchPromise;
use pocketmine\network\mcpe\NetworkCipher;
use pocketmine\network\mcpe\NetworkLittleEndianNBTStream;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;

View File

@ -0,0 +1,79 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program 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.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\network\mcpe;
use pocketmine\nbt\LittleEndianNBTStream;
#ifndef COMPILE
use pocketmine\utils\Binary;
#endif
#include <rules/NBT.h>
class NetworkLittleEndianNBTStream extends LittleEndianNBTStream{
public function getInt() : int{
return Binary::readVarInt($this->buffer, $this->offset);
}
public function putInt(int $v) : void{
$this->put(Binary::writeVarInt($v));
}
public function getLong() : int{
return Binary::readVarLong($this->buffer, $this->offset);
}
public function putLong(int $v) : void{
$this->put(Binary::writeVarLong($v));
}
public function getString() : string{
return $this->get(Binary::readUnsignedVarInt($this->buffer, $this->offset));
}
public function putString(string $v) : void{
$len = strlen($v);
if($len > 32767){
throw new \InvalidArgumentException("NBT strings cannot be longer than 32767 bytes, got $len bytes");
}
$this->put(Binary::writeUnsignedVarInt($len) . $v);
}
public function getIntArray() : array{
$len = $this->getInt(); //varint
$ret = [];
for($i = 0; $i < $len; ++$i){
$ret[] = $this->getInt(); //varint
}
return $ret;
}
public function putIntArray(array $array) : void{
$this->putInt(count($array)); //varint
foreach($array as $v){
$this->putInt($v); //varint
}
}
}

View File

@ -23,10 +23,10 @@ declare(strict_types=1);
namespace pocketmine\tile;
use pocketmine\nbt\NetworkLittleEndianNBTStream;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
use pocketmine\nbt\tag\StringTag;
use pocketmine\network\mcpe\NetworkLittleEndianNBTStream;
use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\Player;