public static function store($value) { if (\tool::debug()) { \tool::fprint("Storing " . get_called_class() . ":{$value}"); } return Writer::convert('d', $value); }
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 static function store($value) { if ($value < -2147483648 || $value > 2147483647) { throw new RangeException('Value is out of allowed range for given type.'); } if (\tool::debug()) { \tool::fprint("Storing " . get_called_class() . ":{$value}"); } return Writer::convert('l', (int) $value); }
public static function store($value) { $len = strlen($value); if ($len < 0 || $len > 32767) { throw new \LengthException('Valid string length range is 0..32767.'); } if (\tool::debug()) { \tool::fprint("Storing " . get_called_class() . ":{$value}"); } return TAG_Short::store($len) . $value; }
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; }
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")); }