Updated NBT/DataPacket reading

This commit is contained in:
Shoghi Cervantes 2014-10-31 00:32:50 +01:00
parent f72d7284b9
commit 82cfe6ea9c
2 changed files with 4 additions and 18 deletions

View File

@ -72,23 +72,15 @@ class NBT{
public $endianness;
private $data;
public function get($len){
protected function get($len){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
if($len > 16){
return substr($this->buffer, ($this->offset += $len) - $len, $len);
}
$buffer = "";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
return $len === 1 ? $this->buffer{$this->offset++} : substr($this->buffer, ($this->offset += $len) - $len, $len);
}
public function put($v){

View File

@ -115,20 +115,14 @@ abstract class DataPacket extends \stdClass{
}
protected function get($len){
if($len <= 0){
if($len < 0){
$this->offset = strlen($this->buffer) - 1;
return "";
}elseif($len === true){
return substr($this->buffer, $this->offset);
}
$buffer = "";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= $this->buffer{$this->offset};
}
return $buffer;
return $len === 1 ? $this->buffer{$this->offset++} : substr($this->buffer, ($this->offset += $len) - $len, $len);
}
protected function put($str){