//--------------------------------------
//			   PowerUI
//
//		For documentation or 
//	if you have any issues, visit
//		powerUI.kulestar.com
//
//	Copyright © 2013 Kulestar Ltd
//		  www.kulestar.com
//--------------------------------------

using System;
using BinaryIO;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;


namespace Gif{

	/// <summary>
	/// Any other extension in a GIF stream.
	/// </summary>
	public class ApplicationExtensionBlock : GifBlock{
		
		public const int HeaderSize = 0X0B;
		
		/// <summary>The extensions.</summary>
		public List<byte[]> Extensions;
		/// <summary>ID for the application.</summary>
		public string ApplicationIdentifier;
		/// <summary>Auth code for the application (GIF has this? Interesting choices are interesting!)</summary>
		public string ApplicationAuthenticationCode;
		
		
		public override void Load(Reader reader){
			
			Extensions=new List<byte[]>();
			
			int blockSize=reader.ReadByte();
			
			if(blockSize!=HeaderSize){
				throw new Exception("An extension block had the wrong size in a GIF stream.");
			}
			
			ApplicationIdentifier=reader.ReadString(8);
			ApplicationAuthenticationCode=reader.ReadString(3);
			
			int nextFlag=reader.ReadByte();
			
			while(nextFlag != 0){
				
				Extensions.Add(reader.ReadBytes(nextFlag));
				nextFlag=reader.ReadByte();
				
			}
			
		}
		
	}
	
}