39 public function __construct(){
47 private function readRoot(
int $maxDepth) :
TreeRoot{
49 if($type === NBT::TAG_End){
64 public function read(
string $buffer,
int &$offset = 0,
int $maxDepth = 0) :
TreeRoot{
68 $data = $this->readRoot($maxDepth);
72 $offset = $this->buffer->getOffset();
87 public function readHeadless(
string $buffer,
int $rootType,
int &$offset = 0,
int $maxDepth = 0) :
Tag{
91 $offset = $this->buffer->getOffset();
104 public function readMultiple(
string $buffer,
int $maxDepth = 0) : array{
109 while(!$this->buffer->feof()){
111 $retval[] = $this->readRoot($maxDepth);
113 throw new NbtDataException($e->getMessage(), 0, $e);
120 private function writeRoot(TreeRoot $root) : void{
121 $this->writeByte($root->getTag()->getType());
122 $this->writeString($root->getName());
123 $root->getTag()->write($this);
126 public function write(TreeRoot $data) : string{
127 $this->buffer = new BinaryStream();
129 $this->writeRoot($data);
131 return $this->buffer->getBuffer();
143 return $this->buffer->getBuffer();
151 foreach($data as $root){
152 $this->writeRoot($root);
154 return $this->buffer->getBuffer();
158 return $this->buffer->getByte();
162 return
Binary::signByte($this->buffer->getByte());
165 public function writeByte(
int $v) : void{
166 $this->buffer->putByte($v);
170 $length = $this->readInt();
172 throw new NbtDataException(
"Array length cannot be less than zero ($length < 0)");
174 return $this->buffer->get($length);
177 public function writeByteArray(
string $v) : void{
178 $this->writeInt(strlen($v));
179 $this->buffer->put($v);
197 throw new \InvalidArgumentException(
"NBT string length too large ($len > 32767)");
203 return $this->buffer->get(self::checkReadStringLength($this->readShort()));
210 $this->writeShort(self::checkWriteStringLength(strlen($v)));
211 $this->buffer->put($v);