<?php

namespace App\Media\QuickTime\Atoms\moov\trak\mdia;

use App\Media\QuickTime\Atoms\SubAtom;

class hdlr extends SubAtom
{
	protected const unpack = [
		'version'=>['c',1],
		'flags'=>['a3',3],
		'ctype'=>['a4',4],
		'csubtype'=>['a4',4],
		'cmanufact'=>['a4',4],
		'cflags'=>['a4',4],
		'cmask'=>['a4',4],
	];

	public function __construct(int $offset,int $size,string $filename,?string $data)
	{
		parent::__construct($offset,$size,$filename);

		$this->cache = $this->cache();
		$this->cache['name'] = pascal_string($this->unused_data);

		$this->unused_data = (($x=strlen($this->cache['name'])+1) < strlen($this->unused_data)) ? substr($data,$x) : NULL;

		// For debugging
		if (FALSE)
			$this->debug = hex_dump($data ?: $this->data());
	}
}