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();
105 public function readMultiple(
string $buffer,
int $maxDepth = 0) : array{
110 while(!$this->buffer->feof()){
112 $retval[] = $this->readRoot($maxDepth);
114 throw new NbtDataException($e->getMessage(), 0, $e);
121 private function writeRoot(TreeRoot $root) : void{
122 $this->writeByte($root->getTag()->getType());
123 $this->writeString($root->getName());
124 $root->getTag()->write($this);
127 public function write(TreeRoot $data) : string{
128 $this->buffer = new BinaryStream();
130 $this->writeRoot($data);
132 return $this->buffer->getBuffer();
144 return $this->buffer->getBuffer();
152 foreach($data as $root){
153 $this->writeRoot($root);
155 return $this->buffer->getBuffer();
159 return $this->buffer->getByte();
163 return
Binary::signByte($this->buffer->getByte());
166 public function writeByte(
int $v) : void{
167 $this->buffer->putByte($v);
171 $length = $this->readInt();
173 throw new NbtDataException(
"Array length cannot be less than zero ($length < 0)");
175 return $this->buffer->get($length);
178 public function writeByteArray(
string $v) : void{
179 $this->writeInt(strlen($v));
180 $this->buffer->put($v);
198 throw new \InvalidArgumentException(
"NBT string length too large ($len > 32767)");
204 return $this->buffer->get(self::checkReadStringLength($this->readShort()));
211 $this->writeShort(self::checkWriteStringLength(strlen($v)));
212 $this->buffer->put($v);