Faster NBT parsing

This commit is contained in:
Shoghi Cervantes 2014-03-05 10:37:14 +01:00
parent 98c0dfef43
commit 5f53f61121
2 changed files with 11 additions and 8 deletions

View File

@ -26,18 +26,21 @@ class NBT implements ArrayAccess{
private $buffer; private $buffer;
private $offset; private $offset;
private $endianness; private $endianness;
private $data; private $data;
public function get($len){ public function get($len){
if($len < 0){ if($len <= 0){
$this->offset = strlen($this->buffer) - 1; $this->offset = strlen($this->buffer) - 1;
return ""; return "";
} }elseif($len === true){
if($len === true){
return substr($this->buffer, $this->offset); return substr($this->buffer, $this->offset);
} }
$this->offset += $len;
return substr($this->buffer, $this->offset - $len, $len); $buffer = b"";
for(; $len > 0; --$len, ++$this->offset){
$buffer .= @$this->buffer{$this->offset};
}
return $buffer;
} }
public function put($v){ public function put($v){

View File

@ -31,7 +31,7 @@ class RakNetPacket extends Packet{
public function pid(){ public function pid(){
return $this->packetID; return $this->packetID;
} }
protected function get($len){ protected function get($len){
if($len <= 0){ if($len <= 0){
$this->offset = strlen($this->buffer) - 1; $this->offset = strlen($this->buffer) - 1;