Skip to content

Commit

Permalink
NBTStream: allow specifying an offset parameter to read()
Browse files Browse the repository at this point in the history
this permits reading directly from a buffer ptr without substr(). The parameter is a reference and will be updated to reflect the point where the reader stopped reading.
  • Loading branch information
dktapps committed Feb 7, 2019
1 parent 49d4181 commit 92eaf84
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/NBTStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public function feof() : bool{
*
* @param string $buffer
* @param bool $doMultiple Whether to keep reading after the first tag if there are more bytes in the buffer
* @param int &$offset
*
* @return NamedTag|NamedTag[]
*/
public function read(string $buffer, bool $doMultiple = false){
$this->offset = 0;
public function read(string $buffer, bool $doMultiple = false, int &$offset = 0){
$this->offset = &$offset;
$this->buffer = $buffer;
$data = $this->readTag();

Expand Down

0 comments on commit 92eaf84

Please sign in to comment.