using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using skyscraper5.Mpeg2;
using skyscraper5.Skyscraper.IO;
using skyscraper5.Skyscraper.Plugins;

namespace skyscraper5.Mhp.Descriptors
{
	[SkyscraperPlugin]
	[TsDescriptor(0x01,"AIT")]
    class ApplicationNameDescriptor : TsDescriptor
    {
        public ApplicationNameDescriptor(byte[] buffer)
        {
            Dictionary<string, string> temp = new Dictionary<string, string>();
            MemoryStream ms = new MemoryStream(buffer, false);
            while (ms.GetAvailableBytes() >= 4)
            {
                string key = Encoding.ASCII.GetString(ms.ReadBytes(3));
                byte valueLength = ms.ReadUInt8();
                string value = Encoding.ASCII.GetString(ms.ReadBytes(valueLength));
                temp.Add(key, value);
            }
            ApplicationNames = new ReadOnlyDictionary<string, string>(temp);
            Valid = true;
        }

        public ReadOnlyDictionary<string, string> ApplicationNames { get; }
    }
}
