mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 09:56:06 +00:00
Moved network NBT serializer into network namespace
This commit is contained in:
79
src/pocketmine/network/mcpe/NetworkLittleEndianNBTStream.php
Normal file
79
src/pocketmine/network/mcpe/NetworkLittleEndianNBTStream.php
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user