*/ public static function unpack($data) { $header = unpack(self::HEADER_STRUCT, substr($data, 0, self::HEADER_SIZE)); if ($header === false) { throw new RuntimeException('Invalid Header'); } switch ($header['type']) { case Packer::TYPE_BUFFER: $handler = new Buffer($header['length']); break; case Packer::TYPE_FILE: $handler = new File($header['length']); break; default: throw new RuntimeException("unsupported data type: [{$header['type']}"); } $data = substr($data, self::HEADER_SIZE); return [$handler, $data]; } }