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; }
public static final function convert($format, $value) { $result = unpack($format, Dictionary::convert($value))[1]; if (\tool::debug()) { \tool::fprint("Converted {$format}'" . bin2hex($value) . "' to {$result}"); } return $result; }
public function save(SplFileObject $file) { $result = parent::save($file); if (\tool::debug()) { \tool::fprint("Storing " . count($this->content) . " values @{$file->ftell()} ..."); } $i = 1; foreach ($this->content as $tag) { if ($tag instanceof TAG_End) { break; } $result += $tag->save($file); $i++; } if (\tool::debug()) { if ($i < count($this->content)) { # TODO: Check if the tag is TAG_End at insetion times. \tool::fprint("Stored {$i} values! Don't stuff TAG_End in the middle of compound tags!"); } } return $result + $file->fwrite(Dictionary::mapName("TAG_End")); }
public static final function convert($format, $value) { return Dictionary::convert(pack($format, $value)); }
public function save(SplFileObject $file) { \tool::fprint("Saving ... " . get_called_class()); return $file->fwrite(Dictionary::mapName($this->id)); }
public function save(SplFileObject $file) { \tool::fprint("Saving ... " . get_called_class() . (isset($this->name) ? ":{$this->name}" : '') . "@{$file->ftell()}"); return $file->fwrite(isset($this->name) ? Dictionary::mapName($this->id) . TAG_String::store($this->name) : ''); }