From 92eaf84dd61f700d3ec02ebd01b606cb5b1590d4 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 7 Feb 2019 16:28:11 +0000 Subject: [PATCH] NBTStream: allow specifying an offset parameter to read() 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. --- src/NBTStream.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/NBTStream.php b/src/NBTStream.php index c8aa0d8..79197e3 100644 --- a/src/NBTStream.php +++ b/src/NBTStream.php @@ -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();