Esempio n. 1
0
 public function save(SplFileObject $file)
 {
     $result = parent::save($file);
     if (isset($this->type)) {
         $result += $file->fwrite(Dictionary::mapName($this->type));
     } else {
         if (count($this->content)) {
             throw new UnexpectedValueException('Populated list needs an explicit type cast.');
         } else {
             $result += $file->fwrite(Dictionary::mapName('TAG_End'));
         }
     }
     $result += $file->fwrite(TAG_Int::store(count($this->content)));
     if (\tool::debug()) {
         \tool::fprint("Storing " . count($this->content) . " values of type {$this->type} @{$file->ftell()} ...");
     }
     $type = $this->type;
     foreach ($this->content as $index => $tag) {
         if (!is_object($tag)) {
             $result += $file->fwrite($type::store($tag));
         } else {
             if ($tag instanceof $this->type) {
                 if (isset($tag->name)) {
                     throw new UnexpectedValueException("List#{$index} is a named tag.");
                 }
                 $result += $tag->save($file);
             } else {
                 throw new UnexpectedValueException("List#{$index} type '" . get_class($tag) . "' doesn't match the list type '{$this->type}'.");
             }
         }
     }
     return $result;
 }
Esempio n. 2
0
 public function save(SplFileObject $file)
 {
     $result = parent::save($file) + $file->fwrite(TAG_Int::store(count($this->content)));
     if (\tool::debug()) {
         \tool::fprint("Storing " . count($this->content) . " values @{$file->ftell()} ...");
     }
     ksort($this->content);
     foreach ($this->content as $value) {
         $result += $file->fwrite(TAG_Byte::store($value));
     }
     return $result;
 }